#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 */
scalar_t__ malloc(int);
int traverse(struct TreeNode **, int, int);
bool hasPathSum0(struct TreeNode *root, int sum) {
  if (root == NULL)
    return false;
  int len = 100;
  struct TreeNode **stack =
      (struct TreeNode **)malloc(sizeof(struct TreeNode *) * len);
  int top = -1;
  stack[++top] = root;
  return traverse(stack, top, sum);
}


x86 assembly (clang, -O0):
<hasPathSum0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1146 <hasPathSum0+0x26>
movl   $0x0,-0x4(%rbp)
jmp    1191 <hasPathSum0+0x71>
movl   $0x64,-0x18(%rbp)
movslq -0x18(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x24(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1030 <traverse@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hasPathSum0>:
test   %rdi,%rdi
je     114c <hasPathSum0+0x2c>
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x320,%edi
call   1040 <malloc@plt>
mov    %rbx,(%rax)
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <traverse@plt>
xor    %eax,%eax
ret

LLVM IR (-O0):
%struct.TreeNode = type { i32 }
define i32 @hasPathSum0(%struct.TreeNode* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.TreeNode*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.TreeNode**
%8 = alloca i32
store %struct.TreeNode* %0, %struct.TreeNode** %4
store i32 %1, i32* %5
%9 = load %struct.TreeNode*, %struct.TreeNode** %4
%10 = icmp eq %struct.TreeNode* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 0, i32* %3
br label %29
12: ; preds = %2
store i32 100, i32* %6
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = mul i64 8, %14
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to %struct.TreeNode**
store %struct.TreeNode** %18, %struct.TreeNode*** %7
store i32 -1, i32* %8
%19 = load %struct.TreeNode*, %struct.TreeNode** %4
%20 = load %struct.TreeNode**, %struct.TreeNode*** %7
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds %struct.TreeNode*, %struct.TreeNode** %20, i64 %23
store %struct.TreeNode* %19, %struct.TreeNode** %24
%25 = load %struct.TreeNode**, %struct.TreeNode*** %7
%26 = load i32, i32* %8
%27 = load i32, i32* %5
%28 = call i32 @traverse(%struct.TreeNode** %25, i32 %26, i32 %27)
store i32 %28, i32* %3
br label %29
29: ; preds = %12, %11
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
%struct.TreeNode = type { i32 }
define i32 @hasPathSum0(%struct.TreeNode* %0, i32 %1) {
%3 = icmp eq %struct.TreeNode* %0, null
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i64 @malloc(i32 800)
%6 = inttoptr i64 %5 to %struct.TreeNode**
store %struct.TreeNode* %0, %struct.TreeNode** %6
%7 = tail call i32 @traverse(%struct.TreeNode** %6, i32 0, i32 %1)
br label %8
8: ; preds = %2, %4
%9 = phi i32 [ %7, %4 ], [ 0, %2 ]
ret i32 %9
}