#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 tree_node {
  int dummy;
};
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
struct tree_node *deserialize_internal(int *, int *, size_t);
int /*<<< orphan*/ scanf(char *, int *);
struct tree_node *deserialize(size_t nodes) {
  static int buff[4096];
  int val;
  size_t i;
  for (i = 0; i < nodes * 2; i++) {
    scanf("%d", &val);
    assert(i < sizeof(buff) / sizeof(buff[0]));
    buff[i] = val;
  }
  return deserialize_internal(&buff[0], &buff[i / 2], i / 2);
}


x86 assembly (clang, -O0):
<deserialize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
shl    $0x1,%rcx
cmp    %rcx,%rax
jae    11a0 <deserialize+0x70>
lea    0xea0(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
cmpq   $0x1000,-0x18(%rbp)
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
lea    0x2ec4(%rip),%rax
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1144 <deserialize+0x14>
mov    -0x18(%rbp),%rax
shr    $0x1,%rax
lea    0x2ea1(%rip),%rsi
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x18(%rbp),%rdx
shr    $0x1,%rdx
lea    0x2e8b(%rip),%rdi
call   1030 <deserialize_internal@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deserialize>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
add    %rdi,%r13
je     119f <deserialize+0x6f>
mov    %rdi,%r14
lea    0x2f03(%rip),%rbx
xor    %ebp,%ebp
lea    0xeaa(%rip),%r15
lea    0x4(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
xor    %edi,%edi
cmp    $0x1000,%rbp
setb   %dil
call   1040 <assert@plt>
mov    0x4(%rsp),%eax
mov    %eax,(%rbx)
add    $0x1,%rbp
add    $0x4,%rbx
cmp    %rbp,%r13
jne    1160 <deserialize+0x30>
movabs $0x7fffffffffffffff,%rax
ff ff 7f
and    %rax,%r14
jmp    11a2 <deserialize+0x72>
xor    %r14d,%r14d
lea    0x2ea7(%rip),%rdi
lea    (%rdi,%r14,4),%rsi
mov    %r14,%rdx
call   1030 <deserialize_internal@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tree_node = type { i32 }
@deserialize.buff = internal global [4096 x i32] zeroinitializer
@.str = [3 x i8] c"%d\00"
define %struct.tree_node* @deserialize(i64 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
store i64 %0, i64* %2
store i64 0, i64* %4
br label %5
5: ; preds = %19, %1
%6 = load i64, i64* %4
%7 = load i64, i64* %2
%8 = mul i64 %7, 2
%9 = icmp ult i64 %6, %8
br i1 %9, label %10, label %22
10: ; preds = %5
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%12 = load i64, i64* %4
%13 = icmp ult i64 %12, 4096
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32, i32* %3
%17 = load i64, i64* %4
%18 = getelementptr inbounds [4096 x i32], [4096 x i32]* @deserialize.buff, i64 0, i64 %17
store i32 %16, i32* %18
br label %19
19: ; preds = %10
%20 = load i64, i64* %4
%21 = add i64 %20, 1
store i64 %21, i64* %4
br label %5
22: ; preds = %5
%23 = load i64, i64* %4
%24 = udiv i64 %23, 2
%25 = getelementptr inbounds [4096 x i32], [4096 x i32]* @deserialize.buff, i64 0, i64 %24
%26 = load i64, i64* %4
%27 = udiv i64 %26, 2
%28 = call %struct.tree_node* @deserialize_internal(i32* getelementptr inbounds ([4096 x i32], [4096 x i32]* @deserialize.buff, i64 0, i64 0), i32* %25, i64 %27)
ret %struct.tree_node* %28
}

LLVM IR (-O2):
%struct.tree_node = type { i32 }
@deserialize.buff = internal global [4096 x i32] zeroinitializer
@.str = [3 x i8] c"%d\00"
define %struct.tree_node* @deserialize(i64 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = shl i64 %0, 1
%5 = icmp eq i64 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %14, %6 ], [ 0, %1 ]
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%9 = icmp ult i64 %7, 4096
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i32, i32* %2
%13 = getelementptr inbounds [4096 x i32], [4096 x i32]* @deserialize.buff, i64 0, i64 %7
store i32 %12, i32* %13
%14 = add nuw i64 %7, 1
%15 = icmp eq i64 %14, %4
br i1 %15, label %16, label %6
16: ; preds = %6
%17 = and i64 %0, 9223372036854775807
br label %18
18: ; preds = %16, %1
%19 = phi i64 [ 0, %1 ], [ %17, %16 ]
%20 = getelementptr inbounds [4096 x i32], [4096 x i32]* @deserialize.buff, i64 0, i64 %19
%21 = call %struct.tree_node* @deserialize_internal(i32* getelementptr inbounds ([4096 x i32], [4096 x i32]* @deserialize.buff, i64 0, i64 0), i32* %20, i64 %19)
ret %struct.tree_node* %21
}