#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int, char *,
                           char *);
char *getenv(char *);
int getpid();
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ random_tag();
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ stderr;
int time(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int tc, seed;
  printf(
      "Content-Type: text/html;charset=utf-8\nRefresh: 0;URL=mangle.cgi\n\n");
  printf("<HTML><HEAD><META HTTP-EQUIV=\"Refresh\" "
         "content=\"0;URL=mangle.cgi\">\n");
  printf("<script "
         "language=\"javascript\">setTimeout('window.location=\"mangle.cgi\"', "
         "1000);</script>\n");
  seed = (time(0) ^ (getpid() << 16));
  fprintf(stderr, "[%u] Mangle attempt 0x%08x (%s) -- %s\n", (int)time(0), seed,
          getenv("HTTP_USER_AGENT"), getenv("REMOTE_ADDR"));
  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    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe53(%rip),%rdi
call   1050 <printf@plt>
lea    0xe89(%rip),%rdi
call   1050 <printf@plt>
lea    0xec1(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
shl    $0x10,%ecx
xor    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    0xefc(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
lea    0xefc(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    %rax,%r9
lea    0xea9(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x18(%rbp),%edi
call   1070 <srand@plt>
mov    $0x0,%al
call   10b0 <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     1279 <main+0xe9>
mov    $0x0,%al
call   1060 <random_tag@plt>
jmp    1259 <main+0xc9>
xor    %edi,%edi
call   10a0 <fflush@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1040 <puts@plt>
lea    0xeda(%rip),%rdi
call   1040 <puts@plt>
lea    0xf11(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getpid@plt>
shl    $0x10,%eax
xor    %eax,%ebx
mov    0x2e09(%rip),%rax
mov    (%rax),%r14d
xor    %edi,%edi
call   1090 <time@plt>
mov    %eax,%r15d
lea    0xe3c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbp
lea    0xe3d(%rip),%rdi
call   1030 <getenv@plt>
lea    0xdfa(%rip),%rsi
mov    %r14d,%edi
mov    %r15d,%edx
mov    %ebx,%ecx
mov    %rbp,%r8
mov    %rax,%r9
call   1080 <fprintf@plt>
mov    %ebx,%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     125c <main+0xcc>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <random_tag@plt>
add    $0xffffffff,%ebx
jne    1250 <main+0xc0>
xor    %edi,%edi
call   10a0 <fflush@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [66 x i8] c"Content-Type: text/html;charset=utf-8\0ARefresh: 0;URL=mangle.cgi\0A\0A\00"
@.str.1 = [68 x i8] c"<HTML><HEAD><META HTTP-EQUIV=\22Refresh\22 content=\220;URL=mangle.cgi\22>\0A\00"
@.str.2 = [90 x i8] c"<script language=\22javascript\22>setTimeout('window.location=\22mangle.cgi\22', 1000);</script>\0A\00"
@stderr = global i32 0
@.str.3 = [39 x i8] c"[%u] Mangle attempt 0x%08x (%s) -- %s\0A\00"
@.str.4 = [16 x i8] c"HTTP_USER_AGENT\00"
@.str.5 = [12 x i8] c"REMOTE_ADDR\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([90 x i8], [90 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @time(i32 0)
%12 = call i32 (...) @getpid()
%13 = shl i32 %12, 16
%14 = xor i32 %11, %13
store i32 %14, i32* %7
%15 = load i32, i32* @stderr
%16 = call i32 @time(i32 0)
%17 = load i32, i32* %7
%18 = call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%19 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%20 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %16, i32 %17, i8* %18, i8* %19)
%21 = load i32, i32* %7
%22 = call i32 @srand(i32 %21)
%23 = call i32 (...) @rand()
%24 = srem i32 %23, 100
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %26
26: ; preds = %30, %2
%27 = load i32, i32* %6
%28 = add nsw i32 %27, -1
store i32 %28, i32* %6
%29 = icmp ne i32 %27, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 (...) @random_tag()
br label %26
32: ; preds = %26
%33 = call i32 @fflush(i32 0)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.3 = [39 x i8] c"[%u] Mangle attempt 0x%08x (%s) -- %s\0A\00"
@.str.4 = [16 x i8] c"HTTP_USER_AGENT\00"
@.str.5 = [12 x i8] c"REMOTE_ADDR\00"
@str = [65 x i8] c"Content-Type: text/html;charset=utf-8\0ARefresh: 0;URL=mangle.cgi\0A\00"
@str.6 = [67 x i8] c"<HTML><HEAD><META HTTP-EQUIV=\22Refresh\22 content=\220;URL=mangle.cgi\22>\00"
@str.7 = [89 x i8] c"<script language=\22javascript\22>setTimeout('window.location=\22mangle.cgi\22', 1000);</script>\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @str, i64 0, i64 0))
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @str.6, i64 0, i64 0))
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([89 x i8], [89 x i8]* @str.7, i64 0, i64 0))
%6 = tail call i32 @time(i32 0)
%7 = tail call i32 (...) @getpid()
%8 = shl i32 %7, 16
%9 = xor i32 %8, %6
%10 = load i32, i32* @stderr
%11 = tail call i32 @time(i32 0)
%12 = tail call i8* @getenv(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%13 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%14 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i32 %11, i32 %9, i8* %12, i8* %13)
%15 = tail call i32 @srand(i32 %9)
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, 100
%18 = add nsw i32 %17, 1
%19 = icmp eq i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %2, %20
%21 = phi i32 [ %22, %20 ], [ %18, %2 ]
%22 = add nsw i32 %21, -1
%23 = tail call i32 (...) @random_tag()
%24 = icmp eq i32 %22, 0
br i1 %24, label %25, label %20
25: ; preds = %20, %2
%26 = tail call i32 @fflush(i32 0)
ret i32 0
}