#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*/ printf(char *, int, int);
int /*<<< orphan*/ puts(char *);
void print_heap(int *a) {
  int i;
  for (i = 1; i <= a[0]; i++) {
    printf("a[%d]=%d\t", i, a[i]);
    if (!(i % 10))
      puts("\n");
  }
}


x86 assembly (clang, -O0):
<print_heap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%eax
jg     118f <print_heap+0x6f>
mov    -0xc(%rbp),%esi
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xea9(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    117c <print_heap+0x5c>
lea    0xe93(%rip),%rdi
call   1030 <puts@plt>
jmp    1181 <print_heap+0x61>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <print_heap+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_heap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmpl   $0x0,(%rdi)
jle    1198 <print_heap+0x78>
mov    %rdi,%r12
mov    $0x1,%ebp
xor    %ebx,%ebx
mov    $0xcccccccd,%r13d
lea    0xeb9(%rip),%r14
jmp    1160 <print_heap+0x40>
nopl   0x0(%rax)
movslq (%r12),%rax
add    $0x1,%rbx
add    $0x1,%ebp
cmp    %rax,%rbx
jge    1198 <print_heap+0x78>
mov    %ebp,%eax
imul   %r13,%rax
shr    $0x23,%rax
lea    (%rax,%rax,4),%eax
lea    (%rax,%rax,1),%r15d
add    $0xffffffff,%r15d
mov    0x4(%r12,%rbx,4),%edx
lea    0x1(%rbx),%esi
mov    %r14,%rdi
call   1040 <printf@plt>
cmp    %ebx,%r15d
jne    1150 <print_heap+0x30>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
jmp    1150 <print_heap+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"a[%d]=%d\09\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @print_heap(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
store i32 1, i32* %3
br label %4
4: ; preds = %24, %1
%5 = load i32, i32* %3
%6 = load i32*, i32** %2
%7 = getelementptr inbounds i32, i32* %6, i64 0
%8 = load i32, i32* %7
%9 = icmp sle i32 %5, %8
br i1 %9, label %10, label %27
10: ; preds = %4
%11 = load i32, i32* %3
%12 = load i32*, i32** %2
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32, i32* %15
%17 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %16)
%18 = load i32, i32* %3
%19 = srem i32 %18, 10
%20 = icmp ne i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %10
%22 = call i32 @puts(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %10
br label %24
24: ; preds = %23
%25 = load i32, i32* %3
%26 = add nsw i32 %25, 1
store i32 %26, i32* %3
br label %4
27: ; preds = %4
ret void
}

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