#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 count_of_dim(struct object **, unsigned int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(struct object **);
int /*<<< orphan*/ get_closure(struct object *, int /*<<< orphan*/,
                               struct object ***, unsigned int *);
int /*<<< orphan*/ print_object_dmg(int /*<<< orphan*/ *, struct object *);
void print_closure_dmg(FILE *f, struct object *obj) {
  struct object **closure;
  unsigned closure_size;
  get_closure(obj, 0, &closure, &closure_size);
  fprintf(f, "%u %u %u %u\n", count_of_dim(closure, closure_size, 3),
          count_of_dim(closure, closure_size, 2),
          count_of_dim(closure, closure_size, 1),
          count_of_dim(closure, closure_size, 0));
  fprintf(f, "0 0 0\n0 0 0\n");
  for (unsigned i = 0; i < closure_size; ++i)
    print_object_dmg(f, closure[closure_size - i - 1]);
  free(closure);
}


x86 assembly (clang, -O0):
<print_closure_dmg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1060 <get_closure@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x3,%edx
call   1050 <count_of_dim@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x2,%edx
call   1050 <count_of_dim@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    $0x1,%edx
call   1050 <count_of_dim@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
xor    %edx,%edx
call   1050 <count_of_dim@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    %eax,%r9d
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    1233 <print_closure_dmg+0xe3>
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   1070 <print_object_dmg@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11fd <print_closure_dmg+0xad>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_closure_dmg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r13
xor    %ebp,%ebp
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %rsi,%rdi
xor    %esi,%esi
call   1060 <get_closure@plt>
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
mov    $0x3,%edx
call   1050 <count_of_dim@plt>
mov    %eax,%r14d
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
mov    $0x2,%edx
call   1050 <count_of_dim@plt>
mov    %eax,%r15d
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
mov    $0x1,%edx
call   1050 <count_of_dim@plt>
mov    %eax,%r12d
mov    0x10(%rsp),%rdi
mov    0xc(%rsp),%esi
xor    %edx,%edx
call   1050 <count_of_dim@plt>
lea    0xe20(%rip),%rsi
mov    %r13,%rdi
mov    %r14d,%edx
mov    %r15d,%ecx
mov    %r12d,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1040 <fprintf@plt>
lea    0xe10(%rip),%rdi
mov    $0xc,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1070 <fwrite@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     1241 <print_closure_dmg+0xe1>
mov    $0xffffffff,%ebx
nopl   0x0(%rax)
mov    0x10(%rsp),%rcx
add    %ebx,%eax
mov    (%rcx,%rax,8),%rsi
mov    %r13,%rdi
call   1080 <print_object_dmg@plt>
add    $0x1,%ebp
mov    0xc(%rsp),%eax
add    $0xffffffff,%ebx
cmp    %ebp,%eax
ja     1220 <print_closure_dmg+0xc0>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.object = type { i32 }
@.str = [13 x i8] c"%u %u %u %u\0A\00"
@.str.1 = [13 x i8] c"0 0 0\0A0 0 0\0A\00"
define void @print_closure_dmg(i32* %0, %struct.object* %1) {
%3 = alloca i32*
%4 = alloca %struct.object*
%5 = alloca %struct.object**
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store %struct.object* %1, %struct.object** %4
%8 = load %struct.object*, %struct.object** %4
%9 = call i32 @get_closure(%struct.object* %8, i32 0, %struct.object*** %5, i32* %6)
%10 = load i32*, i32** %3
%11 = load %struct.object**, %struct.object*** %5
%12 = load i32, i32* %6
%13 = call i32 @count_of_dim(%struct.object** %11, i32 %12, i32 3)
%14 = load %struct.object**, %struct.object*** %5
%15 = load i32, i32* %6
%16 = call i32 @count_of_dim(%struct.object** %14, i32 %15, i32 2)
%17 = load %struct.object**, %struct.object*** %5
%18 = load i32, i32* %6
%19 = call i32 @count_of_dim(%struct.object** %17, i32 %18, i32 1)
%20 = load %struct.object**, %struct.object*** %5
%21 = load i32, i32* %6
%22 = call i32 @count_of_dim(%struct.object** %20, i32 %21, i32 0)
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %16, i32 %19, i32 %22)
%24 = load i32*, i32** %3
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %24, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
br label %26
26: ; preds = %41, %2
%27 = load i32, i32* %7
%28 = load i32, i32* %6
%29 = icmp ult i32 %27, %28
br i1 %29, label %30, label %44
30: ; preds = %26
%31 = load i32*, i32** %3
%32 = load %struct.object**, %struct.object*** %5
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = sub i32 %33, %34
%36 = sub i32 %35, 1
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds %struct.object*, %struct.object** %32, i64 %37
%39 = load %struct.object*, %struct.object** %38
%40 = call i32 @print_object_dmg(i32* %31, %struct.object* %39)
br label %41
41: ; preds = %30
%42 = load i32, i32* %7
%43 = add i32 %42, 1
store i32 %43, i32* %7
br label %26
44: ; preds = %26
%45 = load %struct.object**, %struct.object*** %5
%46 = call i32 @free(%struct.object** %45)
ret void
}

LLVM IR (-O2):
%struct.object = type { i32 }
@.str = [13 x i8] c"%u %u %u %u\0A\00"
@.str.1 = [13 x i8] c"0 0 0\0A0 0 0\0A\00"
define void @print_closure_dmg(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 0, %struct.object*** %3, i32* %4)
%8 = load %struct.object**, %struct.object*** %3
%9 = load i32, i32* %4
%10 = call i32 @count_of_dim(%struct.object** %8, i32 %9, i32 3)
%11 = load %struct.object**, %struct.object*** %3
%12 = load i32, i32* %4
%13 = call i32 @count_of_dim(%struct.object** %11, i32 %12, i32 2)
%14 = load %struct.object**, %struct.object*** %3
%15 = load i32, i32* %4
%16 = call i32 @count_of_dim(%struct.object** %14, i32 %15, i32 1)
%17 = load %struct.object**, %struct.object*** %3
%18 = load i32, i32* %4
%19 = call i32 @count_of_dim(%struct.object** %17, i32 %18, i32 0)
%20 = call i32 (i32*, i8*, ...) @fprintf(i32* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %13, i32 %16, i32 %19)
%21 = call i64 @fwrite(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 12, i64 1, i32* %0)
%22 = load i32, i32* %4
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %27, %2
%25 = load %struct.object**, %struct.object*** %3
%26 = call i32 @free(%struct.object** %25)
ret void
27: ; preds = %2, %27
%28 = phi i32 [ %38, %27 ], [ %22, %2 ]
%29 = phi i32 [ %37, %27 ], [ 0, %2 ]
%30 = load %struct.object**, %struct.object*** %3
%31 = xor i32 %29, -1
%32 = add i32 %28, %31
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds %struct.object*, %struct.object** %30, i64 %33
%35 = load %struct.object*, %struct.object** %34
%36 = call i32 @print_object_dmg(i32* %0, %struct.object* %35)
%37 = add nuw i32 %29, 1
%38 = load i32, i32* %4
%39 = icmp ugt i32 %38, %37
br i1 %39, label %27, label %24
}