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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct tree_node **malloc(int);
int /*<<< orphan*/ paths_sum_aux(struct tree_node *, struct tree_node **,
                                 int /*<<< orphan*/, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
size_t tree_depth(struct tree_node *);
void paths_sum(struct tree_node *root, int sum) {
  size_t depth = tree_depth(root);
  if (depth == 0) {
    return;
  }
  struct tree_node **paths_buff = malloc(sizeof(*paths_buff) * depth * depth);
  if (paths_buff == NULL) {
    fprintf(stderr, "Out of memory.\n");
    return;
  }
  paths_sum_aux(root, paths_buff, 0, 0, sum);
}


x86 assembly (clang, -O0):
<paths_sum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <tree_depth@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116c <paths_sum+0x2c>
jmp    11be <paths_sum+0x7e>
mov    -0x18(%rbp),%rax
shl    $0x3,%rax
imul   -0x18(%rbp),%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a9 <paths_sum+0x69>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1040 <fprintf@plt>
jmp    11be <paths_sum+0x7e>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%r8d
xor    %ecx,%ecx
mov    %ecx,%edx
call   1030 <paths_sum_aux@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<paths_sum>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1060 <tree_depth@plt>
test   %rax,%rax
je     117c <paths_sum+0x3c>
imul   %eax,%eax
shl    $0x3,%eax
mov    %eax,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1183 <paths_sum+0x43>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %ebp,%r8d
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <paths_sum_aux@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
%struct.tree_node = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Out of memory.\0A\00"
define void @paths_sum(%struct.tree_node* %0, i32 %1) {
%3 = alloca %struct.tree_node*
%4 = alloca i32
%5 = alloca i64
%6 = alloca %struct.tree_node**
store %struct.tree_node* %0, %struct.tree_node** %3
store i32 %1, i32* %4
%7 = load %struct.tree_node*, %struct.tree_node** %3
%8 = call i64 @tree_depth(%struct.tree_node* %7)
store i64 %8, i64* %5
%9 = load i64, i64* %5
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
br label %29
12: ; preds = %2
%13 = load i64, i64* %5
%14 = mul i64 8, %13
%15 = load i64, i64* %5
%16 = mul i64 %14, %15
%17 = trunc i64 %16 to i32
%18 = call %struct.tree_node** @malloc(i32 %17)
store %struct.tree_node** %18, %struct.tree_node*** %6
%19 = load %struct.tree_node**, %struct.tree_node*** %6
%20 = icmp eq %struct.tree_node** %19, null
br i1 %20, label %21, label %24
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %29
24: ; preds = %12
%25 = load %struct.tree_node*, %struct.tree_node** %3
%26 = load %struct.tree_node**, %struct.tree_node*** %6
%27 = load i32, i32* %4
%28 = call i32 @paths_sum_aux(%struct.tree_node* %25, %struct.tree_node** %26, i32 0, i32 0, i32 %27)
br label %29
29: ; preds = %24, %21, %11
ret void
}

LLVM IR (-O2):
%struct.tree_node = type { i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Out of memory.\0A\00"
define void @paths_sum(%struct.tree_node* %0, i32 %1) {
%3 = tail call i64 @tree_depth(%struct.tree_node* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %16, label %5
5: ; preds = %2
%6 = shl i64 %3, 3
%7 = mul i64 %6, %3
%8 = trunc i64 %7 to i32
%9 = tail call %struct.tree_node** @malloc(i32 %8)
%10 = icmp eq %struct.tree_node** %9, null
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %16
14: ; preds = %5
%15 = tail call i32 @paths_sum_aux(%struct.tree_node* %0, %struct.tree_node** %9, i32 0, i32 0, i32 %1)
br label %16
16: ; preds = %11, %14, %2
ret void
}