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

/* Variables and functions */
int /*<<< orphan*/ diagonal_sum_main(struct node *, int, int *);
int /*<<< orphan*/ printf(char *, int, int);
int diagonal_sum(struct node *node) {
  if (node == NULL)
    return 0;
  int i = 0;
  int left = 0;
  int array[20];
  for (i = 0; i < 20; i++) {
    array[i] = 0;
  }
  diagonal_sum_main(node, left, array);
  for (i = 0; i < 20; i++) {
    printf("(%d)[%d]\n", i, array[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<diagonal_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <diagonal_sum+0x23>
movl   $0x0,-0x4(%rbp)
jmp    11c9 <diagonal_sum+0xa9>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jge    117c <diagonal_sum+0x5c>
movslq -0x14(%rbp),%rax
movl   $0x0,-0x70(%rbp,%rax,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1158 <diagonal_sum+0x38>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
lea    -0x70(%rbp),%rdx
call   1040 <diagonal_sum_main@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x14,-0x14(%rbp)
jge    11c2 <diagonal_sum+0xa2>
mov    -0x14(%rbp),%esi
movslq -0x14(%rbp),%rax
mov    -0x70(%rbp,%rax,4),%edx
lea    0xe51(%rip),%rdi
call   1030 <printf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1193 <diagonal_sum+0x73>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diagonal_sum>:
test   %rdi,%rdi
je     12af <diagonal_sum+0x18f>
push   %rbx
sub    $0x50,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rdx
xor    %esi,%esi
call   1040 <diagonal_sum_main@plt>
mov    (%rsp),%edx
lea    0xea3(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    0x8(%rsp),%edx
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    0xc(%rsp),%edx
mov    %rbx,%rdi
mov    $0x3,%esi
call   1030 <printf@plt>
mov    0x10(%rsp),%edx
mov    %rbx,%rdi
mov    $0x4,%esi
call   1030 <printf@plt>
mov    0x14(%rsp),%edx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1030 <printf@plt>
mov    0x18(%rsp),%edx
mov    %rbx,%rdi
mov    $0x6,%esi
call   1030 <printf@plt>
mov    0x1c(%rsp),%edx
mov    %rbx,%rdi
mov    $0x7,%esi
call   1030 <printf@plt>
mov    0x20(%rsp),%edx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1030 <printf@plt>
mov    0x24(%rsp),%edx
mov    %rbx,%rdi
mov    $0x9,%esi
call   1030 <printf@plt>
mov    0x28(%rsp),%edx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <printf@plt>
mov    0x2c(%rsp),%edx
mov    %rbx,%rdi
mov    $0xb,%esi
call   1030 <printf@plt>
mov    0x30(%rsp),%edx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1030 <printf@plt>
mov    0x34(%rsp),%edx
mov    %rbx,%rdi
mov    $0xd,%esi
call   1030 <printf@plt>
mov    0x38(%rsp),%edx
mov    %rbx,%rdi
mov    $0xe,%esi
call   1030 <printf@plt>
mov    0x3c(%rsp),%edx
mov    %rbx,%rdi
mov    $0xf,%esi
call   1030 <printf@plt>
mov    0x40(%rsp),%edx
mov    %rbx,%rdi
mov    $0x10,%esi
call   1030 <printf@plt>
mov    0x44(%rsp),%edx
mov    %rbx,%rdi
mov    $0x11,%esi
call   1030 <printf@plt>
mov    0x48(%rsp),%edx
mov    %rbx,%rdi
mov    $0x12,%esi
call   1030 <printf@plt>
mov    0x4c(%rsp),%edx
mov    %rbx,%rdi
mov    $0x13,%esi
call   1030 <printf@plt>
add    $0x50,%rsp
pop    %rbx
xor    %eax,%eax
ret

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

LLVM IR (-O2):
%struct.node = type { i32 }
@.str = [10 x i8] c"(%d)[%d]\0A\00"
define i32 @diagonal_sum(%struct.node* %0) {
%2 = alloca [20 x i32]
%3 = bitcast [20 x i32]* %2 to i8*
%4 = icmp eq %struct.node* %0, null
br i1 %4, label %67, label %5
5: ; preds = %1
%6 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%7 = call i32 @diagonal_sum_main(%struct.node* %0, i32 0, i32* %6)
%8 = load i32, i32* %6
%9 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 0, i32 %8)
%10 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 1
%11 = load i32, i32* %10
%12 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 1, i32 %11)
%13 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 2
%14 = load i32, i32* %13
%15 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 2, i32 %14)
%16 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 3
%17 = load i32, i32* %16
%18 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 3, i32 %17)
%19 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 4
%20 = load i32, i32* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 4, i32 %20)
%22 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 5
%23 = load i32, i32* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 5, i32 %23)
%25 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 6
%26 = load i32, i32* %25
%27 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 6, i32 %26)
%28 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 7
%29 = load i32, i32* %28
%30 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 7, i32 %29)
%31 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 8
%32 = load i32, i32* %31
%33 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 8, i32 %32)
%34 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 9
%35 = load i32, i32* %34
%36 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 9, i32 %35)
%37 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 10
%38 = load i32, i32* %37
%39 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 10, i32 %38)
%40 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 11
%41 = load i32, i32* %40
%42 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 11, i32 %41)
%43 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 12
%44 = load i32, i32* %43
%45 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 12, i32 %44)
%46 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 13
%47 = load i32, i32* %46
%48 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 13, i32 %47)
%49 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 14
%50 = load i32, i32* %49
%51 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 14, i32 %50)
%52 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 15
%53 = load i32, i32* %52
%54 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 15, i32 %53)
%55 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 16
%56 = load i32, i32* %55
%57 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 16, i32 %56)
%58 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 17
%59 = load i32, i32* %58
%60 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 17, i32 %59)
%61 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 18
%62 = load i32, i32* %61
%63 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 18, i32 %62)
%64 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 19
%65 = load i32, i32* %64
%66 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 19, i32 %65)
br label %67
67: ; preds = %1, %5
ret i32 0
}