#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*/ cntHelper(struct TreeNode *, int *, int *, int *, int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ pickHelper(int *, struct TreeNode *, int *, int, int *,
                              int *);
int *findMode(struct TreeNode *root, int *returnSize) {
  int cnt = 0;
  int maxCnt = 0;
  int prev = 0;
  int resSize = 0;
  cntHelper(root, &cnt, &maxCnt, &prev, &resSize);
  cnt = 0;
  int *res = (int *)malloc(resSize * sizeof(int));
  *returnSize = resSize;
  resSize = 0;
  pickHelper(res, root, &cnt, maxCnt, &prev, &resSize);
  return res;
}


x86 assembly (clang, -O0):
<findMode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x20(%rbp),%r8
call   1050 <cntHelper@plt>
movl   $0x0,-0x14(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%ecx
lea    -0x14(%rbp),%rdx
lea    -0x1c(%rbp),%r8
lea    -0x20(%rbp),%r9
call   1040 <pickHelper@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findMode>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x14(%rsp)
movl   $0x0,0x8(%rsp)
lea    0x10(%rsp),%r15
lea    0xc(%rsp),%rdx
lea    0x14(%rsp),%r12
lea    0x8(%rsp),%r13
mov    %r15,%rsi
mov    %r12,%rcx
mov    %r13,%r8
call   1050 <cntHelper@plt>
movl   $0x0,0x10(%rsp)
mov    0x8(%rsp),%edi
shl    $0x2,%edi
call   1030 <malloc@plt>
mov    %rax,%rbp
mov    0x8(%rsp),%eax
mov    %eax,(%r14)
movl   $0x0,0x8(%rsp)
mov    0xc(%rsp),%ecx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r12,%r8
mov    %r13,%r9
call   1040 <pickHelper@plt>
mov    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TreeNode = type { i32 }
define i32* @findMode(%struct.TreeNode* %0, i32* %1) {
%3 = alloca %struct.TreeNode*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
store %struct.TreeNode* %0, %struct.TreeNode** %3
store i32* %1, i32** %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%10 = load %struct.TreeNode*, %struct.TreeNode** %3
%11 = call i32 @cntHelper(%struct.TreeNode* %10, i32* %5, i32* %6, i32* %7, i32* %8)
store i32 0, i32* %5
%12 = load i32, i32* %8
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 4
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i32*
store i32* %17, i32** %9
%18 = load i32, i32* %8
%19 = load i32*, i32** %4
store i32 %18, i32* %19
store i32 0, i32* %8
%20 = load i32*, i32** %9
%21 = load %struct.TreeNode*, %struct.TreeNode** %3
%22 = load i32, i32* %6
%23 = call i32 @pickHelper(i32* %20, %struct.TreeNode* %21, i32* %5, i32 %22, i32* %7, i32* %8)
%24 = load i32*, i32** %9
ret i32* %24
}

LLVM IR (-O2):
%struct.TreeNode = type { i32 }
define i32* @findMode(%struct.TreeNode* %0, i32* nocapture writeonly %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%10 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%11 = call i32 @cntHelper(%struct.TreeNode* %0, i32* %3, i32* %4, i32* %5, i32* %6)
store i32 0, i32* %3
%12 = load i32, i32* %6
%13 = shl i32 %12, 2
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
%16 = load i32, i32* %6
store i32 %16, i32* %1
store i32 0, i32* %6
%17 = load i32, i32* %4
%18 = call i32 @pickHelper(i32* %15, %struct.TreeNode* %0, i32* %3, i32 %17, i32* %5, i32* %6)
ret i32* %15
}