#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 height(struct TreeNode *);
scalar_t__ malloc(int);
int min(struct TreeNode *);
int /*<<< orphan*/ traverse(struct TreeNode *, int /*<<< orphan*/, int *);
int *largestValues(struct TreeNode *root, int *returnSize) {
  *returnSize = height(root);
  int *res = (int *)malloc((*returnSize) * sizeof(int));
  if (0 == *returnSize)
    return res;
  int m = min(root);
  for (int i = 0; i < *returnSize; i++) {
    res[i] = m;
  }
  traverse(root, 0, res);
  return res;
}


x86 assembly (clang, -O0):
<largestValues>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <height@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
movslq (%rax),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%eax
jne    1192 <largestValues+0x52>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e7 <largestValues+0xa7>
mov    -0x10(%rbp),%rdi
call   1030 <min@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x18(%rbp),%rcx
cmp    (%rcx),%eax
jge    11d0 <largestValues+0x90>
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11a5 <largestValues+0x65>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
xor    %esi,%esi
call   1040 <traverse@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<largestValues>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
call   1060 <height@plt>
mov    %eax,(%rbx)
lea    0x0(,%rax,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
cmpl   $0x0,(%rbx)
je     119d <largestValues+0x5d>
mov    %r14,%rdi
call   1030 <min@plt>
cmpl   $0x0,(%rbx)
jle    1190 <largestValues+0x50>
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,(%r15,%rcx,4)
add    $0x1,%rcx
movslq (%rbx),%rdx
cmp    %rdx,%rcx
jl     1180 <largestValues+0x40>
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1040 <traverse@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TreeNode = type { i32 }
define i32* @largestValues(%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)
%11 = load i32*, i32** %5
store i32 %10, i32* %11
%12 = load i32*, i32** %5
%13 = load i32, i32* %12
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 4
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i32*
store i32* %18, i32** %6
%19 = load i32*, i32** %5
%20 = load i32, i32* %19
%21 = icmp eq i32 0, %20
br i1 %21, label %22, label %24
22: ; preds = %2
%23 = load i32*, i32** %6
store i32* %23, i32** %3
br label %46
24: ; preds = %2
%25 = load %struct.TreeNode*, %struct.TreeNode** %4
%26 = call i32 @min(%struct.TreeNode* %25)
store i32 %26, i32* %7
store i32 0, i32* %8
br label %27
27: ; preds = %38, %24
%28 = load i32, i32* %8
%29 = load i32*, i32** %5
%30 = load i32, i32* %29
%31 = icmp slt i32 %28, %30
br i1 %31, label %32, label %41
32: ; preds = %27
%33 = load i32, i32* %7
%34 = load i32*, i32** %6
%35 = load i32, i32* %8
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i32, i32* %34, i64 %36
store i32 %33, i32* %37
br label %38
38: ; preds = %32
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %27
41: ; preds = %27
%42 = load %struct.TreeNode*, %struct.TreeNode** %4
%43 = load i32*, i32** %6
%44 = call i32 @traverse(%struct.TreeNode* %42, i32 0, i32* %43)
%45 = load i32*, i32** %6
store i32* %45, i32** %3
br label %46
46: ; preds = %41, %22
%47 = load i32*, i32** %3
ret i32* %47
}

LLVM IR (-O2):
%struct.TreeNode = type { i32 }
define i32* @largestValues(%struct.TreeNode* %0, i32* nocapture %1) {
%3 = tail call i32 @height(%struct.TreeNode* %0)
store i32 %3, i32* %1
%4 = shl i32 %3, 2
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i32*
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 0
br i1 %8, label %22, label %9
9: ; preds = %2
%10 = tail call i32 @min(%struct.TreeNode* %0)
%11 = load i32, i32* %1
%12 = icmp sgt i32 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %15, %9
%14 = tail call i32 @traverse(%struct.TreeNode* %0, i32 0, i32* %6)
br label %22
15: ; preds = %9, %15
%16 = phi i64 [ %18, %15 ], [ 0, %9 ]
%17 = getelementptr inbounds i32, i32* %6, i64 %16
store i32 %10, i32* %17
%18 = add nuw nsw i64 %16, 1
%19 = load i32, i32* %1
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %15, label %13
22: ; preds = %2, %13
ret i32* %6
}