#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 tree_dot_printf(int *tree, int size) {
  int i = 0;
  if (tree) {
    printf("digraph etree {\n  rankdir = BT;\n");
    printf("  d2tgraphstyle=\"scale=0.4\"\n  node [shape=circle];\n");
    for (; i < size; ++i)
      if (tree[i] != -1)
        printf("  %d->%d\n", i + 1, tree[i] + 1);
    printf("}\n");
  }
}


x86 assembly (clang, -O0):
<tree_dot_printf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ae <tree_dot_printf+0x9e>
lea    0xec8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a0 <tree_dot_printf+0x90>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpl   $0xffffffff,(%rax,%rcx,4)
je     118d <tree_dot_printf+0x7d>
mov    -0x10(%rbp),%esi
add    $0x1,%esi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
add    $0x1,%edx
lea    0xecf(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1192 <tree_dot_printf+0x82>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114d <tree_dot_printf+0x3d>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tree_dot_printf>:
test   %rdi,%rdi
je     119d <tree_dot_printf+0x7d>
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r15
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
lea    0xee6(%rip),%rdi
call   1030 <puts@plt>
test   %ebp,%ebp
jle    1187 <tree_dot_printf+0x67>
mov    %ebp,%ebp
lea    0xeaa(%rip),%r14
xor    %esi,%esi
jmp    1168 <tree_dot_printf+0x48>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rsi
cmp    %rbx,%rbp
je     1187 <tree_dot_printf+0x67>
mov    (%r15,%rsi,4),%edx
lea    0x1(%rsi),%rbx
cmp    $0xffffffff,%edx
je     1160 <tree_dot_printf+0x40>
add    $0x1,%edx
add    $0x1,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <tree_dot_printf+0x40>
lea    0xecf(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
ret

LLVM IR (-O0):
@.str = [33 x i8] c"digraph etree {\0A rankdir = BT;\0A\00"
@.str.1 = [52 x i8] c" d2tgraphstyle=\22scale=0.4\22\0A node [shape=circle];\0A\00"
@.str.2 = [10 x i8] c" %d->%d\0A\00"
@.str.3 = [3 x i8] c"}\0A\00"
define void @tree_dot_printf(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %38
8: ; preds = %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %33, %8
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %36
15: ; preds = %11
%16 = load i32*, i32** %3
%17 = load i32, i32* %5
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = icmp ne i32 %20, -1
br i1 %21, label %22, label %32
22: ; preds = %15
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
%25 = load i32*, i32** %3
%26 = load i32, i32* %5
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = add nsw i32 %29, 1
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %30)
br label %32
32: ; preds = %22, %15
br label %33
33: ; preds = %32
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 1
store i32 %35, i32* %5
br label %11
36: ; preds = %11
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %2
ret void
}

LLVM IR (-O2):
@.str.2 = [10 x i8] c" %d->%d\0A\00"
@str = [32 x i8] c"digraph etree {\0A rankdir = BT;\00"
@str.4 = [51 x i8] c" d2tgraphstyle=\22scale=0.4\22\0A node [shape=circle];\00"
@str.5 = [2 x i8] c"}\00"
define void @tree_dot_printf(i32* %0, i32 %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %24, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.4, i64 0, i64 0))
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %22
8: ; preds = %4
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %20
%11 = phi i64 [ 0, %8 ], [ %15, %20 ]
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, -1
%15 = add nuw nsw i64 %11, 1
br i1 %14, label %20, label %16
16: ; preds = %10
%17 = add nuw nsw i32 %13, 1
%18 = trunc i64 %15 to i32
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32 %17)
br label %20
20: ; preds = %10, %16
%21 = icmp eq i64 %15, %9
br i1 %21, label %22, label %10
22: ; preds = %20, %4
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.5, i64 0, i64 0))
br label %24
24: ; preds = %22, %2
ret void
}