#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int rand();
int /*<<< orphan*/ random_tag();
int /*<<< orphan*/ srand(int);
int sscanf(char *, char *, int *);
int main(int argc, char **argv) {
  int tc, seed;
  char *x = getenv("QUERY_STRING");
  if (!x || sscanf(x, "%x", &seed) != 1) {
    printf("Content-type: text/plain\n\nMissing or invalid parameter.\n");
    exit(1);
  }
  printf("Content-Type: text/html;charset=utf-8\nRefresh: "
         "0;URL=remangle.cgi?0x%08x\n\n",
         seed);
  printf("<HTML><HEAD><META HTTP-EQUIV=\"Refresh\" "
         "content=\"0;URL=remangle.cgi?0x%08x\">\n",
         seed);
  printf("<script "
         "language=\"javascript\">setTimeout('window.location=\"remangle.cgi?"
         "0x%08x\"', 1000);</script>\n",
         seed);
  srand(seed);
  tc = (rand() % (100)) + 1;
  while (tc--)
    random_tag();
  fflush(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11ce <main+0x4e>
mov    -0x20(%rbp),%rdi
lea    0xe51(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
je     11e6 <main+0x66>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%esi
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%esi
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1060 <srand@plt>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1256 <main+0xd6>
mov    $0x0,%al
call   1050 <random_tag@plt>
jmp    1236 <main+0xb6>
xor    %edi,%edi
call   1070 <fflush@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe64(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     124b <main+0xbb>
lea    0xe5c(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1090 <sscanf@plt>
cmp    $0x1,%eax
jne    124b <main+0xbb>
mov    0xc(%rsp),%esi
lea    0xe3e(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xe77(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%esi
lea    0xeb2(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
call   1070 <srand@plt>
xor    %eax,%eax
call   10b0 <rand@plt>
movslq %eax,%rbx
imul   $0x51eb851f,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x25,%rax
add    %ecx,%eax
imul   $0x64,%eax,%eax
sub    %eax,%ebx
inc    %ebx
je     123c <main+0xac>
nopl   (%rax)
xor    %eax,%eax
call   1060 <random_tag@plt>
add    $0xffffffff,%ebx
jne    1230 <main+0xa0>
xor    %edi,%edi
call   1080 <fflush@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xeb9(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"QUERY_STRING\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [57 x i8] c"Content-type: text/plain\0A\0AMissing or invalid parameter.\0A\00"
@.str.3 = [75 x i8] c"Content-Type: text/html;charset=utf-8\0ARefresh: 0;URL=remangle.cgi?0x%08x\0A\0A\00"
@.str.4 = [77 x i8] c"<HTML><HEAD><META HTTP-EQUIV=\22Refresh\22 content=\220;URL=remangle.cgi?0x%08x\22>\0A\00"
@.str.5 = [99 x i8] c"<script language=\22javascript\22>setTimeout('window.location=\22remangle.cgi?0x%08x\22', 1000);</script>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %8
%10 = load i8*, i8** %8
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %8
%14 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%15 = icmp ne i32 %14, 1
br i1 %15, label %16, label %19
16: ; preds = %12, %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %12
%20 = load i32, i32* %7
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %7
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([77 x i8], [77 x i8]* @.str.4, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %7
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([99 x i8], [99 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %7
%27 = call i32 @srand(i32 %26)
%28 = call i32 (...) @rand()
%29 = srem i32 %28, 100
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %31
31: ; preds = %35, %19
%32 = load i32, i32* %6
%33 = add nsw i32 %32, -1
store i32 %33, i32* %6
%34 = icmp ne i32 %32, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (...) @random_tag()
br label %31
37: ; preds = %31
%38 = call i32 @fflush(i32 0)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"QUERY_STRING\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.3 = [75 x i8] c"Content-Type: text/html;charset=utf-8\0ARefresh: 0;URL=remangle.cgi?0x%08x\0A\0A\00"
@.str.4 = [77 x i8] c"<HTML><HEAD><META HTTP-EQUIV=\22Refresh\22 content=\220;URL=remangle.cgi?0x%08x\22>\0A\00"
@.str.5 = [99 x i8] c"<script language=\22javascript\22>setTimeout('window.location=\22remangle.cgi?0x%08x\22', 1000);</script>\0A\00"
@str = [56 x i8] c"Content-type: text/plain\0A\0AMissing or invalid parameter.\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%9 = icmp eq i32 %8, 1
br i1 %9, label %13, label %10
10: ; preds = %7, %2
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %7
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %3
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([77 x i8], [77 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([99 x i8], [99 x i8]* @.str.5, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %3
%21 = call i32 @srand(i32 %20)
%22 = call i32 (...) @rand()
%23 = srem i32 %22, 100
%24 = add nsw i32 %23, 1
%25 = icmp eq i32 %24, 0
br i1 %25, label %31, label %26
26: ; preds = %13, %26
%27 = phi i32 [ %28, %26 ], [ %24, %13 ]
%28 = add nsw i32 %27, -1
%29 = call i32 (...) @random_tag()
%30 = icmp eq i32 %28, 0
br i1 %30, label %31, label %26
31: ; preds = %26, %13
%32 = call i32 @fflush(i32 0)
ret i32 0
}