#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*/ exit(int);
scalar_t__ oomtest(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ srand(int);
int main(void) {
  srand(1234);
  for (int i = 0; i < 100000; i++) {
    if (oomtest(i)) {
      printf("Test failed\n");
      exit(1);
    }
  }
  printf("Test OK!\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4d2,%edi
call   1040 <srand@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x186a0,-0x8(%rbp)
jge    11a8 <main+0x68>
mov    -0x8(%rbp),%edi
call   1060 <oomtest@plt>
cmp    $0x0,%rax
je     1195 <main+0x55>
lea    0xe7a(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
jmp    119a <main+0x5a>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1160 <main+0x20>
lea    0xe5e(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x4d2,%edi
call   1040 <srand@plt>
xor    %ebx,%ebx
nopl   (%rax)
mov    %ebx,%edi
call   1060 <oomtest@plt>
test   %rax,%rax
jne    1177 <main+0x37>
add    $0x1,%ebx
cmp    $0x186a0,%ebx
jne    1150 <main+0x10>
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"Test failed\0A\00"
@.str.1 = [10 x i8] c"Test OK!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 @srand(i32 1234)
store i32 0, i32* %2
br label %4
4: ; preds = %15, %0
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 100000
br i1 %6, label %7, label %18
7: ; preds = %4
%8 = load i32, i32* %2
%9 = call i64 @oomtest(i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %7
br label %15
15: ; preds = %14
%16 = load i32, i32* %2
%17 = add nsw i32 %16, 1
store i32 %17, i32* %2
br label %4
18: ; preds = %4
%19 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@str = [9 x i8] c"Test OK!\00"
@str.2 = [12 x i8] c"Test failed\00"
define i32 @main() {
%1 = tail call i32 @srand(i32 1234)
br label %7
2: ; preds = %7
%3 = add nuw nsw i32 %8, 1
%4 = icmp eq i32 %3, 100000
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
ret i32 0
7: ; preds = %0, %2
%8 = phi i32 [ 0, %0 ], [ %3, %2 ]
%9 = tail call i64 @oomtest(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %2, label %11
11: ; preds = %7
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.2, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
}