#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 */
struct pool {
  int dummy;
};

/* Variables and functions */
struct pool *pool_alloc(int);
int /*<<< orphan*/ pool_free(struct pool *);
int pool_release(struct pool *, int);
int pool_reserve(struct pool *);
int /*<<< orphan*/ printf(char *, int, ...);
int main(void) {
  struct pool *p;
  int i;
  int reserve_i;
  p = pool_alloc(10);
  for (i = 0; i < 10; i++) {
    reserve_i = pool_reserve(p);
    printf("reserve: %d\n", reserve_i);
    reserve_i = pool_reserve(p);
    printf("reserve: %d\n", reserve_i);
    printf("release(%d): %d\n", reserve_i, pool_release(p, reserve_i));
  }
  for (i = 0; i < 10; i++) {
    printf("release(%d): %d\n", i, pool_release(p, i));
  }
  pool_free(p);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
call   1040 <pool_alloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    11eb <main+0x9b>
mov    -0x10(%rbp),%rdi
call   1070 <pool_reserve@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe6c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <pool_reserve@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe4f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <pool_release@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1174 <main+0x24>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    122f <main+0xdf>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <pool_release@plt>
mov    -0x20(%rbp),%esi
mov    %eax,%edx
lea    0xdf3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f2 <main+0xa2>
mov    -0x10(%rbp),%rdi
call   1060 <pool_free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    $0xa,%ebx
mov    $0xa,%edi
call   1040 <pool_alloc@plt>
mov    %rax,%r12
lea    0xe8f(%rip),%r14
lea    0xe95(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1070 <pool_reserve@plt>
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
call   1070 <pool_reserve@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %ebp,%esi
call   1030 <pool_release@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
add    $0xffffffff,%ebx
jne    1180 <main+0x30>
mov    %r12,%rdi
xor    %esi,%esi
call   1030 <pool_release@plt>
lea    0xe35(%rip),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x1,%esi
call   1030 <pool_release@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x2,%esi
call   1030 <pool_release@plt>
mov    %r14,%rdi
mov    $0x2,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x3,%esi
call   1030 <pool_release@plt>
mov    %r14,%rdi
mov    $0x3,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x4,%esi
call   1030 <pool_release@plt>
mov    %r14,%rdi
mov    $0x4,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x5,%esi
call   1030 <pool_release@plt>
mov    %r14,%rdi
mov    $0x5,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x6,%esi
call   1030 <pool_release@plt>
mov    %r14,%rdi
mov    $0x6,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x7,%esi
call   1030 <pool_release@plt>
mov    %r14,%rdi
mov    $0x7,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x8,%esi
call   1030 <pool_release@plt>
mov    %r14,%rdi
mov    $0x8,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    $0x9,%esi
call   1030 <pool_release@plt>
mov    %r14,%rdi
mov    $0x9,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
call   1060 <pool_free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pool = type { i32 }
@.str = [13 x i8] c"reserve: %d\0A\00"
@.str.1 = [17 x i8] c"release(%d): %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.pool*
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call %struct.pool* @pool_alloc(i32 10)
store %struct.pool* %5, %struct.pool** %2
store i32 0, i32* %3
br label %6
6: ; preds = %23, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 10
br i1 %8, label %9, label %26
9: ; preds = %6
%10 = load %struct.pool*, %struct.pool** %2
%11 = call i32 @pool_reserve(%struct.pool* %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load %struct.pool*, %struct.pool** %2
%15 = call i32 @pool_reserve(%struct.pool* %14)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = load i32, i32* %4
%19 = load %struct.pool*, %struct.pool** %2
%20 = load i32, i32* %4
%21 = call i32 @pool_release(%struct.pool* %19, i32 %20)
%22 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %21)
br label %23
23: ; preds = %9
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %6
26: ; preds = %6
store i32 0, i32* %3
br label %27
27: ; preds = %36, %26
%28 = load i32, i32* %3
%29 = icmp slt i32 %28, 10
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = load i32, i32* %3
%32 = load %struct.pool*, %struct.pool** %2
%33 = load i32, i32* %3
%34 = call i32 @pool_release(%struct.pool* %32, i32 %33)
%35 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %34)
br label %36
36: ; preds = %30
%37 = load i32, i32* %3
%38 = add nsw i32 %37, 1
store i32 %38, i32* %3
br label %27
39: ; preds = %27
%40 = load %struct.pool*, %struct.pool** %2
%41 = call i32 @pool_free(%struct.pool* %40)
ret i32 0
}

LLVM IR (-O2):
%struct.pool = type { i32 }
@.str = [13 x i8] c"reserve: %d\0A\00"
@.str.1 = [17 x i8] c"release(%d): %d\0A\00"
define i32 @main() {
%1 = tail call %struct.pool* @pool_alloc(i32 10)
br label %2
2: ; preds = %0, %2
%3 = phi i32 [ 0, %0 ], [ %10, %2 ]
%4 = tail call i32 @pool_reserve(%struct.pool* %1)
%5 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 @pool_reserve(%struct.pool* %1)
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 @pool_release(%struct.pool* %1, i32 %6)
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %8)
%10 = add nuw nsw i32 %3, 1
%11 = icmp eq i32 %10, 10
br i1 %11, label %12, label %2
12: ; preds = %2
%13 = tail call i32 @pool_release(%struct.pool* %1, i32 0)
%14 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %13)
%15 = tail call i32 @pool_release(%struct.pool* %1, i32 1)
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 %15)
%17 = tail call i32 @pool_release(%struct.pool* %1, i32 2)
%18 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 2, i32 %17)
%19 = tail call i32 @pool_release(%struct.pool* %1, i32 3)
%20 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 3, i32 %19)
%21 = tail call i32 @pool_release(%struct.pool* %1, i32 4)
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 4, i32 %21)
%23 = tail call i32 @pool_release(%struct.pool* %1, i32 5)
%24 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 5, i32 %23)
%25 = tail call i32 @pool_release(%struct.pool* %1, i32 6)
%26 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 6, i32 %25)
%27 = tail call i32 @pool_release(%struct.pool* %1, i32 7)
%28 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 7, i32 %27)
%29 = tail call i32 @pool_release(%struct.pool* %1, i32 8)
%30 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 8, i32 %29)
%31 = tail call i32 @pool_release(%struct.pool* %1, i32 9)
%32 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 9, i32 %31)
%33 = tail call i32 @pool_free(%struct.pool* %1)
ret i32 0
}