#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 init_completion(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int main(int argc, char **argv) {
  int how_many;
  int i;
  sscanf(argv[1], "%d", &how_many);
  for (i = 0; i != how_many; ++i) {
    int res;
    char tmp[40];
    sprintf(tmp, "%d", i);
    res = init_completion(tmp);
    if (i < 2048 && res) {
      return 1;
    }
    if (i >= 2048 && !res) {
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeab(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <sscanf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     11e9 <main+0xb9>
lea    -0x50(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe81(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x50(%rbp),%rdi
call   1030 <init_completion@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x800,-0x18(%rbp)
jge    11b3 <main+0x83>
cmpl   $0x0,-0x1c(%rbp)
je     11b3 <main+0x83>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <main+0xc0>
cmpl   $0x800,-0x18(%rbp)
jl     11d6 <main+0xa6>
cmpl   $0x0,-0x1c(%rbp)
jne    11d6 <main+0xa6>
movl   $0x1,-0x4(%rbp)
jmp    11f0 <main+0xc0>
jmp    11db <main+0xab>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1165 <main+0x35>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    0x8(%rsi),%rdi
lea    0xeb9(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1040 <sscanf@plt>
cmpl   $0x0,0xc(%rsp)
je     11b5 <main+0x85>
xor    %ebx,%ebx
lea    0xe9f(%rip),%r14
lea    0x10(%rsp),%r15
mov    $0x1,%r12d
xor    %ebp,%ebp
xchg   %ax,%ax
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <sprintf@plt>
mov    %r15,%rdi
call   1030 <init_completion@plt>
cmp    $0x800,%ebp
setb   %cl
test   %eax,%eax
setne  %al
mov    %ecx,%edx
and    %al,%dl
or     %al,%cl
cmove  %r12d,%ebx
test   %dl,%dl
cmovne %r12d,%ebx
cmp    $0x1,%dl
je     11b7 <main+0x87>
test   %cl,%cl
je     11b7 <main+0x87>
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jne    1170 <main+0x40>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\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 i32
%9 = alloca [40 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32 @sscanf(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
store i32 0, i32* %7
br label %14
14: ; preds = %38, %2
%15 = load i32, i32* %7
%16 = load i32, i32* %6
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %41
18: ; preds = %14
%19 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%20 = load i32, i32* %7
%21 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = getelementptr inbounds [40 x i8], [40 x i8]* %9, i64 0, i64 0
%23 = call i32 @init_completion(i8* %22)
store i32 %23, i32* %8
%24 = load i32, i32* %7
%25 = icmp slt i32 %24, 2048
br i1 %25, label %26, label %30
26: ; preds = %18
%27 = load i32, i32* %8
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 1, i32* %3
br label %42
30: ; preds = %26, %18
%31 = load i32, i32* %7
%32 = icmp sge i32 %31, 2048
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %33
store i32 1, i32* %3
br label %42
37: ; preds = %33, %30
br label %38
38: ; preds = %37
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %14
41: ; preds = %14
store i32 0, i32* %3
br label %42
42: ; preds = %41, %36, %29
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [40 x i8]
%5 = bitcast i32* %3 to i8*
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, 0
br i1 %10, label %30, label %11
11: ; preds = %2
%12 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
br label %16
13: ; preds = %16
%14 = load i32, i32* %3
%15 = icmp eq i32 %29, %14
br i1 %15, label %30, label %16
16: ; preds = %11, %13
%17 = phi i32 [ 0, %11 ], [ %26, %13 ]
%18 = phi i32 [ 0, %11 ], [ %29, %13 ]
%19 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = call i32 @init_completion(i8* %12)
%21 = icmp ult i32 %18, 2048
%22 = icmp ne i32 %20, 0
%23 = select i1 %21, i1 %22, i1 false
%24 = select i1 %21, i1 true, i1 %22
%25 = select i1 %24, i32 %17, i32 1
%26 = select i1 %23, i32 1, i32 %25
%27 = xor i1 %23, true
%28 = select i1 %27, i1 %24, i1 false
%29 = add nuw nsw i32 %18, 1
br i1 %28, label %13, label %30
30: ; preds = %16, %13, %2
%31 = phi i32 [ 0, %2 ], [ 0, %13 ], [ %26, %16 ]
ret i32 %31
}