#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*/ free(void *);
int /*<<< orphan*/ printf(char *, int);
void release(void **pool, int amount) {
  int i;
  printf("Release: %d\n", amount);
  for (i = 0; i < 1024; i++) {
    if (pool[i] != NULL) {
      free(pool[i]);
      pool[i] = NULL;
      amount--;
      if (amount == 0) {
        break;
      }
    }
  }
}


x86 assembly (clang, -O0):
<release>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xec7(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x400,-0x10(%rbp)
jge    11b6 <release+0x96>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11a3 <release+0x83>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    119e <release+0x7e>
jmp    11b6 <release+0x96>
jmp    11a3 <release+0x83>
jmp    11a8 <release+0x88>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1145 <release+0x25>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<release>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
lea    0xed0(%rip),%rdi
call   1040 <printf@plt>
xor    %ebx,%ebx
jmp    114d <release+0x2d>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    $0x400,%rbx
je     1168 <release+0x48>
mov    (%r14,%rbx,8),%rdi
test   %rdi,%rdi
je     1140 <release+0x20>
call   1030 <free@plt>
movq   $0x0,(%r14,%rbx,8)
add    $0xffffffff,%ebp
jne    1140 <release+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"Release: %d\0A\00"
define void @release(i8** nocapture %0, i32 %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %4
4: ; preds = %2, %14
%5 = phi i64 [ 0, %2 ], [ %16, %14 ]
%6 = phi i32 [ %1, %2 ], [ %15, %14 ]
%7 = getelementptr inbounds i8*, i8** %0, i64 %5
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %4
%11 = tail call i32 @free(i8* %8)
store i8* null, i8** %7
%12 = add nsw i32 %6, -1
%13 = icmp eq i32 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %4, %10
%15 = phi i32 [ %12, %10 ], [ %6, %4 ]
%16 = add nuw nsw i64 %5, 1
%17 = icmp eq i64 %16, 1024
br i1 %17, label %18, label %4
18: ; preds = %10, %14
ret void
}