#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 *, ...);
void print_heap_struct(int arr[], int len) {
  int newline = 1;
  int cnt = 0;
  printf("heap struct:\n");
  for (int i = 0; i < len; i++) {
    printf("%d", arr[i]);
    if (i == cnt) {
      newline *= 2;
      cnt += newline;
      printf("\n");
    } else {
      i == len - 1 ? printf("\n") : printf(" ");
    }
  }
}


x86 assembly (clang, -O0):
<print_heap_struct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11dd <print_heap_struct+0xcd>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xeae(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1198 <print_heap_struct+0x88>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ca <print_heap_struct+0xba>
mov    -0x18(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    11bc <print_heap_struct+0xac>
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ca <print_heap_struct+0xba>
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cf <print_heap_struct+0xbf>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1142 <print_heap_struct+0x32>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_heap_struct>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,(%rsp)
lea    0xeba(%rip),%rdi
call   1040 <puts@plt>
test   %r14d,%r14d
jle    11b9 <print_heap_struct+0x89>
lea    -0x1(%r14),%r12d
mov    %r14d,%r13d
mov    $0x1,%ebx
mov    $0xa,%ebp
xor    %r14d,%r14d
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    (%rsp),%rax
mov    (%rax,%r14,4),%esi
lea    0xe81(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%eax
lea    (%rbx,%rbx,1),%ecx
cmp    %r14,%r12
mov    $0x20,%edi
cmove  %ebp,%edi
cmp    %rax,%r14
cmove  %ebp,%edi
cmove  %ecx,%ebx
mov    $0x0,%eax
cmovne %eax,%ecx
add    %ecx,%r15d
call   1030 <putchar@plt>
add    $0x1,%r14
cmp    %r14,%r13
jne    1170 <print_heap_struct+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [13 x i8] c"heap struct:\00"
define void @print_heap_struct(i32* nocapture %0, i32 %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = add nsw i32 %1, -1
%7 = zext i32 %6 to i64
%8 = zext i32 %1 to i64
br label %10
9: ; preds = %10, %2
ret void
10: ; preds = %5, %10
%11 = phi i64 [ 0, %5 ], [ %27, %10 ]
%12 = phi i32 [ 0, %5 ], [ %25, %10 ]
%13 = phi i32 [ 1, %5 ], [ %23, %10 ]
%14 = getelementptr inbounds i32, i32* %0, i64 %11
%15 = load i32, i32* %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = zext i32 %12 to i64
%18 = icmp eq i64 %11, %17
%19 = shl nsw i32 %13, 1
%20 = icmp eq i64 %11, %7
%21 = select i1 %18, i1 true, i1 %20
%22 = select i1 %21, i32 10, i32 32
%23 = select i1 %18, i32 %19, i32 %13
%24 = select i1 %18, i32 %19, i32 0
%25 = add nsw i32 %12, %24
%26 = tail call i32 @putchar(i32 %22)
%27 = add nuw nsw i64 %11, 1
%28 = icmp eq i64 %27, %8
br i1 %28, label %9, label %10
}