Fix crash at startup with -W options.
diff --git a/Modules/main.c b/Modules/main.c
index 824bada..b57241e 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -262,7 +262,33 @@
     Py_RISCOSWimpFlag = 0;
 #endif
 
+    /* Hash randomization needed early for all string operations
+       (including -W and -X options). */
+    while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) {
+        if (c == 'm' || c == 'c') {
+            /* -c / -m is the last option: following arguments are
+               not interpreter options. */
+            break;
+        }
+        switch (c) {
+        case 'E':
+            Py_IgnoreEnvironmentFlag++;
+            break;
+        case 'R':
+            Py_HashRandomizationFlag++;
+            break;
+        }
+    }
+    /* The variable is only tested for existence here; _PyRandom_Init will
+       check its value further. */
+    if (!Py_HashRandomizationFlag &&
+        (p = Py_GETENV("PYTHONHASHSEED")) && *p != '\0')
+        Py_HashRandomizationFlag = 1;
+
+    _PyRandom_Init();
+
     PySys_ResetWarnOptions();
+    _PyOS_ResetGetOpt();
 
     while ((c = _PyOS_GetOpt(argc, argv, PROGRAM_OPTS)) != EOF) {
         if (c == 'c') {
@@ -356,7 +382,7 @@
             break;
 
         case 'E':
-            Py_IgnoreEnvironmentFlag++;
+            /* Already handled above */
             break;
 
         case 't':
@@ -406,7 +432,7 @@
             break;
 
         case 'R':
-            Py_HashRandomizationFlag++;
+            /* Already handled above */
             break;
 
         /* This space reserved for other options */