#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 atoi(char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/);
char *getenv(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int rand();
int /*<<< orphan*/ stdout;
int strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int main() {
  int filesize;
  char *str_filesize;
  char *buffer;
  int index;
  printf("Content-type: text/plain\r\n\r\n");
  if (!(str_filesize = getenv("QUERY_STRING")))
    filesize = 10240;
  else {
    if (!strncmp(str_filesize, "size=", 5))
      filesize = atoi(&(str_filesize[5]));
    else
      filesize = 10240;
  }
  if (!(buffer = (char *)malloc(filesize))) {
    fwrite("Out of memory", strlen("Out of memory"), 1, stdout);
    return -1;
  }
  for (index = 0; index < filesize; index++)
    buffer[index] = rand() % 26 + 63;
  fwrite(buffer, filesize, 1, stdout);
  free(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe5a(%rip),%rdi
call   1070 <printf@plt>
lea    0xe6b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11d1 <main+0x41>
movl   $0x2800,-0x8(%rbp)
jmp    1210 <main+0x80>
mov    -0x10(%rbp),%rdi
lea    0xe4e(%rip),%rsi
mov    $0x5,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%eax
jne    1204 <main+0x74>
mov    -0x10(%rbp),%rdi
add    $0x5,%rdi
call   1090 <atoi@plt>
mov    %eax,-0x8(%rbp)
jmp    120b <main+0x7b>
movl   $0x2800,-0x8(%rbp)
jmp    1210 <main+0x80>
mov    -0x8(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    125a <main+0xca>
lea    0xe03(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%esi
mov    0x2da5(%rip),%rax
mov    (%rax),%ecx
lea    0xdec(%rip),%rdi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12c2 <main+0x132>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1298 <main+0x108>
mov    $0x0,%al
call   10b0 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x3f,%edx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1261 <main+0xd1>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    0x2d3a(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xe83(%rip),%rdi
call   1060 <puts@plt>
lea    0xe56(%rip),%rdi
call   1030 <getenv@plt>
mov    $0x2800,%r14d
test   %rax,%rax
je     11e4 <main+0x54>
mov    %rax,%rbx
lea    0xe49(%rip),%rsi
mov    %rax,%rdi
mov    $0x5,%edx
call   1050 <strncmp@plt>
test   %eax,%eax
jne    11e4 <main+0x54>
add    $0x5,%rbx
mov    %rbx,%rdi
call   1090 <atoi@plt>
mov    %eax,%r14d
mov    %r14d,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     125b <main+0xcb>
mov    %rax,%r15
test   %r14d,%r14d
jle    1236 <main+0xa6>
mov    %r14d,%ebp
xor    %ebx,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   10b0 <rand@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x3f,%al
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1200 <main+0x70>
mov    0x2da3(%rip),%rax
mov    (%rax),%ecx
mov    %r15,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    %r15,%rdi
call   1040 <free@plt>
xor    %eax,%eax
jmp    1287 <main+0xf7>
lea    0xdb1(%rip),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    0x2d6f(%rip),%rcx
mov    (%rcx),%ecx
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Content-type: text/plain\0D\0A\0D\0A\00"
@.str.1 = [13 x i8] c"QUERY_STRING\00"
@.str.2 = [6 x i8] c"size=\00"
@.str.3 = [14 x i8] c"Out of memory\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%7 = call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i8* %7, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %0
store i32 10240, i32* %2
br label %20
10: ; preds = %0
%11 = load i8*, i8** %3
%12 = call i32 @strncmp(i8* %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%13 = icmp ne i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 5
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %2
br label %19
18: ; preds = %10
store i32 10240, i32* %2
br label %19
19: ; preds = %18, %14
br label %20
20: ; preds = %19, %9
%21 = load i32, i32* %2
%22 = call i64 @malloc(i32 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %4
%24 = icmp ne i8* %23, null
br i1 %24, label %29, label %25
25: ; preds = %20
%26 = call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%27 = load i32, i32* @stdout
%28 = call i32 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %26, i32 1, i32 %27)
store i32 -1, i32* %1
br label %53
29: ; preds = %20
store i32 0, i32* %5
br label %30
30: ; preds = %43, %29
%31 = load i32, i32* %5
%32 = load i32, i32* %2
%33 = icmp slt i32 %31, %32
br i1 %33, label %34, label %46
34: ; preds = %30
%35 = call i32 (...) @rand()
%36 = srem i32 %35, 26
%37 = add nsw i32 %36, 63
%38 = trunc i32 %37 to i8
%39 = load i8*, i8** %4
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 %38, i8* %42
br label %43
43: ; preds = %34
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %30
46: ; preds = %30
%47 = load i8*, i8** %4
%48 = load i32, i32* %2
%49 = load i32, i32* @stdout
%50 = call i32 @fwrite(i8* %47, i32 %48, i32 1, i32 %49)
%51 = load i8*, i8** %4
%52 = call i32 @free(i8* %51)
store i32 0, i32* %1
br label %53
53: ; preds = %46, %25
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str.1 = [13 x i8] c"QUERY_STRING\00"
@.str.2 = [6 x i8] c"size=\00"
@.str.3 = [14 x i8] c"Out of memory\00"
@stdout = global i32 0
@str = [28 x i8] c"Content-type: text/plain\0D\0A\0D\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%2 = tail call i8* @getenv(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %10, label %4
4: ; preds = %0
%5 = tail call i32 @strncmp(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = getelementptr inbounds i8, i8* %2, i64 5
%9 = tail call i32 @atoi(i8* %8)
br label %10
10: ; preds = %4, %0, %7
%11 = phi i32 [ %9, %7 ], [ 10240, %0 ], [ 10240, %4 ]
%12 = tail call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
%14 = icmp eq i64 %12, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = icmp sgt i32 %11, 0
br i1 %16, label %17, label %32
17: ; preds = %15
%18 = zext i32 %11 to i64
br label %23
19: ; preds = %10
%20 = tail call i32 @strlen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @stdout
%22 = tail call i32 @fwrite(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 1, i32 %21)
br label %36
23: ; preds = %17, %23
%24 = phi i64 [ 0, %17 ], [ %30, %23 ]
%25 = tail call i32 (...) @rand()
%26 = srem i32 %25, 26
%27 = trunc i32 %26 to i8
%28 = add nsw i8 %27, 63
%29 = getelementptr inbounds i8, i8* %13, i64 %24
store i8 %28, i8* %29
%30 = add nuw nsw i64 %24, 1
%31 = icmp eq i64 %30, %18
br i1 %31, label %32, label %23
32: ; preds = %23, %15
%33 = load i32, i32* @stdout
%34 = tail call i32 @fwrite(i8* %13, i32 %11, i32 1, i32 %33)
%35 = tail call i32 @free(i8* %13)
br label %36
36: ; preds = %32, %19
%37 = phi i32 [ 0, %32 ], [ -1, %19 ]
ret i32 %37
}