#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 scanf(char *, int *);
struct tree_node *deserialize(void) {
  static int buff[4096];
  size_t i = 0;
  int val;
  while (scanf("%d", &val) == 1) {
    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    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
lea    0xeb9(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    118f <deserialize+0x5f>
cmpq   $0x1000,-0x8(%rbp)
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rcx
mov    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
lea    0x2ec9(%rip),%rax
mov    %edx,(%rax,%rcx,4)
jmp    1140 <deserialize+0x10>
mov    -0x8(%rbp),%rax
shr    $0x1,%rax
lea    0x2eb2(%rip),%rsi
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x8(%rbp),%rdx
shr    $0x1,%rdx
lea    0x2e9c(%rip),%rdi
call   1030 <deserialize_internal@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deserialize>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xec1(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
cmp    $0x1,%eax
jne    11a5 <deserialize+0x75>
lea    0x2efb(%rip),%rbx
xor    %r12d,%r12d
lea    0xea1(%rip),%r14
lea    0x4(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edi,%edi
cmp    $0x1000,%r12
setb   %dil
call   1040 <assert@plt>
mov    0x4(%rsp),%eax
add    $0x1,%r12
mov    %eax,(%rbx)
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <scanf@plt>
add    $0x4,%rbx
cmp    $0x1,%eax
je     1170 <deserialize+0x40>
shr    %r12
jmp    11a8 <deserialize+0x78>
xor    %r12d,%r12d
lea    0x2ea1(%rip),%rdi
lea    (%rdi,%r12,4),%rsi
mov    %r12,%rdx
call   1030 <deserialize_internal@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
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() {
%1 = alloca i64
%2 = alloca i32
store i64 0, i64* %1
br label %3
3: ; preds = %6, %0
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%5 = icmp eq i32 %4, 1
br i1 %5, label %6, label %15
6: ; preds = %3
%7 = load i64, i64* %1
%8 = icmp ult i64 %7, 4096
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* %2
%12 = load i64, i64* %1
%13 = add i64 %12, 1
store i64 %13, i64* %1
%14 = getelementptr inbounds [4096 x i32], [4096 x i32]* @deserialize.buff, i64 0, i64 %12
store i32 %11, i32* %14
br label %3
15: ; preds = %3
%16 = load i64, i64* %1
%17 = udiv i64 %16, 2
%18 = getelementptr inbounds [4096 x i32], [4096 x i32]* @deserialize.buff, i64 0, i64 %17
%19 = load i64, i64* %1
%20 = udiv i64 %19, 2
%21 = call %struct.tree_node* @deserialize_internal(i32* getelementptr inbounds ([4096 x i32], [4096 x i32]* @deserialize.buff, i64 0, i64 0), i32* %18, i64 %20)
ret %struct.tree_node* %21
}

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() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %17
5: ; preds = %0, %5
%6 = phi i64 [ %11, %5 ], [ 0, %0 ]
%7 = icmp ult i64 %6, 4096
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %1
%11 = add i64 %6, 1
%12 = getelementptr inbounds [4096 x i32], [4096 x i32]* @deserialize.buff, i64 0, i64 %6
store i32 %10, i32* %12
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%14 = icmp eq i32 %13, 1
br i1 %14, label %5, label %15
15: ; preds = %5
%16 = lshr i64 %11, 1
br label %17
17: ; preds = %15, %0
%18 = phi i64 [ 0, %0 ], [ %16, %15 ]
%19 = getelementptr inbounds [4096 x i32], [4096 x i32]* @deserialize.buff, i64 0, i64 %18
%20 = call %struct.tree_node* @deserialize_internal(i32* getelementptr inbounds ([4096 x i32], [4096 x i32]* @deserialize.buff, i64 0, i64 0), i32* %19, i64 %18)
ret %struct.tree_node* %20
}