#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*/ abort();
int /*<<< orphan*/ alloc(void **, int);
int /*<<< orphan*/ memset(void **, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int random();
int /*<<< orphan*/ release(void **, int);
int main(int argc, char **argv) {
  void *pool[1024];
  int i;
  int count = 0;
  memset(pool, 0, sizeof(void *) * 1024);
  for (i = 0; i < 1114; i++) {
    switch (random() % 2) {
    case 0:
      alloc(pool, random() % 1024);
      break;
    case 1:
      release(pool, random() % 1024);
      break;
    default:
      printf("EER\n");
      abort();
    }
  }
  for (i = 0; i < 1024; i++) {
    if (pool[i] != NULL) {
      count++;
    }
  }
  printf("Still allocated: %d\n", count);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2018(%rbp)
lea    -0x2010(%rbp),%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1050 <memset@plt>
movl   $0x0,-0x2014(%rbp)
cmpl   $0x45a,-0x2014(%rbp)
jge    1278 <main+0x118>
xor    %eax,%eax
call   1060 <random@plt>
mov    %eax,%edx
shr    $0x1f,%edx
mov    %eax,%ecx
add    %edx,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
mov    %eax,-0x201c(%rbp)
je     11ea <main+0x8a>
jmp    11d6 <main+0x76>
mov    -0x201c(%rbp),%eax
sub    $0x1,%eax
je     121a <main+0xba>
jmp    124a <main+0xea>
lea    -0x2010(%rbp),%rax
mov    %rax,-0x2028(%rbp)
mov    $0x0,%al
call   1060 <random@plt>
mov    -0x2028(%rbp),%rdi
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
call   1070 <alloc@plt>
jmp    125f <main+0xff>
lea    -0x2010(%rbp),%rax
mov    %rax,-0x2030(%rbp)
mov    $0x0,%al
call   1060 <random@plt>
mov    -0x2030(%rbp),%rdi
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
call   1080 <release@plt>
jmp    125f <main+0xff>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1264 <main+0x104>
mov    -0x2014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2014(%rbp)
jmp    11a0 <main+0x40>
movl   $0x0,-0x2014(%rbp)
cmpl   $0x400,-0x2014(%rbp)
jge    12d0 <main+0x170>
movslq -0x2014(%rbp),%rax
cmpq   $0x0,-0x2010(%rbp,%rax,8)
je     12b7 <main+0x157>
mov    -0x2018(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2018(%rbp)
jmp    12bc <main+0x15c>
mov    -0x2014(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2014(%rbp)
jmp    1282 <main+0x122>
mov    -0x2018(%rbp),%esi
lea    0xd28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x2008,%rsp
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2000,%edx
call   1060 <memset@plt>
mov    $0x45a,%ebp
jmp    11c9 <main+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <random@plt>
lea    0x3ff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffc00,%ecx
sub    %ecx,%eax
mov    %rbx,%rdi
mov    %eax,%esi
call   1090 <release@plt>
add    $0xffffffff,%ebp
je     1212 <main+0xa2>
xor    %eax,%eax
call   1070 <random@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
and    $0xfffffffe,%ecx
sub    %ecx,%eax
cmp    $0x1,%eax
je     11a0 <main+0x30>
test   %eax,%eax
jne    1269 <main+0xf9>
xor    %eax,%eax
call   1070 <random@plt>
lea    0x3ff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffc00,%ecx
sub    %ecx,%eax
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <alloc@plt>
add    $0xffffffff,%ebp
jne    11c9 <main+0x59>
xor    %eax,%eax
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
cmpq   $0x1,(%rsp,%rax,8)
sbb    $0xffffffff,%esi
cmpq   $0x1,0x8(%rsp,%rax,8)
sbb    $0xffffffff,%esi
cmpq   $0x1,0x10(%rsp,%rax,8)
sbb    $0xffffffff,%esi
cmpq   $0x1,0x18(%rsp,%rax,8)
sbb    $0xffffffff,%esi
add    $0x4,%rax
cmp    $0x400,%rax
jne    1220 <main+0xb0>
lea    0xdaa(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x2008,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xda5(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"EER\0A\00"
@.str.1 = [21 x i8] c"Still allocated: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8*]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%9 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 0
%10 = call i32 @memset(i8** %9, i32 0, i32 8192)
store i32 0, i32* %7
br label %11
11: ; preds = %31, %2
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 1114
br i1 %13, label %14, label %34
14: ; preds = %11
%15 = call i32 (...) @random()
%16 = srem i32 %15, 2
switch i32 %16, label %27 [
i32 0, label %17
i32 1, label %22
]
17: ; preds = %14
%18 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 0
%19 = call i32 (...) @random()
%20 = srem i32 %19, 1024
%21 = call i32 @alloc(i8** %18, i32 %20)
br label %30
22: ; preds = %14
%23 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 0
%24 = call i32 (...) @random()
%25 = srem i32 %24, 1024
%26 = call i32 @release(i8** %23, i32 %25)
br label %30
27: ; preds = %14
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%29 = call i32 (...) @abort()
unreachable
30: ; preds = %22, %17
br label %31
31: ; preds = %30
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %11
34: ; preds = %11
store i32 0, i32* %7
br label %35
35: ; preds = %48, %34
%36 = load i32, i32* %7
%37 = icmp slt i32 %36, 1024
br i1 %37, label %38, label %51
38: ; preds = %35
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %6, i64 0, i64 %40
%42 = load i8*, i8** %41
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %47
47: ; preds = %44, %38
br label %48
48: ; preds = %47
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
store i32 %50, i32* %7
br label %35
51: ; preds = %35
%52 = load i32, i32* %8
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %52)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [21 x i8] c"Still allocated: %d\0A\00"
@str = [4 x i8] c"EER\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8*]
%4 = bitcast [1024 x i8*]* %3 to i8*
%5 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %3, i64 0, i64 0
%6 = call i32 @memset(i8** %5, i32 0, i32 8192)
br label %7
7: ; preds = %2, %22
%8 = phi i32 [ 0, %2 ], [ %23, %22 ]
%9 = call i32 (...) @random()
%10 = srem i32 %9, 2
switch i32 %10, label %19 [
i32 0, label %11
i32 1, label %15
]
11: ; preds = %7
%12 = call i32 (...) @random()
%13 = srem i32 %12, 1024
%14 = call i32 @alloc(i8** %5, i32 %13)
br label %22
15: ; preds = %7
%16 = call i32 (...) @random()
%17 = srem i32 %16, 1024
%18 = call i32 @release(i8** %5, i32 %17)
br label %22
19: ; preds = %7
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%21 = call i32 (...) @abort()
unreachable
22: ; preds = %11, %15
%23 = add nuw nsw i32 %8, 1
%24 = icmp eq i32 %23, 1114
br i1 %24, label %25, label %7
25: ; preds = %22, %25
%26 = phi i64 [ %51, %25 ], [ 0, %22 ]
%27 = phi i32 [ %50, %25 ], [ 0, %22 ]
%28 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %3, i64 0, i64 %26
%29 = load i8*, i8** %28
%30 = icmp ne i8* %29, null
%31 = zext i1 %30 to i32
%32 = add nuw nsw i32 %27, %31
%33 = or i64 %26, 1
%34 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %3, i64 0, i64 %33
%35 = load i8*, i8** %34
%36 = icmp ne i8* %35, null
%37 = zext i1 %36 to i32
%38 = add nuw nsw i32 %32, %37
%39 = or i64 %26, 2
%40 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %3, i64 0, i64 %39
%41 = load i8*, i8** %40
%42 = icmp ne i8* %41, null
%43 = zext i1 %42 to i32
%44 = add nuw nsw i32 %38, %43
%45 = or i64 %26, 3
%46 = getelementptr inbounds [1024 x i8*], [1024 x i8*]* %3, i64 0, i64 %45
%47 = load i8*, i8** %46
%48 = icmp ne i8* %47, null
%49 = zext i1 %48 to i32
%50 = add nuw nsw i32 %44, %49
%51 = add nuw nsw i64 %26, 4
%52 = icmp eq i64 %51, 1024
br i1 %52, label %53, label %25
53: ; preds = %25
%54 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %50)
ret i32 0
}