#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 find_node_num(long, long *);
int /*<<< orphan*/ init(long *, long *, int);
int /*<<< orphan*/ print_tree(int, long, long *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, long *);
int main() {
  long n = 0;
  long tree_num[100] = {0};
  long acc_num[100] = {0};
  init(tree_num, acc_num, 500000000);
  while (1) {
    scanf("%ld", &n);
    if (n == 0) {
      break;
    }
    int node_num = find_node_num(n, acc_num);
    print_tree(node_num, n - acc_num[node_num - 1], tree_num);
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x660,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x330(%rbp),%rdi
xor    %esi,%esi
mov    $0x320,%edx
call   1050 <memset@plt>
lea    -0x650(%rbp),%rdi
xor    %esi,%esi
mov    $0x320,%edx
call   1050 <memset@plt>
lea    -0x330(%rbp),%rdi
lea    -0x650(%rbp),%rsi
mov    $0x1dcd6500,%edx
call   1060 <init@plt>
lea    0xe41(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1070 <scanf@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11d8 <main+0x78>
jmp    1228 <main+0xc8>
mov    -0x10(%rbp),%rdi
lea    -0x650(%rbp),%rsi
call   1030 <find_node_num@plt>
mov    %eax,-0x654(%rbp)
mov    -0x654(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x654(%rbp),%eax
sub    $0x1,%eax
cltq
sub    -0x650(%rbp,%rax,8),%rsi
ff
lea    -0x330(%rbp),%rdx
call   1080 <print_tree@plt>
lea    0xde6(%rip),%rdi
call   1040 <printf@plt>
jmp    11b8 <main+0x58>
xor    %eax,%eax
add    $0x660,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x658,%rsp
movq   $0x0,0x8(%rsp)
lea    0x330(%rsp),%r14
mov    $0x320,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
lea    0x10(%rsp),%rbx
mov    $0x320,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1dcd6500,%edx
call   1060 <init@plt>
lea    0xe47(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1070 <scanf@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
je     122c <main+0xcc>
lea    0x10(%rsp),%r14
lea    0x330(%rsp),%r15
lea    0xe1f(%rip),%r12
lea    0x8(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rsi
call   1040 <find_node_num@plt>
mov    0x8(%rsp),%rsi
movslq %eax,%rdi
sub    0x8(%rsp,%rdi,8),%rsi
mov    %r15,%rdx
call   1080 <print_tree@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
mov    0x8(%rsp),%rdi
test   %rdi,%rdi
jne    11f0 <main+0x90>
xor    %eax,%eax
add    $0x658,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca [100 x i64]
%4 = alloca [100 x i64]
%5 = alloca i32
store i32 0, i32* %1
store i64 0, i64* %2
%6 = bitcast [100 x i64]* %3 to i8*
%7 = bitcast [100 x i64]* %4 to i8*
%8 = getelementptr inbounds [100 x i64], [100 x i64]* %3, i64 0, i64 0
%9 = getelementptr inbounds [100 x i64], [100 x i64]* %4, i64 0, i64 0
%10 = call i32 @init(i64* %8, i64* %9, i32 500000000)
br label %11
11: ; preds = %0, %16
%12 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %2)
%13 = load i64, i64* %2
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
br label %31
16: ; preds = %11
%17 = load i64, i64* %2
%18 = getelementptr inbounds [100 x i64], [100 x i64]* %4, i64 0, i64 0
%19 = call i32 @find_node_num(i64 %17, i64* %18)
store i32 %19, i32* %5
%20 = load i32, i32* %5
%21 = load i64, i64* %2
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i64], [100 x i64]* %4, i64 0, i64 %24
%26 = load i64, i64* %25
%27 = sub nsw i64 %21, %26
%28 = getelementptr inbounds [100 x i64], [100 x i64]* %3, i64 0, i64 0
%29 = call i32 @print_tree(i32 %20, i64 %27, i64* %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %11
31: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca [100 x i64]
%3 = alloca [100 x i64]
%4 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%5 = bitcast [100 x i64]* %2 to i8*
%6 = bitcast [100 x i64]* %3 to i8*
%7 = getelementptr inbounds [100 x i64], [100 x i64]* %2, i64 0, i64 0
%8 = getelementptr inbounds [100 x i64], [100 x i64]* %3, i64 0, i64 0
%9 = call i32 @init(i64* %7, i64* %8, i32 500000000)
%10 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %1)
%11 = load i64, i64* %1
%12 = icmp eq i64 %11, 0
br i1 %12, label %27, label %13
13: ; preds = %0, %13
%14 = phi i64 [ %25, %13 ], [ %11, %0 ]
%15 = call i32 @find_node_num(i64 %14, i64* %8)
%16 = load i64, i64* %1
%17 = add nsw i32 %15, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i64], [100 x i64]* %3, i64 0, i64 %18
%20 = load i64, i64* %19
%21 = sub nsw i64 %16, %20
%22 = call i32 @print_tree(i32 %15, i64 %21, i64* %7)
%23 = call i32 @putchar(i32 10)
%24 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i64* %1)
%25 = load i64, i64* %1
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %13
27: ; preds = %13, %0
ret i32 0
}