#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__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  double *pointer;
  int x;
  unsigned long int space = 0;
  pointer = (double *)malloc(2);
  for (x = 99999999; x < 9999999999999999; x++) {
    space = +x;
    if (pointer == (char *)NULL) {
      printf("Out of memory");
      return 0;
    } else {
      pointer = (double *)malloc(x);
    }
    x += x;
    printf("Pointer occupies %d\n", space);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x2,%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x5f5e0ff,-0x14(%rbp)
movslq -0x14(%rbp),%rax
movabs $0x2386f26fc0ffff,%rcx
cmp    %rcx,%rax
jge    11c5 <main+0xa5>
movslq -0x14(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1190 <main+0x70>
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11cc <main+0xac>
mov    -0x14(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114c <main+0x2c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x2,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1165 <main+0x45>
mov    $0x5f5e0ff,%eax
lea    0xece(%rip),%r14
movslq %eax,%rbx
mov    %ebx,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    (%rbx,%rbx,1),%eax
add    $0x1,%eax
test   %r15,%r15
jne    1140 <main+0x20>
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Out of memory\00"
@.str.1 = [21 x i8] c"Pointer occupies %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double*
%3 = alloca i32
%4 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %4
%5 = call i64 @malloc(i32 2)
%6 = inttoptr i64 %5 to double*
store double* %6, double** %2
store i32 99999999, i32* %3
br label %7
7: ; preds = %28, %0
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = icmp slt i64 %9, 9999999999999999
br i1 %10, label %11, label %31
11: ; preds = %7
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
store i64 %13, i64* %4
%14 = load double*, double** %2
%15 = icmp eq double* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %32
18: ; preds = %11
%19 = load i32, i32* %3
%20 = call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to double*
store double* %21, double** %2
br label %22
22: ; preds = %18
%23 = load i32, i32* %3
%24 = load i32, i32* %3
%25 = add nsw i32 %24, %23
store i32 %25, i32* %3
%26 = load i64, i64* %4
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %26)
br label %28
28: ; preds = %22
%29 = load i32, i32* %3
%30 = add nsw i32 %29, 1
store i32 %30, i32* %3
br label %7
31: ; preds = %7
store i32 0, i32* %1
br label %32
32: ; preds = %31, %16
%33 = load i32, i32* %1
ret i32 %33
}

LLVM IR (-O2):
@.str = [14 x i8] c"Out of memory\00"
@.str.1 = [21 x i8] c"Pointer occupies %d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 2)
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %5
3: ; preds = %5, %0
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
ret i32 0
5: ; preds = %0, %5
%6 = phi i32 [ %11, %5 ], [ 99999999, %0 ]
%7 = sext i32 %6 to i64
%8 = tail call i64 @malloc(i32 %6)
%9 = shl nsw i32 %6, 1
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i64 %7)
%11 = or i32 %9, 1
%12 = icmp eq i64 %8, 0
br i1 %12, label %3, label %5
}