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

/* Variables and functions */
int /*<<< orphan*/ free(int *);
int height(struct TreeNode *);
int helper(struct TreeNode *, int *, int /*<<< orphan*/, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int pathSum(struct TreeNode *root, int sum) {
  int h = height(root);
  if (h == 0)
    return 0;
  int *sums = (int *)malloc(h * sizeof(int));
  memset(sums, 0, h * sizeof(int));
  int cnt = helper(root, sums, 0, sum);
  free(sums);
  return cnt;
}


x86 assembly (clang, -O0):
<pathSum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <height@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1181 <pathSum+0x31>
movl   $0x0,-0x4(%rbp)
jmp    11cd <pathSum+0x7d>
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%ecx
xor    %edx,%edx
call   1070 <helper@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathSum>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%r15
call   1060 <height@plt>
test   %eax,%eax
je     119f <pathSum+0x4f>
mov    %eax,%ebp
shl    $0x2,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
mov    %r14d,%ecx
call   1070 <helper@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
jmp    11a1 <pathSum+0x51>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TreeNode = type { i32 }
define i32 @pathSum(%struct.TreeNode* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.TreeNode*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store %struct.TreeNode* %0, %struct.TreeNode** %4
store i32 %1, i32* %5
%9 = load %struct.TreeNode*, %struct.TreeNode** %4
%10 = call i32 @height(%struct.TreeNode* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %34
14: ; preds = %2
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = mul i64 %16, 4
%18 = trunc i64 %17 to i32
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i32*
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 4
%25 = trunc i64 %24 to i32
%26 = call i32 @memset(i32* %21, i32 0, i32 %25)
%27 = load %struct.TreeNode*, %struct.TreeNode** %4
%28 = load i32*, i32** %7
%29 = load i32, i32* %5
%30 = call i32 @helper(%struct.TreeNode* %27, i32* %28, i32 0, i32 %29)
store i32 %30, i32* %8
%31 = load i32*, i32** %7
%32 = call i32 @free(i32* %31)
%33 = load i32, i32* %8
store i32 %33, i32* %3
br label %34
34: ; preds = %14, %13
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
%struct.TreeNode = type { i32 }
define i32 @pathSum(%struct.TreeNode* %0, i32 %1) {
%3 = tail call i32 @height(%struct.TreeNode* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %2
%6 = shl i32 %3, 2
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = tail call i32 @memset(i32* %8, i32 0, i32 %6)
%10 = tail call i32 @helper(%struct.TreeNode* %0, i32* %8, i32 0, i32 %1)
%11 = tail call i32 @free(i32* %8)
br label %12
12: ; preds = %2, %5
%13 = phi i32 [ %10, %5 ], [ 0, %2 ]
ret i32 %13
}