#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct stat {
  scalar_t__ st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ scanf(char *, char *);
scalar_t__ stat(char *, struct stat *);
scalar_t__ strcmp(char *, char *);
int main() {
  int i;
  int len;
  bool isEve;
  char str[97];
  len = atoi(getenv("CONTENT_LENGTH"));
  scanf("%s", str);
  if (len == 96)
    isEve = true;
  else {
    printf("content-type: text/plain\n\n");
    printf("Error:1 %d %s", len, str);
    return -1;
  }
  FILE *fp;
  if ((fp = fopen("./output.txt", "w")) == NULL) {
    printf("content-type: text/plain\n\n");
    printf("Error:2");
    return -1;
  }
  int eq_flag = 0;
  int n = 0;
  for (i = 0; i < len; i++) {
    if (eq_flag == 0 || eq_flag == 2 || eq_flag == 4) {
      if (str[i] == '=')
        eq_flag++;
      else
        continue;
    } else if (eq_flag == 1 || eq_flag == 3 || eq_flag == 5) {
      if (str[i] == '&') {
        if (!isEve && eq_flag == 3)
          break;
        eq_flag++;
        continue;
      } else if (str[i] != '0' && str[i] != '1' && str[i] != '2') {
        printf("content-type: text/plain\n\n");
        printf("Error:3");
        return -1;
      }
      fprintf(fp, "%c ", str[i]);
      if (++n % 20 == 0)
        fprintf(fp, "\n");
    }
  }
  fclose(fp);
  struct stat stat_buf;
  while (true) {
    if (stat("resultTmp", &stat_buf) == 0)
      if (stat_buf.st_size != 0)
        break;
  }
  printf("content-type: text/plain\n\n");
  char copyBuf[128];
  FILE *index;
  FILE *result;
  if ((index = fopen("./index.html", "r")) == NULL) {
    printf("error");
    return -1;
  }
  if ((result = fopen("./resultTmp", "r")) == NULL) {
    printf("error");
    fclose(index);
    return -1;
  }
  while (strcmp(fgets(copyBuf, 128, index),
                "<body onload=\"setRandomAll();\">\n") != 0)
    ;
  while (fgets(copyBuf, 128, index) != NULL) {
    if (strcmp(copyBuf, "<!--result-->\n") == 0)
      break;
    printf("%s", copyBuf);
  }
  while (fgets(copyBuf, 128, result) != NULL)
    printf("%s", copyBuf);
  while (strcmp(fgets(copyBuf, 128, index), "<!--/result-->\n") != 0)
    ;
  while (fgets(copyBuf, 128, index) != NULL) {
    if (strcmp(copyBuf, "</body>\n") == 0)
      break;
    printf("%s", copyBuf);
  }
  fclose(index);
  fclose(result);
  remove("./resultTmp");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe37(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
call   10d0 <atoi@plt>
mov    %eax,-0xc(%rbp)
lea    -0x80(%rbp),%rsi
lea    0xe52(%rip),%rdi
call   10b0 <scanf@plt>
cmpl   $0x60,-0xc(%rbp)
jne    11fe <main+0x4e>
movl   $0x1,-0x10(%rbp)
jmp    122d <main+0x7d>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xc(%rbp),%esi
lea    -0x80(%rbp),%rdx
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16b7 <main+0x507>
lea    0xe04(%rip),%rdi
lea    0xe0a(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x88(%rbp)
cmp    $0x0,%rax
jne    1279 <main+0xc9>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xde1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16b7 <main+0x507>
movl   $0x0,-0x8c(%rbp)
movl   $0x0,-0x90(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1433 <main+0x283>
cmpl   $0x0,-0x8c(%rbp)
je     12c7 <main+0x117>
cmpl   $0x2,-0x8c(%rbp)
je     12c7 <main+0x117>
cmpl   $0x4,-0x8c(%rbp)
jne    12f7 <main+0x147>
movslq -0x8(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x3d,%eax
jne    12ed <main+0x13d>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    12f2 <main+0x142>
jmp    1425 <main+0x275>
jmp    1420 <main+0x270>
cmpl   $0x1,-0x8c(%rbp)
je     131e <main+0x16e>
cmpl   $0x3,-0x8c(%rbp)
je     131e <main+0x16e>
cmpl   $0x5,-0x8c(%rbp)
jne    141b <main+0x26b>
movslq -0x8(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x26,%eax
jne    1360 <main+0x1b0>
cmpl   $0x0,-0x10(%rbp)
jne    134c <main+0x19c>
cmpl   $0x3,-0x8c(%rbp)
jne    134c <main+0x19c>
jmp    1433 <main+0x283>
mov    -0x8c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8c(%rbp)
jmp    1425 <main+0x275>
movslq -0x8(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x30,%eax
je     13be <main+0x20e>
movslq -0x8(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x31,%eax
je     13be <main+0x20e>
movslq -0x8(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x32,%eax
je     13be <main+0x20e>
lea    0xc72(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xca4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16b7 <main+0x507>
jmp    13c3 <main+0x213>
mov    -0x88(%rbp),%rdi
movslq -0x8(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%edx
lea    0xc7d(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    -0x90(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x90(%rbp)
mov    $0x14,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1416 <main+0x266>
mov    -0x88(%rbp),%rdi
lea    0xc19(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    141b <main+0x26b>
jmp    1420 <main+0x270>
jmp    1425 <main+0x275>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1294 <main+0xe4>
mov    -0x88(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xc2a(%rip),%rdi
lea    -0x98(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%rax
jne    1474 <main+0x2c4>
cmpq   $0x0,-0x98(%rbp)
je     146f <main+0x2bf>
jmp    1479 <main+0x2c9>
jmp    1474 <main+0x2c4>
jmp    143f <main+0x28f>
lea    0xb8f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xbcd(%rip),%rdi
lea    0xbd7(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
jne    14c5 <main+0x315>
lea    0xbb6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16b7 <main+0x507>
lea    0xba2(%rip),%rdi
lea    0xb99(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x130(%rbp)
cmp    $0x0,%rax
jne    150f <main+0x35f>
lea    0xb78(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x128(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    16b7 <main+0x507>
jmp    1514 <main+0x364>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x80,%esi
call   1070 <fgets@plt>
mov    %rax,%rdi
lea    0xb44(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     154a <main+0x39a>
jmp    1514 <main+0x364>
jmp    154f <main+0x39f>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x80,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     15ad <main+0x3fd>
lea    -0x120(%rbp),%rdi
lea    0xb1c(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1593 <main+0x3e3>
jmp    15ad <main+0x3fd>
lea    -0x120(%rbp),%rsi
lea    0xa94(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    154f <main+0x39f>
jmp    15b2 <main+0x402>
lea    -0x120(%rbp),%rdi
mov    -0x130(%rbp),%rdx
mov    $0x80,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     15ee <main+0x43e>
lea    -0x120(%rbp),%rsi
lea    0xa53(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15b2 <main+0x402>
jmp    15f3 <main+0x443>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x80,%esi
call   1070 <fgets@plt>
mov    %rax,%rdi
lea    0xa95(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1629 <main+0x479>
jmp    15f3 <main+0x443>
jmp    162e <main+0x47e>
lea    -0x120(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x80,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     168c <main+0x4dc>
lea    -0x120(%rbp),%rdi
lea    0xa5c(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1672 <main+0x4c2>
jmp    168c <main+0x4dc>
lea    -0x120(%rbp),%rsi
lea    0x9b5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    162e <main+0x47e>
mov    -0x128(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x130(%rbp),%rdi
call   1050 <fclose@plt>
lea    0x9c3(%rip),%rdi
call   1040 <remove@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
lea    0xe18(%rip),%rdi
call   1030 <getenv@plt>
mov    %eax,%edi
call   10f0 <atoi@plt>
mov    %eax,%ebx
lea    0xe1d(%rip),%rdi
lea    0x90(%rsp),%rsi
call   10d0 <scanf@plt>
cmp    $0x60,%ebx
jne    12ce <main+0xfe>
lea    0xe03(%rip),%rdi
lea    0xe09(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1502 <main+0x332>
mov    %rax,%r12
mov    $0x15,%r15d
lea    0xdfd(%rip),%r14
xor    %ebp,%ebp
xor    %r13d,%r13d
xor    %ebx,%ebx
jmp    126d <main+0x9d>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
cmpb   $0x3d,0x90(%rsp,%rbp,1)
3d
sete   %al
add    %eax,%ebx
add    $0x1,%rbp
cmp    $0x60,%rbp
je     12f7 <main+0x127>
cmp    $0x5,%ebx
ja     125f <main+0x8f>
bt     %ebx,%r15d
jb     1250 <main+0x80>
movzbl 0x90(%rsp,%rbp,1),%eax
lea    -0x30(%rax),%ecx
cmp    $0x3,%cl
jae    12c1 <main+0xf1>
movzbl %al,%edx
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
add    $0x1,%r13d
imul   $0xcccccccd,%r13d,%eax
add    $0x19999998,%eax
ror    $0x2,%eax
cmp    $0xccccccc,%eax
ja     125f <main+0x8f>
mov    $0xa,%edi
mov    %r12,%rsi
call   1080 <fputc@plt>
jmp    125f <main+0x8f>
cmp    $0x26,%al
jne    1538 <main+0x368>
add    $0x1,%ebx
jmp    125f <main+0x8f>
lea    0xdd3(%rip),%rdi
call   1050 <puts@plt>
lea    0xd2e(%rip),%rdi
lea    0x90(%rsp),%rdx
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1552 <main+0x382>
mov    %r12,%rdi
call   1060 <fclose@plt>
lea    0xd4f(%rip),%rbx
lea    0x8(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10c0 <stat@plt>
test   %rax,%rax
jne    1310 <main+0x140>
cmpq   $0x0,0x8(%rsp)
je     1310 <main+0x140>
lea    0xd79(%rip),%rdi
call   1050 <puts@plt>
lea    0xd05(%rip),%rdi
lea    0xd0f(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1517 <main+0x347>
mov    %rax,%rbp
lea    0xcf9(%rip),%rdi
lea    0xcf0(%rip),%rsi
call   10e0 <fopen@plt>
test   %rax,%rax
je     1520 <main+0x350>
mov    %rax,%r14
lea    0x10(%rsp),%r15
lea    0xce1(%rip),%rbx
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
call   1090 <fgets@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1380 <main+0x1b0>
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1402 <main+0x232>
lea    0xcc2(%rip),%r15
lea    0x10(%rsp),%r12
lea    0xc50(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1402 <main+0x232>
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
jne    13d0 <main+0x200>
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1452 <main+0x282>
lea    0xbfa(%rip),%r15
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
jne    1430 <main+0x260>
lea    0x10(%rsp),%r15
lea    0xc31(%rip),%rbx
xchg   %ax,%ax
mov    %r15,%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
call   1090 <fgets@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1460 <main+0x290>
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     14e2 <main+0x312>
lea    0xc01(%rip),%r15
lea    0x10(%rsp),%r12
lea    0xb70(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     14e2 <main+0x312>
mov    %r13,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
mov    $0x80,%esi
mov    %rbp,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
jne    14b0 <main+0x2e0>
mov    %rbp,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
lea    0xb5a(%rip),%rdi
call   1040 <remove@plt>
xor    %eax,%eax
jmp    1557 <main+0x387>
lea    0xb9f(%rip),%rdi
call   1050 <puts@plt>
lea    0xb17(%rip),%rdi
jmp    154b <main+0x37b>
lea    0xb2f(%rip),%rdi
jmp    154b <main+0x37b>
lea    0xb26(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rdi
call   1060 <fclose@plt>
jmp    1552 <main+0x382>
lea    0xb69(%rip),%rdi
call   1050 <puts@plt>
lea    0xae9(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0xffffffff,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [15 x i8] c"CONTENT_LENGTH\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [27 x i8] c"content-type: text/plain\0A\0A\00"
@.str.3 = [14 x i8] c"Error:1 %d %s\00"
@.str.4 = [13 x i8] c"./output.txt\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [8 x i8] c"Error:2\00"
@.str.7 = [8 x i8] c"Error:3\00"
@.str.8 = [4 x i8] c"%c \00"
@.str.9 = [2 x i8] c"\0A\00"
@.str.10 = [10 x i8] c"resultTmp\00"
@.str.11 = [13 x i8] c"./index.html\00"
@.str.12 = [2 x i8] c"r\00"
@.str.13 = [6 x i8] c"error\00"
@.str.14 = [12 x i8] c"./resultTmp\00"
@.str.15 = [33 x i8] c"<body onload=\22setRandomAll();\22>\0A\00"
@.str.16 = [15 x i8] c"<!--result-->\0A\00"
@.str.17 = [16 x i8] c"<!--/result-->\0A\00"
@.str.18 = [9 x i8] c"</body>\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [97 x i8]
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.stat
%10 = alloca [128 x i8]
%11 = alloca i32*
%12 = alloca i32*
store i32 0, i32* %1
%13 = call i32 @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @atoi(i32 %13)
store i32 %14, i32* %3
%15 = getelementptr inbounds [97 x i8], [97 x i8]* %5, i64 0, i64 0
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, 96
br i1 %18, label %19, label %20
19: ; preds = %0
store i32 1, i32* %4
br label %25
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* %3
%23 = getelementptr inbounds [97 x i8], [97 x i8]* %5, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %22, i8* %23)
store i32 -1, i32* %1
br label %214
25: ; preds = %19
%26 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %26, i32** %6
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %214
31: ; preds = %25
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %2
br label %32
32: ; preds = %126, %31
%33 = load i32, i32* %2
%34 = load i32, i32* %3
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %129
36: ; preds = %32
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %36
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, 2
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = load i32, i32* %7
%44 = icmp eq i32 %43, 4
br i1 %44, label %45, label %57
45: ; preds = %42, %39, %36
%46 = load i32, i32* %2
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [97 x i8], [97 x i8]* %5, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 61
br i1 %51, label %52, label %55
52: ; preds = %45
%53 = load i32, i32* %7
%54 = add nsw i32 %53, 1
store i32 %54, i32* %7
br label %56
55: ; preds = %45
br label %126
56: ; preds = %52
br label %125
57: ; preds = %42
%58 = load i32, i32* %7
%59 = icmp eq i32 %58, 1
br i1 %59, label %66, label %60
60: ; preds = %57
%61 = load i32, i32* %7
%62 = icmp eq i32 %61, 3
br i1 %62, label %66, label %63
63: ; preds = %60
%64 = load i32, i32* %7
%65 = icmp eq i32 %64, 5
br i1 %65, label %66, label %124
66: ; preds = %63, %60, %57
%67 = load i32, i32* %2
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [97 x i8], [97 x i8]* %5, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp eq i32 %71, 38
br i1 %72, label %73, label %83
73: ; preds = %66
%74 = load i32, i32* %4
%75 = icmp ne i32 %74, 0
br i1 %75, label %80, label %76
76: ; preds = %73
%77 = load i32, i32* %7
%78 = icmp eq i32 %77, 3
br i1 %78, label %79, label %80
79: ; preds = %76
br label %129
80: ; preds = %76, %73
%81 = load i32, i32* %7
%82 = add nsw i32 %81, 1
store i32 %82, i32* %7
br label %126
83: ; preds = %66
%84 = load i32, i32* %2
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [97 x i8], [97 x i8]* %5, i64 0, i64 %85
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = icmp ne i32 %88, 48
br i1 %89, label %90, label %107
90: ; preds = %83
%91 = load i32, i32* %2
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds [97 x i8], [97 x i8]* %5, i64 0, i64 %92
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = icmp ne i32 %95, 49
br i1 %96, label %97, label %107
97: ; preds = %90
%98 = load i32, i32* %2
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [97 x i8], [97 x i8]* %5, i64 0, i64 %99
%101 = load i8, i8* %100
%102 = sext i8 %101 to i32
%103 = icmp ne i32 %102, 50
br i1 %103, label %104, label %107
104: ; preds = %97
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %214
107: ; preds = %97, %90, %83
br label %108
108: ; preds = %107
%109 = load i32*, i32** %6
%110 = load i32, i32* %2
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds [97 x i8], [97 x i8]* %5, i64 0, i64 %111
%113 = load i8, i8* %112
%114 = sext i8 %113 to i32
%115 = call i32 (i32*, i8*, ...) @fprintf(i32* %109, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %114)
%116 = load i32, i32* %8
%117 = add nsw i32 %116, 1
store i32 %117, i32* %8
%118 = srem i32 %117, 20
%119 = icmp eq i32 %118, 0
br i1 %119, label %120, label %123
120: ; preds = %108
%121 = load i32*, i32** %6
%122 = call i32 (i32*, i8*, ...) @fprintf(i32* %121, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %123
123: ; preds = %120, %108
br label %124
124: ; preds = %123, %63
br label %125
125: ; preds = %124, %56
br label %126
126: ; preds = %125, %80, %55
%127 = load i32, i32* %2
%128 = add nsw i32 %127, 1
store i32 %128, i32* %2
br label %32
129: ; preds = %79, %32
%130 = load i32*, i32** %6
%131 = call i32 @fclose(i32* %130)
br label %132
132: ; preds = %129, %141
%133 = call i64 @stat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), %struct.stat* %9)
%134 = icmp eq i64 %133, 0
br i1 %134, label %135, label %141
135: ; preds = %132
%136 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%137 = load i64, i64* %136
%138 = icmp ne i64 %137, 0
br i1 %138, label %139, label %140
139: ; preds = %135
br label %142
140: ; preds = %135
br label %141
141: ; preds = %140, %132
br label %132
142: ; preds = %139
%143 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%144 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
store i32* %144, i32** %11
%145 = icmp eq i32* %144, null
br i1 %145, label %146, label %148
146: ; preds = %142
%147 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0))
store i32 -1, i32* %1
br label %214
148: ; preds = %142
%149 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
store i32* %149, i32** %12
%150 = icmp eq i32* %149, null
br i1 %150, label %151, label %155
151: ; preds = %148
%152 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0))
%153 = load i32*, i32** %11
%154 = call i32 @fclose(i32* %153)
store i32 -1, i32* %1
br label %214
155: ; preds = %148
br label %156
156: ; preds = %162, %155
%157 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%158 = load i32*, i32** %11
%159 = call i8* @fgets(i8* %157, i32 128, i32* %158)
%160 = call i64 @strcmp(i8* %159, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.15, i64 0, i64 0))
%161 = icmp ne i64 %160, 0
br i1 %161, label %162, label %163
162: ; preds = %156
br label %156
163: ; preds = %156
br label %164
164: ; preds = %174, %163
%165 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%166 = load i32*, i32** %11
%167 = call i8* @fgets(i8* %165, i32 128, i32* %166)
%168 = icmp ne i8* %167, null
br i1 %168, label %169, label %177
169: ; preds = %164
%170 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%171 = call i64 @strcmp(i8* %170, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.16, i64 0, i64 0))
%172 = icmp eq i64 %171, 0
br i1 %172, label %173, label %174
173: ; preds = %169
br label %177
174: ; preds = %169
%175 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%176 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %175)
br label %164
177: ; preds = %173, %164
br label %178
178: ; preds = %183, %177
%179 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%180 = load i32*, i32** %12
%181 = call i8* @fgets(i8* %179, i32 128, i32* %180)
%182 = icmp ne i8* %181, null
br i1 %182, label %183, label %186
183: ; preds = %178
%184 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%185 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %184)
br label %178
186: ; preds = %178
br label %187
187: ; preds = %193, %186
%188 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%189 = load i32*, i32** %11
%190 = call i8* @fgets(i8* %188, i32 128, i32* %189)
%191 = call i64 @strcmp(i8* %190, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.17, i64 0, i64 0))
%192 = icmp ne i64 %191, 0
br i1 %192, label %193, label %194
193: ; preds = %187
br label %187
194: ; preds = %187
br label %195
195: ; preds = %205, %194
%196 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%197 = load i32*, i32** %11
%198 = call i8* @fgets(i8* %196, i32 128, i32* %197)
%199 = icmp ne i8* %198, null
br i1 %199, label %200, label %208
200: ; preds = %195
%201 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%202 = call i64 @strcmp(i8* %201, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.18, i64 0, i64 0))
%203 = icmp eq i64 %202, 0
br i1 %203, label %204, label %205
204: ; preds = %200
br label %208
205: ; preds = %200
%206 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%207 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %206)
br label %195
208: ; preds = %204, %195
%209 = load i32*, i32** %11
%210 = call i32 @fclose(i32* %209)
%211 = load i32*, i32** %12
%212 = call i32 @fclose(i32* %211)
%213 = call i32 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* %1
br label %214
214: ; preds = %208, %151, %146, %104, %28, %20
%215 = load i32, i32* %1
ret i32 %215
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [15 x i8] c"CONTENT_LENGTH\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.3 = [14 x i8] c"Error:1 %d %s\00"
@.str.4 = [13 x i8] c"./output.txt\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [8 x i8] c"Error:2\00"
@.str.7 = [8 x i8] c"Error:3\00"
@.str.8 = [4 x i8] c"%c \00"
@.str.10 = [10 x i8] c"resultTmp\00"
@.str.11 = [13 x i8] c"./index.html\00"
@.str.12 = [2 x i8] c"r\00"
@.str.13 = [6 x i8] c"error\00"
@.str.14 = [12 x i8] c"./resultTmp\00"
@.str.15 = [33 x i8] c"<body onload=\22setRandomAll();\22>\0A\00"
@.str.16 = [15 x i8] c"<!--result-->\0A\00"
@.str.17 = [16 x i8] c"<!--/result-->\0A\00"
@.str.18 = [9 x i8] c"</body>\0A\00"
@str.21 = [26 x i8] c"content-type: text/plain\0A\00"
define i32 @main() {
%1 = alloca [97 x i8]
%2 = alloca %struct.stat
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [97 x i8], [97 x i8]* %1, i64 0, i64 0
%5 = tail call i32 @getenv(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @atoi(i32 %5)
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%8 = icmp eq i32 %6, 96
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %15, label %18
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.21, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %6, i8* %4)
br label %114
15: ; preds = %9
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.21, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %114
18: ; preds = %9, %44
%19 = phi i64 [ %47, %44 ], [ 0, %9 ]
%20 = phi i32 [ %46, %44 ], [ 0, %9 ]
%21 = phi i32 [ %45, %44 ], [ 0, %9 ]
switch i32 %21, label %44 [
i32 4, label %22
i32 2, label %22
i32 0, label %22
i32 5, label %28
i32 3, label %28
i32 1, label %28
]
22: ; preds = %18, %18, %18
%23 = getelementptr inbounds [97 x i8], [97 x i8]* %1, i64 0, i64 %19
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 61
%26 = zext i1 %25 to i32
%27 = add nuw nsw i32 %21, %26
br label %44
28: ; preds = %18, %18, %18
%29 = getelementptr inbounds [97 x i8], [97 x i8]* %1, i64 0, i64 %19
%30 = load i8, i8* %29
switch i8 %30, label %33 [
i8 38, label %31
i8 48, label %36
i8 49, label %36
i8 50, label %36
]
31: ; preds = %28
%32 = add nuw nsw i32 %21, 1
br label %44
33: ; preds = %28
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.21, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %114
36: ; preds = %28, %28, %28
%37 = zext i8 %30 to i32
%38 = call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i32 %37)
%39 = add nsw i32 %20, 1
%40 = srem i32 %39, 20
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %36
%43 = call i32 @fputc(i32 10, i32* %10)
br label %44
44: ; preds = %18, %22, %36, %42, %31
%45 = phi i32 [ %32, %31 ], [ %21, %42 ], [ %21, %36 ], [ %27, %22 ], [ %21, %18 ]
%46 = phi i32 [ %20, %31 ], [ %39, %42 ], [ %39, %36 ], [ %20, %22 ], [ %20, %18 ]
%47 = add nuw nsw i64 %19, 1
%48 = icmp eq i64 %47, 96
br i1 %48, label %49, label %18
49: ; preds = %44
%50 = call i32 @fclose(i32* %10)
%51 = bitcast %struct.stat* %2 to i8*
%52 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %53
53: ; preds = %53, %49
%54 = call i64 @stat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), %struct.stat* %2)
%55 = icmp eq i64 %54, 0
%56 = load i64, i64* %52
%57 = icmp ne i64 %56, 0
%58 = select i1 %55, i1 %57, i1 false
br i1 %58, label %59, label %53
59: ; preds = %53
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.21, i64 0, i64 0))
%61 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%62 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%63 = icmp eq i32* %62, null
br i1 %63, label %64, label %66
64: ; preds = %59
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0))
br label %112
66: ; preds = %59
%67 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
%68 = icmp eq i32* %67, null
br i1 %68, label %69, label %72
69: ; preds = %66
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i64 0, i64 0))
%71 = call i32 @fclose(i32* %62)
br label %112
72: ; preds = %66, %72
%73 = call i8* @fgets(i8* %61, i32 128, i32* %62)
%74 = call i64 @strcmp(i8* %73, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.15, i64 0, i64 0))
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %72
76: ; preds = %72
%77 = call i8* @fgets(i8* %61, i32 128, i32* %62)
%78 = icmp eq i8* %77, null
br i1 %78, label %86, label %79
79: ; preds = %76, %82
%80 = call i64 @strcmp(i8* %61, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.16, i64 0, i64 0))
%81 = icmp eq i64 %80, 0
br i1 %81, label %86, label %82
82: ; preds = %79
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %61)
%84 = call i8* @fgets(i8* %61, i32 128, i32* %62)
%85 = icmp eq i8* %84, null
br i1 %85, label %86, label %79
86: ; preds = %82, %79, %76
%87 = call i8* @fgets(i8* %61, i32 128, i32* %67)
%88 = icmp eq i8* %87, null
br i1 %88, label %93, label %89
89: ; preds = %86, %89
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %61)
%91 = call i8* @fgets(i8* %61, i32 128, i32* %67)
%92 = icmp eq i8* %91, null
br i1 %92, label %93, label %89
93: ; preds = %89, %86
br label %94
94: ; preds = %93, %94
%95 = call i8* @fgets(i8* %61, i32 128, i32* %62)
%96 = call i64 @strcmp(i8* %95, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.17, i64 0, i64 0))
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %94
98: ; preds = %94
%99 = call i8* @fgets(i8* %61, i32 128, i32* %62)
%100 = icmp eq i8* %99, null
br i1 %100, label %108, label %101
101: ; preds = %98, %104
%102 = call i64 @strcmp(i8* %61, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.18, i64 0, i64 0))
%103 = icmp eq i64 %102, 0
br i1 %103, label %108, label %104
104: ; preds = %101
%105 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %61)
%106 = call i8* @fgets(i8* %61, i32 128, i32* %62)
%107 = icmp eq i8* %106, null
br i1 %107, label %108, label %101
108: ; preds = %104, %101, %98
%109 = call i32 @fclose(i32* %62)
%110 = call i32 @fclose(i32* %67)
%111 = call i32 @remove(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.14, i64 0, i64 0))
br label %112
112: ; preds = %108, %69, %64
%113 = phi i32 [ -1, %64 ], [ -1, %69 ], [ 0, %108 ]
br label %114
114: ; preds = %15, %112, %33, %12
%115 = phi i32 [ -1, %12 ], [ -1, %15 ], [ %113, %112 ], [ -1, %33 ]
ret i32 %115
}