#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 /*<<< orphan*/ traverse(struct TreeNode ***, struct TreeNode ***, int,
                            int ***, int **, int *);
int **zigzagLevelOrder(struct TreeNode *root, int **colSize, int *count) {
  if (root == NULL)
    return NULL;
  struct TreeNode **stack0 =
      (struct TreeNode **)malloc(sizeof(struct TreeNode *));
  struct TreeNode **stack1 =
      (struct TreeNode **)malloc(sizeof(struct TreeNode *));
  *colSize = (int *)malloc(sizeof(int));
  int top = -1;
  stack0[++top] = root;
  int **table = (int **)malloc(sizeof(int *));
  *count = 0;
  traverse(&stack0, &stack1, top, &table, colSize, count);
  return table;
}


x86 assembly (clang, -O0):
<zigzagLevelOrder>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    114c <zigzagLevelOrder+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    11d7 <zigzagLevelOrder+0xb7>
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x34(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x34(%rbp)
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x34(%rbp),%edx
mov    -0x18(%rbp),%r8
mov    -0x20(%rbp),%r9
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x40(%rbp),%rcx
call   1030 <traverse@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zigzagLevelOrder>:
test   %rdi,%rdi
je     11ae <zigzagLevelOrder+0x8e>
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,%r12
mov    %rax,0x10(%rsp)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,0x8(%rsp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,(%r15)
mov    %rbx,(%r12)
mov    $0x8,%edi
call   1040 <malloc@plt>
mov    %rax,(%rsp)
movl   $0x0,(%r14)
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%rcx
xor    %edx,%edx
mov    %r15,%r8
mov    %r14,%r9
call   1030 <traverse@plt>
mov    (%rsp),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
xor    %eax,%eax
ret

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

LLVM IR (-O2):
%struct.TreeNode = type { i32 }
define i32** @zigzagLevelOrder(%struct.TreeNode* %0, i32** %1, i32* %2) {
%4 = alloca %struct.TreeNode**
%5 = alloca %struct.TreeNode**
%6 = alloca i32**
%7 = icmp eq %struct.TreeNode* %0, null
br i1 %7, label %22, label %8
8: ; preds = %3
%9 = bitcast %struct.TreeNode*** %4 to i8*
%10 = tail call i64 @malloc(i32 8)
%11 = inttoptr i64 %10 to %struct.TreeNode**
store %struct.TreeNode** %11, %struct.TreeNode*** %4
%12 = bitcast %struct.TreeNode*** %5 to i8*
%13 = tail call i64 @malloc(i32 8)
%14 = inttoptr i64 %13 to %struct.TreeNode**
store %struct.TreeNode** %14, %struct.TreeNode*** %5
%15 = tail call i64 @malloc(i32 4)
%16 = inttoptr i64 %15 to i32*
store i32* %16, i32** %1
store %struct.TreeNode* %0, %struct.TreeNode** %11
%17 = bitcast i32*** %6 to i8*
%18 = tail call i64 @malloc(i32 8)
%19 = inttoptr i64 %18 to i32**
store i32** %19, i32*** %6
store i32 0, i32* %2
%20 = call i32 @traverse(%struct.TreeNode*** %4, %struct.TreeNode*** %5, i32 0, i32*** %6, i32** %1, i32* %2)
%21 = load i32**, i32*** %6
br label %22
22: ; preds = %3, %8
%23 = phi i32** [ %21, %8 ], [ null, %3 ]
ret i32** %23
}