#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*/ GC_INIT();
int **GC_MALLOC(int);
int *GC_MALLOC_ATOMIC(int);
int *GC_REALLOC(int *, int);
scalar_t__ GC_get_heap_size();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, unsigned long);
int /*<<< orphan*/ stderr;
int main(void) {
  int i;
  unsigned long last_heap_size = 0;
  GC_INIT();
  for (i = 0; i < 10000000; i++) {
    int **p = GC_MALLOC(sizeof(int *));
    int *q = GC_MALLOC_ATOMIC(sizeof(int));
    if (*p != 0) {
      fprintf(stderr, "GC_malloc returned garbage\n");
      exit(1);
    }
    *p = GC_REALLOC(q, 2 * sizeof(int));
    if (i % 10 == 0) {
      unsigned long heap_size = (unsigned long)GC_get_heap_size();
      if (heap_size != last_heap_size) {
        printf("Heap size: %lu\n", heap_size);
        last_heap_size = heap_size;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    $0x0,%al
call   1070 <GC_INIT@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x989680,-0x8(%rbp)
jge    1270 <main+0xf0>
mov    $0x8,%edi
call   1090 <GC_MALLOC@plt>
mov    %rax,-0x18(%rbp)
mov    $0x4,%edi
call   10a0 <GC_MALLOC_ATOMIC@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     11fb <main+0x7b>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   1050 <GC_REALLOC@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    125d <main+0xdd>
mov    $0x0,%al
call   1030 <GC_get_heap_size@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     1258 <main+0xd8>
mov    -0x28(%rbp),%rsi
lea    0xdd1(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    125d <main+0xdd>
jmp    1262 <main+0xe2>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a5 <main+0x25>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <GC_INIT@plt>
mov    $0xcccccccd,%r15d
xor    %ebp,%ebp
xor    %r12d,%r12d
xor    %r13d,%r13d
jmp    11bf <main+0x3f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r12d
add    $0xffffffff,%ebp
cmp    $0xff676980,%ebp
je     1228 <main+0xa8>
mov    $0x8,%edi
call   1090 <GC_MALLOC@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   10a0 <GC_MALLOC_ATOMIC@plt>
cmpq   $0x0,(%rbx)
jne    1239 <main+0xb9>
mov    %r12d,%ecx
imul   %r15,%rcx
shr    $0x23,%rcx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%r14d
neg    %r14d
mov    %rax,%rdi
mov    $0x8,%esi
call   1050 <GC_REALLOC@plt>
mov    %rax,(%rbx)
cmp    %ebp,%r14d
jne    11b0 <main+0x30>
xor    %eax,%eax
call   1030 <GC_get_heap_size@plt>
cmp    %r13,%rax
je     11b0 <main+0x30>
mov    %rax,%rbx
lea    0xe01(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %rbx,%r13
jmp    11b0 <main+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"GC_malloc returned garbage\0A\00"
@.str.1 = [16 x i8] c"Heap size: %lu\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i32**
%5 = alloca i32*
%6 = alloca i64
store i32 0, i32* %1
store i64 0, i64* %3
%7 = call i32 (...) @GC_INIT()
store i32 0, i32* %2
br label %8
8: ; preds = %39, %0
%9 = load i32, i32* %2
%10 = icmp slt i32 %9, 10000000
br i1 %10, label %11, label %42
11: ; preds = %8
%12 = call i32** @GC_MALLOC(i32 8)
store i32** %12, i32*** %4
%13 = call i32* @GC_MALLOC_ATOMIC(i32 4)
store i32* %13, i32** %5
%14 = load i32**, i32*** %4
%15 = load i32*, i32** %14
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %11
%22 = load i32*, i32** %5
%23 = call i32* @GC_REALLOC(i32* %22, i32 8)
%24 = load i32**, i32*** %4
store i32* %23, i32** %24
%25 = load i32, i32* %2
%26 = srem i32 %25, 10
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %21
%29 = call i64 (...) @GC_get_heap_size()
store i64 %29, i64* %6
%30 = load i64, i64* %6
%31 = load i64, i64* %3
%32 = icmp ne i64 %30, %31
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i64, i64* %6
%35 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %34)
%36 = load i64, i64* %6
store i64 %36, i64* %3
br label %37
37: ; preds = %33, %28
br label %38
38: ; preds = %37, %21
br label %39
39: ; preds = %38
%40 = load i32, i32* %2
%41 = add nsw i32 %40, 1
store i32 %41, i32* %2
br label %8
42: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"GC_malloc returned garbage\0A\00"
@.str.1 = [16 x i8] c"Heap size: %lu\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @GC_INIT()
br label %2
2: ; preds = %0, %22
%3 = phi i32 [ 0, %0 ], [ %24, %22 ]
%4 = phi i64 [ 0, %0 ], [ %23, %22 ]
%5 = tail call i32** @GC_MALLOC(i32 8)
%6 = tail call i32* @GC_MALLOC_ATOMIC(i32 4)
%7 = load i32*, i32** %5
%8 = icmp eq i32* %7, null
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = tail call i32* @GC_REALLOC(i32* %6, i32 8)
store i32* %14, i32** %5
%15 = urem i32 %3, 10
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = tail call i64 (...) @GC_get_heap_size()
%19 = icmp eq i64 %18, %4
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i64 %18)
br label %22
22: ; preds = %17, %20, %13
%23 = phi i64 [ %4, %13 ], [ %18, %20 ], [ %4, %17 ]
%24 = add nuw nsw i32 %3, 1
%25 = icmp eq i32 %24, 10000000
br i1 %25, label %26, label %2
26: ; preds = %22
ret i32 0
}