#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 */
typedef int /*<<< orphan*/ tmp;

/* Variables and functions */
int completion_exists(char *);
int init_completion(char *);
int /*<<< orphan*/ memset(char *, char, int);
int main(int argc, char **argv) {
  int i;
  int how_many = 2048 * 2;
  char tmp[4096 * 2];
  memset(tmp, 'a', sizeof(tmp));
  tmp[sizeof(tmp) - 2] = 0;
  for (i = 0; i != how_many; ++i) {
    int res;
    res = completion_exists(tmp);
    if (res) {
      return 1;
    }
    res = init_completion(tmp);
    if (!res) {
      return 1;
    }
  }
  tmp[4096] = 0;
  for (i = 0; i != how_many; ++i) {
    int res;
    res = init_completion(tmp);
    if (!res) {
      return 1;
    }
  }
  how_many = 2048;
  tmp[4096 - 1] = 0;
  for (i = 0; i != how_many; ++i) {
    int res;
    res = init_completion(tmp);
    if (res) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1000,-0x18(%rbp)
lea    -0x2020(%rbp),%rdi
mov    $0x61,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
movb   $0x0,-0x22(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     11e6 <main+0xb6>
lea    -0x2020(%rbp),%rdi
call   1030 <completion_exists@plt>
mov    %eax,-0x2024(%rbp)
cmpl   $0x0,-0x2024(%rbp)
je     11a8 <main+0x78>
movl   $0x1,-0x4(%rbp)
jmp    12a4 <main+0x174>
lea    -0x2020(%rbp),%rdi
call   1050 <init_completion@plt>
mov    %eax,-0x2024(%rbp)
cmpl   $0x0,-0x2024(%rbp)
jne    11d3 <main+0xa3>
movl   $0x1,-0x4(%rbp)
jmp    12a4 <main+0x174>
jmp    11d8 <main+0xa8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1171 <main+0x41>
movb   $0x0,-0x1020(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     123e <main+0x10e>
lea    -0x2020(%rbp),%rdi
call   1050 <init_completion@plt>
mov    %eax,-0x2028(%rbp)
cmpl   $0x0,-0x2028(%rbp)
jne    122b <main+0xfb>
movl   $0x1,-0x4(%rbp)
jmp    12a4 <main+0x174>
jmp    1230 <main+0x100>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f4 <main+0xc4>
movl   $0x800,-0x18(%rbp)
movb   $0x0,-0x1021(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     129d <main+0x16d>
lea    -0x2020(%rbp),%rdi
call   1050 <init_completion@plt>
mov    %eax,-0x202c(%rbp)
cmpl   $0x0,-0x202c(%rbp)
je     128a <main+0x15a>
movl   $0x1,-0x4(%rbp)
jmp    12a4 <main+0x174>
jmp    128f <main+0x15f>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1253 <main+0x123>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2000,%rsp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x61,%esi
mov    $0x2000,%edx
call   1040 <memset@plt>
movb   $0x0,0x1ffe(%rsp)
mov    $0x1000,%ebp
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <completion_exists@plt>
test   %eax,%eax
jne    11e3 <main+0xb3>
mov    %r14,%rdi
call   1050 <init_completion@plt>
test   %eax,%eax
je     11e3 <main+0xb3>
add    $0xffffffff,%ebp
jne    1170 <main+0x40>
movb   $0x0,0x1000(%rsp)
mov    $0x1000,%ebp
mov    %rsp,%r14
nopl   (%rax)
mov    %r14,%rdi
call   1050 <init_completion@plt>
test   %eax,%eax
je     11e3 <main+0xb3>
add    $0xffffffff,%ebp
jne    11a0 <main+0x70>
movb   $0x0,0xfff(%rsp)
mov    $0x800,%ebp
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <init_completion@plt>
test   %eax,%eax
jne    11e3 <main+0xb3>
add    $0xffffffff,%ebp
jne    11d0 <main+0xa0>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x2000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [8192 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4096, i32* %7
%12 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i8 signext 97, i32 8192)
%14 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 8190
store i8 0, i8* %14
store i32 0, i32* %6
br label %15
15: ; preds = %32, %2
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %35
19: ; preds = %15
%20 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%21 = call i32 @completion_exists(i8* %20)
store i32 %21, i32* %9
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 1, i32* %3
br label %68
25: ; preds = %19
%26 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%27 = call i32 @init_completion(i8* %26)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = icmp ne i32 %28, 0
br i1 %29, label %31, label %30
30: ; preds = %25
store i32 1, i32* %3
br label %68
31: ; preds = %25
br label %32
32: ; preds = %31
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %15
35: ; preds = %15
%36 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 4096
store i8 0, i8* %36
store i32 0, i32* %6
br label %37
37: ; preds = %48, %35
%38 = load i32, i32* %6
%39 = load i32, i32* %7
%40 = icmp ne i32 %38, %39
br i1 %40, label %41, label %51
41: ; preds = %37
%42 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%43 = call i32 @init_completion(i8* %42)
store i32 %43, i32* %10
%44 = load i32, i32* %10
%45 = icmp ne i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %41
store i32 1, i32* %3
br label %68
47: ; preds = %41
br label %48
48: ; preds = %47
%49 = load i32, i32* %6
%50 = add nsw i32 %49, 1
store i32 %50, i32* %6
br label %37
51: ; preds = %37
store i32 2048, i32* %7
%52 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 4095
store i8 0, i8* %52
store i32 0, i32* %6
br label %53
53: ; preds = %64, %51
%54 = load i32, i32* %6
%55 = load i32, i32* %7
%56 = icmp ne i32 %54, %55
br i1 %56, label %57, label %67
57: ; preds = %53
%58 = getelementptr inbounds [8192 x i8], [8192 x i8]* %8, i64 0, i64 0
%59 = call i32 @init_completion(i8* %58)
store i32 %59, i32* %11
%60 = load i32, i32* %11
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %57
store i32 1, i32* %3
br label %68
63: ; preds = %57
br label %64
64: ; preds = %63
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %53
67: ; preds = %53
store i32 0, i32* %3
br label %68
68: ; preds = %67, %62, %46, %30, %24
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [8192 x i8]
%4 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i8 signext 97, i32 8192)
%6 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 8190
store i8 0, i8* %6
br label %9
7: ; preds = %13
%8 = icmp eq i32 %16, 4096
br i1 %8, label %17, label %9
9: ; preds = %2, %7
%10 = phi i32 [ 0, %2 ], [ %16, %7 ]
%11 = call i32 @completion_exists(i8* %4)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %35
13: ; preds = %9
%14 = call i32 @init_completion(i8* %4)
%15 = icmp eq i32 %14, 0
%16 = add nuw nsw i32 %10, 1
br i1 %15, label %35, label %7
17: ; preds = %7
%18 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 4096
store i8 0, i8* %18
br label %21
19: ; preds = %21
%20 = icmp eq i32 %25, 4096
br i1 %20, label %26, label %21
21: ; preds = %17, %19
%22 = phi i32 [ 0, %17 ], [ %25, %19 ]
%23 = call i32 @init_completion(i8* %4)
%24 = icmp eq i32 %23, 0
%25 = add nuw nsw i32 %22, 1
br i1 %24, label %35, label %19
26: ; preds = %19
%27 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 4095
store i8 0, i8* %27
br label %30
28: ; preds = %30
%29 = icmp eq i32 %34, 2048
br i1 %29, label %35, label %30
30: ; preds = %26, %28
%31 = phi i32 [ 0, %26 ], [ %34, %28 ]
%32 = call i32 @init_completion(i8* %4)
%33 = icmp eq i32 %32, 0
%34 = add nuw nsw i32 %31, 1
br i1 %33, label %28, label %35
35: ; preds = %9, %13, %21, %28, %30
%36 = phi i32 [ 0, %28 ], [ 1, %30 ], [ 1, %21 ], [ 1, %13 ], [ 1, %9 ]
ret i32 %36
}