#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 */

/* Variables and functions */
int /*<<< orphan*/ BottomUp(int *, int, int);
int Replace(int *, int, int);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int /*<<< orphan*/ memcpy(int *, int *, int);
int /*<<< orphan*/ memset(int *, int, int);
int /*<<< orphan*/ printf(char *, int);
int scanf(char *, int *);
int main() {
  int *data = malloc(sizeof(int));
  int Max = 1, size = 0, inp;
  while (scanf("%d", &inp) == 1) {
    if (size == Max) {
      Max <<= 1;
      int *newdata = malloc(sizeof(int) * Max);
      memset(newdata, 0x7f, sizeof(int) * Max);
      memcpy(newdata, data, sizeof(int) * size);
      free(data);
      data = newdata;
    }
    *(data + size) = inp;
    ++size;
    BottomUp(data, (size - 2) / 2, size);
  }
  while (size--) {
    printf("%d\n", Replace(data, Max, (int)0x7f7f7f7f));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe4e(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1090 <scanf@plt>
cmp    $0x1,%eax
jne    1264 <main+0xe4>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    122c <main+0xac>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
mov    $0x7f,%esi
call   1050 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
call   1060 <memcpy@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x18(%rbp),%edx
call   10a0 <BottomUp@plt>
jmp    11ab <main+0x2b>
jmp    1269 <main+0xe9>
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     12a1 <main+0x121>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x7f7f7f7f,%edx
call   1080 <Replace@plt>
mov    %eax,%esi
lea    0xd6c(%rip),%rdi
call   1040 <printf@plt>
jmp    1269 <main+0xe9>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x4,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe61(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1090 <scanf@plt>
cmp    $0x1,%eax
jne    128e <main+0x10e>
mov    $0x1,%r15d
xor    %ebx,%ebx
lea    0xe3f(%rip),%r13
xor    %r12d,%r12d
jmp    1211 <main+0x91>
cs nopw 0x0(%rax,%rax,1)
mov    0x4(%rsp),%eax
mov    %eax,(%r14,%r12,4)
lea    0x1(%r12),%rbp
mov    %r12d,%eax
add    $0xffffffff,%eax
shr    $0x1f,%eax
lea    (%r12,%rax,1),%esi
add    $0xffffffff,%esi
sar    %esi
mov    %r14,%rdi
mov    %ebp,%edx
call   10a0 <BottomUp@plt>
mov    %r13,%rdi
lea    0x4(%rsp),%rsi
call   1090 <scanf@plt>
add    $0x4,%ebx
mov    %rbp,%r12
cmp    $0x1,%eax
jne    1263 <main+0xe3>
mov    %r15d,%eax
cmp    %rax,%r12
jne    11d0 <main+0x50>
lea    (%r15,%r15,1),%r13d
shl    $0x3,%r15d
mov    %r15d,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x7f,%esi
mov    %r15d,%edx
call   1050 <memset@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <memcpy@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r13d,%r15d
lea    0xda5(%rip),%r13
mov    %rbp,%r14
jmp    11d0 <main+0x50>
test   %ebp,%ebp
je     128e <main+0x10e>
neg    %ebp
lea    0xd93(%rip),%rbx
mov    %r14,%rdi
mov    %r15d,%esi
mov    $0x7f7f7f7f,%edx
call   1080 <Replace@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
inc    %ebp
jne    1270 <main+0xf0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 0, i32* %1
%7 = call i32* @malloc(i32 4)
store i32* %7, i32** %2
store i32 1, i32* %3
store i32 0, i32* %4
br label %8
8: ; preds = %39, %0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %5)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %53
11: ; preds = %8
%12 = load i32, i32* %4
%13 = load i32, i32* %3
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %39
15: ; preds = %11
%16 = load i32, i32* %3
%17 = shl i32 %16, 1
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = mul i64 4, %19
%21 = trunc i64 %20 to i32
%22 = call i32* @malloc(i32 %21)
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = load i32, i32* %3
%25 = sext i32 %24 to i64
%26 = mul i64 4, %25
%27 = trunc i64 %26 to i32
%28 = call i32 @memset(i32* %23, i32 127, i32 %27)
%29 = load i32*, i32** %6
%30 = load i32*, i32** %2
%31 = load i32, i32* %4
%32 = sext i32 %31 to i64
%33 = mul i64 4, %32
%34 = trunc i64 %33 to i32
%35 = call i32 @memcpy(i32* %29, i32* %30, i32 %34)
%36 = load i32*, i32** %2
%37 = call i32 @free(i32* %36)
%38 = load i32*, i32** %6
store i32* %38, i32** %2
br label %39
39: ; preds = %15, %11
%40 = load i32, i32* %5
%41 = load i32*, i32** %2
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i32, i32* %41, i64 %43
store i32 %40, i32* %44
%45 = load i32, i32* %4
%46 = add nsw i32 %45, 1
store i32 %46, i32* %4
%47 = load i32*, i32** %2
%48 = load i32, i32* %4
%49 = sub nsw i32 %48, 2
%50 = sdiv i32 %49, 2
%51 = load i32, i32* %4
%52 = call i32 @BottomUp(i32* %47, i32 %50, i32 %51)
br label %8
53: ; preds = %8
br label %54
54: ; preds = %58, %53
%55 = load i32, i32* %4
%56 = add nsw i32 %55, -1
store i32 %56, i32* %4
%57 = icmp ne i32 %55, 0
br i1 %57, label %58, label %63
58: ; preds = %54
%59 = load i32*, i32** %2
%60 = load i32, i32* %3
%61 = call i32 @Replace(i32* %59, i32 %60, i32 2139062143)
%62 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %61)
br label %54
63: ; preds = %54
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = tail call i32* @malloc(i32 4)
%3 = bitcast i32* %1 to i8*
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %9, label %43
6: ; preds = %24
%7 = trunc i64 %29 to i32
%8 = icmp eq i32 %7, 0
br i1 %8, label %43, label %37
9: ; preds = %0, %24
%10 = phi i64 [ %29, %24 ], [ 0, %0 ]
%11 = phi i32* [ %26, %24 ], [ %2, %0 ]
%12 = phi i32 [ %25, %24 ], [ 1, %0 ]
%13 = zext i32 %12 to i64
%14 = icmp eq i64 %10, %13
br i1 %14, label %15, label %24
15: ; preds = %9
%16 = shl i32 %12, 1
%17 = shl i32 %12, 3
%18 = call i32* @malloc(i32 %17)
%19 = call i32 @memset(i32* %18, i32 127, i32 %17)
%20 = trunc i64 %10 to i32
%21 = shl i32 %20, 2
%22 = call i32 @memcpy(i32* %18, i32* %11, i32 %21)
%23 = call i32 @free(i32* %11)
br label %24
24: ; preds = %15, %9
%25 = phi i32 [ %16, %15 ], [ %12, %9 ]
%26 = phi i32* [ %18, %15 ], [ %11, %9 ]
%27 = load i32, i32* %1
%28 = getelementptr inbounds i32, i32* %26, i64 %10
store i32 %27, i32* %28
%29 = add nuw i64 %10, 1
%30 = trunc i64 %10 to i32
%31 = add i32 %30, -1
%32 = sdiv i32 %31, 2
%33 = trunc i64 %29 to i32
%34 = call i32 @BottomUp(i32* %26, i32 %32, i32 %33)
%35 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%36 = icmp eq i32 %35, 1
br i1 %36, label %9, label %6
37: ; preds = %6, %37
%38 = phi i32 [ %39, %37 ], [ %7, %6 ]
%39 = add nsw i32 %38, -1
%40 = call i32 @Replace(i32* %26, i32 %25, i32 2139062143)
%41 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %40)
%42 = icmp eq i32 %39, 0
br i1 %42, label %43, label %37
43: ; preds = %37, %0, %6
ret i32 0
}