#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 */
void free(void *);
void stub1(void *);
void freelist_f(void **list, size_t size, void (*free_func)(void *)) {
  for (size_t i = 0; i < size; i++) {
    (free_func ? free_func : free)(list[i]);
  }
  free(list);
}


x86 assembly (clang, -O0):
<freelist_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1175 <freelist_f+0x75>
cmpq   $0x0,-0x18(%rbp)
je     1142 <freelist_f+0x42>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1152 <freelist_f+0x52>
mov    0x2e8f(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1152 <freelist_f+0x52>
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%rdx
mov    (%rcx,%rdx,8),%rdi
call   *%rax
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    111c <freelist_f+0x1c>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<freelist_f>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rsi,%rsi
je     1140 <freelist_f+0x40>
mov    %rdx,%r12
mov    %rsi,%r15
test   %rdx,%rdx
jne    1122 <freelist_f+0x22>
mov    0x2eb6(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%rbx,8),%rdi
call   *%r12
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <freelist_f+0x30>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @freelist_f(i8** %0, i64 %1, void (i8*)* %2) {
%4 = alloca i8**
%5 = alloca i64
%6 = alloca void (i8*)*
%7 = alloca i64
store i8** %0, i8*** %4
store i64 %1, i64* %5
store void (i8*)* %2, void (i8*)** %6
store i64 0, i64* %7
br label %8
8: ; preds = %24, %3
%9 = load i64, i64* %7
%10 = load i64, i64* %5
%11 = icmp ult i64 %9, %10
br i1 %11, label %12, label %27
12: ; preds = %8
%13 = load void (i8*)*, void (i8*)** %6
%14 = icmp ne void (i8*)* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = load void (i8*)*, void (i8*)** %6
br label %18
17: ; preds = %12
br label %18
18: ; preds = %17, %15
%19 = phi void (i8*)* [ %16, %15 ], [ @free, %17 ]
%20 = load i8**, i8*** %4
%21 = load i64, i64* %7
%22 = getelementptr inbounds i8*, i8** %20, i64 %21
%23 = load i8*, i8** %22
br label %24
24: ; preds = %18
%25 = load i64, i64* %7
%26 = add i64 %25, 1
store i64 %26, i64* %7
br label %8
27: ; preds = %8
%28 = load i8**, i8*** %4
%29 = bitcast i8** %28 to i8*
ret void
}

LLVM IR (-O2):
define void @freelist_f(i8** nocapture %0, i64 %1, void (i8*)* %2) {
%4 = icmp eq i64 %1, 0
br i1 %4, label %8, label %5
5: ; preds = %3
%6 = icmp eq void (i8*)* %2, null
%7 = select i1 %6, void (i8*)* @free, void (i8*)* %2
br label %10
8: ; preds = %10, %3
%9 = bitcast i8** %0 to i8*
tail call void @free(i8* %9)
ret void
10: ; preds = %5, %10
%11 = phi i64 [ 0, %5 ], [ %14, %10 ]
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
%13 = load i8*, i8** %12
tail call void %7(i8* %13)
%14 = add nuw i64 %11, 1
%15 = icmp eq i64 %14, %1
br i1 %15, label %8, label %10
}