#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 link {
  int dummy;
};

/* Variables and functions */
int find_most_left(struct link *, int /*<<< orphan*/);
int /*<<< orphan*/ move_down();
int /*<<< orphan*/ move_right();
int /*<<< orphan*/ move_up();
int /*<<< orphan*/ ptree(struct link *);
int /*<<< orphan*/ putchar(char);
int tree_depth(struct link *);
void show_tree_pic(struct link *r) {
  int depth = tree_depth(r);
  int most_left = find_most_left(r, 0);
  int i;
  putchar('\n');
  for (i = 0; i < depth * 3 + 1; i++)
    putchar('\n');
  for (i = 0; i < depth * 3 + 1; i++)
    move_up();
  for (i = 0; i < (0 - most_left) + 1; i++)
    move_right();
  ptree(r);
  for (i = 0; i < depth * 3 + 1; i++)
    move_down();
  putchar('\n');
}


x86 assembly (clang, -O0):
<show_tree_pic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <tree_depth@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1060 <find_most_left@plt>
mov    %eax,-0x10(%rbp)
mov    $0xa,%edi
call   1030 <putchar@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
imul   $0x3,-0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11d1 <show_tree_pic+0x61>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11a7 <show_tree_pic+0x37>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
imul   $0x3,-0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    11ff <show_tree_pic+0x8f>
mov    $0x0,%al
call   1040 <move_up@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11d8 <show_tree_pic+0x68>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
xor    %ecx,%ecx
sub    -0x10(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    122e <show_tree_pic+0xbe>
mov    $0x0,%al
call   1050 <move_right@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1206 <show_tree_pic+0x96>
mov    -0x8(%rbp),%rdi
call   1070 <ptree@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
imul   $0x3,-0xc(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jge    1265 <show_tree_pic+0xf5>
mov    $0x0,%al
call   1090 <move_down@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123e <show_tree_pic+0xce>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_tree_pic>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
call   1080 <tree_depth@plt>
mov    %eax,%r15d
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <find_most_left@plt>
mov    %eax,%ebp
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    (%r15,%r15,2),%r12d
test   %r15d,%r15d
js     11ec <show_tree_pic+0x7c>
test   %r12d,%r12d
cmovg  %r12d,%ebx
add    $0x1,%ebx
xchg   %ax,%ax
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    11b0 <show_tree_pic+0x40>
test   %r15d,%r15d
js     11ec <show_tree_pic+0x7c>
test   %r12d,%r12d
mov    $0x0,%ebx
cmovg  %r12d,%ebx
add    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1040 <move_up@plt>
add    $0xffffffff,%ebx
jne    11e0 <show_tree_pic+0x70>
mov    $0x1,%eax
sub    %ebp,%eax
test   %eax,%eax
jle    120b <show_tree_pic+0x9b>
add    $0xffffffff,%ebp
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <move_right@plt>
inc    %ebp
jne    1200 <show_tree_pic+0x90>
mov    %r14,%rdi
call   1070 <ptree@plt>
test   %r15d,%r15d
js     123d <show_tree_pic+0xcd>
xor    %eax,%eax
test   %r12d,%r12d
cmovle %eax,%r12d
add    $0x1,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1090 <move_down@plt>
add    $0xffffffff,%r12d
jne    1230 <show_tree_pic+0xc0>
mov    $0xa,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
%struct.link = type { i32 }
define void @show_tree_pic(%struct.link* %0) {
%2 = alloca %struct.link*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store %struct.link* %0, %struct.link** %2
%6 = load %struct.link*, %struct.link** %2
%7 = call i32 @tree_depth(%struct.link* %6)
store i32 %7, i32* %3
%8 = load %struct.link*, %struct.link** %2
%9 = call i32 @find_most_left(%struct.link* %8, i32 0)
store i32 %9, i32* %4
%10 = call i32 @putchar(i8 signext 10)
store i32 0, i32* %5
br label %11
11: ; preds = %19, %1
%12 = load i32, i32* %5
%13 = load i32, i32* %3
%14 = mul nsw i32 %13, 3
%15 = add nsw i32 %14, 1
%16 = icmp slt i32 %12, %15
br i1 %16, label %17, label %22
17: ; preds = %11
%18 = call i32 @putchar(i8 signext 10)
br label %19
19: ; preds = %17
%20 = load i32, i32* %5
%21 = add nsw i32 %20, 1
store i32 %21, i32* %5
br label %11
22: ; preds = %11
store i32 0, i32* %5
br label %23
23: ; preds = %31, %22
%24 = load i32, i32* %5
%25 = load i32, i32* %3
%26 = mul nsw i32 %25, 3
%27 = add nsw i32 %26, 1
%28 = icmp slt i32 %24, %27
br i1 %28, label %29, label %34
29: ; preds = %23
%30 = call i32 (...) @move_up()
br label %31
31: ; preds = %29
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %23
34: ; preds = %23
store i32 0, i32* %5
br label %35
35: ; preds = %43, %34
%36 = load i32, i32* %5
%37 = load i32, i32* %4
%38 = sub nsw i32 0, %37
%39 = add nsw i32 %38, 1
%40 = icmp slt i32 %36, %39
br i1 %40, label %41, label %46
41: ; preds = %35
%42 = call i32 (...) @move_right()
br label %43
43: ; preds = %41
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %35
46: ; preds = %35
%47 = load %struct.link*, %struct.link** %2
%48 = call i32 @ptree(%struct.link* %47)
store i32 0, i32* %5
br label %49
49: ; preds = %57, %46
%50 = load i32, i32* %5
%51 = load i32, i32* %3
%52 = mul nsw i32 %51, 3
%53 = add nsw i32 %52, 1
%54 = icmp slt i32 %50, %53
br i1 %54, label %55, label %60
55: ; preds = %49
%56 = call i32 (...) @move_down()
br label %57
57: ; preds = %55
%58 = load i32, i32* %5
%59 = add nsw i32 %58, 1
store i32 %59, i32* %5
br label %49
60: ; preds = %49
%61 = call i32 @putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
%struct.link = type { i32 }
define void @show_tree_pic(%struct.link* %0) {
%2 = tail call i32 @tree_depth(%struct.link* %0)
%3 = tail call i32 @find_most_left(%struct.link* %0, i32 0)
%4 = tail call i32 @putchar(i8 signext 10)
%5 = mul i32 %2, 3
%6 = icmp slt i32 %2, 0
br i1 %6, label %17, label %7
7: ; preds = %1
%8 = call i32 @llvm.smax.i32(i32 %5, i32 0)
br label %12
9: ; preds = %12
br i1 %6, label %17, label %10
10: ; preds = %9
%11 = call i32 @llvm.smax.i32(i32 %5, i32 0)
br label %20
12: ; preds = %7, %12
%13 = phi i32 [ %15, %12 ], [ 0, %7 ]
%14 = tail call i32 @putchar(i8 signext 10)
%15 = add nuw i32 %13, 1
%16 = icmp eq i32 %13, %8
br i1 %16, label %9, label %12
17: ; preds = %20, %1, %9
%18 = sub i32 1, %3
%19 = icmp sgt i32 %18, 0
br i1 %19, label %25, label %30
20: ; preds = %10, %20
%21 = phi i32 [ %23, %20 ], [ 0, %10 ]
%22 = tail call i32 (...) @move_up()
%23 = add nuw i32 %21, 1
%24 = icmp eq i32 %21, %11
br i1 %24, label %17, label %20
25: ; preds = %17, %25
%26 = phi i32 [ %28, %25 ], [ 0, %17 ]
%27 = tail call i32 (...) @move_right()
%28 = add nuw nsw i32 %26, 1
%29 = icmp eq i32 %28, %18
br i1 %29, label %30, label %25
30: ; preds = %25, %17
%31 = tail call i32 @ptree(%struct.link* %0)
br i1 %6, label %39, label %32
32: ; preds = %30
%33 = call i32 @llvm.smax.i32(i32 %5, i32 0)
br label %34
34: ; preds = %32, %34
%35 = phi i32 [ %37, %34 ], [ 0, %32 ]
%36 = tail call i32 (...) @move_down()
%37 = add nuw i32 %35, 1
%38 = icmp eq i32 %35, %33
br i1 %38, label %39, label %34
39: ; preds = %34, %30
%40 = tail call i32 @putchar(i8 signext 10)
ret void
}