#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 */
scalar_t__ check(size_t, int);
int /*<<< orphan*/ demo(int, int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  size_t x;
  for (x = 6; x < 2048; x *= 2) {
    printf("checking input size = %zu \n ", x);
    if (check(x, 1024 * 1024))
      return -1;
    printf("Ok!\n ");
  }
  demo(1024, 1024 * 1024);
  demo(1024 * 1024, 1024 * 1024);
  demo(32 * 1024 * 1024, 1024 * 1024);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x6,-0x10(%rbp)
cmpq   $0x800,-0x10(%rbp)
jae    11aa <main+0x7a>
mov    -0x10(%rbp),%rsi
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x100000,%esi
call   1050 <check@plt>
cmp    $0x0,%rax
je     118b <main+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11db <main+0xab>
lea    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1147 <main+0x17>
mov    $0x400,%edi
mov    $0x100000,%esi
call   1040 <demo@plt>
mov    $0x100000,%esi
mov    %esi,%edi
call   1040 <demo@plt>
mov    $0x2000000,%edi
mov    $0x100000,%esi
call   1040 <demo@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xec8(%rip),%rdi
mov    $0x6,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x6,%edi
mov    $0x100000,%esi
call   1050 <check@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    135e <main+0x22e>
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe8a(%rip),%rdi
mov    $0xc,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xc,%edi
mov    $0x100000,%esi
call   1050 <check@plt>
test   %rax,%rax
jne    135e <main+0x22e>
lea    0xe7c(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe51(%rip),%rdi
mov    $0x18,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x18,%edi
mov    $0x100000,%esi
call   1050 <check@plt>
test   %rax,%rax
jne    135e <main+0x22e>
lea    0xe43(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe18(%rip),%rdi
mov    $0x30,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x30,%edi
mov    $0x100000,%esi
call   1050 <check@plt>
test   %rax,%rax
jne    135e <main+0x22e>
lea    0xe0a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xddf(%rip),%rdi
mov    $0x60,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x60,%edi
mov    $0x100000,%esi
call   1050 <check@plt>
test   %rax,%rax
jne    135e <main+0x22e>
lea    0xdd1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xda6(%rip),%rdi
mov    $0xc0,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xc0,%edi
mov    $0x100000,%esi
call   1050 <check@plt>
test   %rax,%rax
jne    135e <main+0x22e>
lea    0xd98(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xd6d(%rip),%rdi
mov    $0x180,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x180,%edi
mov    $0x100000,%esi
call   1050 <check@plt>
test   %rax,%rax
jne    135e <main+0x22e>
lea    0xd5f(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xd34(%rip),%rdi
mov    $0x300,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x300,%edi
mov    $0x100000,%esi
call   1050 <check@plt>
test   %rax,%rax
jne    135e <main+0x22e>
lea    0xd2a(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xcff(%rip),%rdi
mov    $0x600,%esi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x600,%edi
mov    $0x100000,%esi
call   1050 <check@plt>
test   %rax,%rax
jne    135e <main+0x22e>
lea    0xcf5(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x400,%edi
mov    $0x100000,%esi
call   1040 <demo@plt>
mov    $0x100000,%edi
mov    $0x100000,%esi
call   1040 <demo@plt>
mov    $0x2000000,%edi
mov    $0x100000,%esi
call   1040 <demo@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [29 x i8] c"checking input size = %zu \0A \00"
@.str.1 = [6 x i8] c"Ok!\0A \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
store i64 6, i64* %2
br label %3
3: ; preds = %15, %0
%4 = load i64, i64* %2
%5 = icmp ult i64 %4, 2048
br i1 %5, label %6, label %18
6: ; preds = %3
%7 = load i64, i64* %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 %7)
%9 = load i64, i64* %2
%10 = call i64 @check(i64 %9, i32 1048576)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %6
store i32 -1, i32* %1
br label %22
13: ; preds = %6
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13
%16 = load i64, i64* %2
%17 = mul i64 %16, 2
store i64 %17, i64* %2
br label %3
18: ; preds = %3
%19 = call i32 @demo(i32 1024, i32 1048576)
%20 = call i32 @demo(i32 1048576, i32 1048576)
%21 = call i32 @demo(i32 33554432, i32 1048576)
store i32 0, i32* %1
br label %22
22: ; preds = %18, %12
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str = [29 x i8] c"checking input size = %zu \0A \00"
@.str.1 = [6 x i8] c"Ok!\0A \00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 6)
%2 = tail call i64 @check(i64 6, i32 1048576)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %49
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 12)
%7 = tail call i64 @check(i64 12, i32 1048576)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %49
9: ; preds = %4
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 24)
%12 = tail call i64 @check(i64 24, i32 1048576)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %49
14: ; preds = %9
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 48)
%17 = tail call i64 @check(i64 48, i32 1048576)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %49
19: ; preds = %14
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 96)
%22 = tail call i64 @check(i64 96, i32 1048576)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %49
24: ; preds = %19
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 192)
%27 = tail call i64 @check(i64 192, i32 1048576)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %49
29: ; preds = %24
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 384)
%32 = tail call i64 @check(i64 384, i32 1048576)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %49
34: ; preds = %29
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%36 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 768)
%37 = tail call i64 @check(i64 768, i32 1048576)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %34
%40 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 1536)
%42 = tail call i64 @check(i64 1536, i32 1048576)
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %39
%45 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%46 = tail call i32 @demo(i32 1024, i32 1048576)
%47 = tail call i32 @demo(i32 1048576, i32 1048576)
%48 = tail call i32 @demo(i32 33554432, i32 1048576)
br label %49
49: ; preds = %0, %4, %9, %14, %19, %24, %29, %34, %39, %44
%50 = phi i32 [ 0, %44 ], [ -1, %39 ], [ -1, %34 ], [ -1, %29 ], [ -1, %24 ], [ -1, %19 ], [ -1, %14 ], [ -1, %9 ], [ -1, %4 ], [ -1, %0 ]
ret i32 %50
}