#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 object {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ free(struct object **);
int /*<<< orphan*/ get_closure(struct object *, int, struct object ***,
                               unsigned int *);
int /*<<< orphan*/ print_object(int /*<<< orphan*/ *, struct object *);
int /*<<< orphan*/ print_object_physical(int /*<<< orphan*/ *, struct object *);
void print_closure(FILE *f, struct object *obj) {
  struct object **closure;
  unsigned closure_size;
  get_closure(obj, 1, &closure, &closure_size);
  for (unsigned i = 0; i < closure_size; ++i)
    print_object(f, closure[closure_size - i - 1]);
  free(closure);
  get_closure(obj, 0, &closure, &closure_size);
  for (unsigned i = 0; i < closure_size; ++i)
    print_object_physical(f, closure[closure_size - i - 1]);
  free(closure);
}


x86 assembly (clang, -O0):
<print_closure>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1050 <get_closure@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11a3 <print_closure+0x63>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    -0x20(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,8),%rsi
call   1040 <print_object@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116d <print_closure+0x2d>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1050 <get_closure@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11fc <print_closure+0xbc>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    -0x24(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,8),%rsi
call   1060 <print_object_physical@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c6 <print_closure+0x86>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_closure>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rsi,%rdi
mov    $0x1,%esi
call   1050 <get_closure@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     11a1 <print_closure+0x61>
xor    %ebp,%ebp
mov    $0xffffffff,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    0x10(%rsp),%rcx
add    %ebx,%eax
mov    (%rcx,%rax,8),%rsi
mov    %r15,%rdi
call   1040 <print_object@plt>
add    $0x1,%ebp
mov    0xc(%rsp),%eax
add    $0xffffffff,%ebx
cmp    %ebp,%eax
ja     1180 <print_closure+0x40>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
xor    %ebp,%ebp
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <get_closure@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     11f1 <print_closure+0xb1>
mov    $0xffffffff,%ebx
xchg   %ax,%ax
mov    0x10(%rsp),%rcx
add    %ebx,%eax
mov    (%rcx,%rax,8),%rsi
mov    %r15,%rdi
call   1060 <print_object_physical@plt>
add    $0x1,%ebp
mov    0xc(%rsp),%eax
add    $0xffffffff,%ebx
cmp    %ebp,%eax
ja     11d0 <print_closure+0x90>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.object = type { i32 }
define void @print_closure(i32* %0, %struct.object* %1) {
%3 = alloca i32*
%4 = alloca %struct.object*
%5 = alloca %struct.object**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store %struct.object* %1, %struct.object** %4
%9 = load %struct.object*, %struct.object** %4
%10 = call i32 @get_closure(%struct.object* %9, i32 1, %struct.object*** %5, i32* %6)
store i32 0, i32* %7
br label %11
11: ; preds = %26, %2
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %29
15: ; preds = %11
%16 = load i32*, i32** %3
%17 = load %struct.object**, %struct.object*** %5
%18 = load i32, i32* %6
%19 = load i32, i32* %7
%20 = sub i32 %18, %19
%21 = sub i32 %20, 1
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds %struct.object*, %struct.object** %17, i64 %22
%24 = load %struct.object*, %struct.object** %23
%25 = call i32 @print_object(i32* %16, %struct.object* %24)
br label %26
26: ; preds = %15
%27 = load i32, i32* %7
%28 = add i32 %27, 1
store i32 %28, i32* %7
br label %11
29: ; preds = %11
%30 = load %struct.object**, %struct.object*** %5
%31 = call i32 @free(%struct.object** %30)
%32 = load %struct.object*, %struct.object** %4
%33 = call i32 @get_closure(%struct.object* %32, i32 0, %struct.object*** %5, i32* %6)
store i32 0, i32* %8
br label %34
34: ; preds = %49, %29
%35 = load i32, i32* %8
%36 = load i32, i32* %6
%37 = icmp ult i32 %35, %36
br i1 %37, label %38, label %52
38: ; preds = %34
%39 = load i32*, i32** %3
%40 = load %struct.object**, %struct.object*** %5
%41 = load i32, i32* %6
%42 = load i32, i32* %8
%43 = sub i32 %41, %42
%44 = sub i32 %43, 1
%45 = zext i32 %44 to i64
%46 = getelementptr inbounds %struct.object*, %struct.object** %40, i64 %45
%47 = load %struct.object*, %struct.object** %46
%48 = call i32 @print_object_physical(i32* %39, %struct.object* %47)
br label %49
49: ; preds = %38
%50 = load i32, i32* %8
%51 = add i32 %50, 1
store i32 %51, i32* %8
br label %34
52: ; preds = %34
%53 = load %struct.object**, %struct.object*** %5
%54 = call i32 @free(%struct.object** %53)
ret void
}

LLVM IR (-O2):
%struct.object = type { i32 }
define void @print_closure(i32* %0, %struct.object* %1) {
%3 = alloca %struct.object**
%4 = alloca i32
%5 = bitcast %struct.object*** %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @get_closure(%struct.object* %1, i32 1, %struct.object*** %3, i32* %4)
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %16, %2
%11 = load %struct.object**, %struct.object*** %3
%12 = call i32 @free(%struct.object** %11)
%13 = call i32 @get_closure(%struct.object* %1, i32 0, %struct.object*** %3, i32* %4)
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 0
br i1 %15, label %29, label %32
16: ; preds = %2, %16
%17 = phi i32 [ %27, %16 ], [ %8, %2 ]
%18 = phi i32 [ %26, %16 ], [ 0, %2 ]
%19 = load %struct.object**, %struct.object*** %3
%20 = xor i32 %18, -1
%21 = add i32 %17, %20
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds %struct.object*, %struct.object** %19, i64 %22
%24 = load %struct.object*, %struct.object** %23
%25 = call i32 @print_object(i32* %0, %struct.object* %24)
%26 = add nuw i32 %18, 1
%27 = load i32, i32* %4
%28 = icmp ugt i32 %27, %26
br i1 %28, label %16, label %10
29: ; preds = %32, %10
%30 = load %struct.object**, %struct.object*** %3
%31 = call i32 @free(%struct.object** %30)
ret void
32: ; preds = %10, %32
%33 = phi i32 [ %43, %32 ], [ %14, %10 ]
%34 = phi i32 [ %42, %32 ], [ 0, %10 ]
%35 = load %struct.object**, %struct.object*** %3
%36 = xor i32 %34, -1
%37 = add i32 %33, %36
%38 = zext i32 %37 to i64
%39 = getelementptr inbounds %struct.object*, %struct.object** %35, i64 %38
%40 = load %struct.object*, %struct.object** %39
%41 = call i32 @print_object_physical(i32* %0, %struct.object* %40)
%42 = add nuw i32 %34, 1
%43 = load i32, i32* %4
%44 = icmp ugt i32 %43, %42
br i1 %44, label %32, label %29
}