#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 */
scalar_t__ EOF;
int /*<<< orphan*/ calc_index_nodes(int, int *, int *);
int /*<<< orphan*/ calc_permutations();
int /*<<< orphan*/ printTree(int, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int n;
  int index, nodes;
  calc_permutations();
  while (scanf("%ld", &n) != EOF) {
    if (n <= 0)
      break;
    calc_index_nodes(n, &index, &nodes);
    printTree(index, nodes);
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <calc_permutations@plt>
lea    0xe8c(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <scanf@plt>
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
je     11c8 <main+0x78>
cmpl   $0x0,-0x14(%rbp)
jg     119c <main+0x4c>
jmp    11c8 <main+0x78>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1070 <calc_index_nodes@plt>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1030 <printTree@plt>
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
jmp    116d <main+0x1d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1050 <calc_permutations@plt>
lea    0xe95(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1060 <scanf@plt>
mov    0x2e6c(%rip),%r13
cmp    0x0(%r13),%rax
je     11db <main+0x8b>
mov    0x4(%rsp),%edi
test   %edi,%edi
jle    11db <main+0x8b>
lea    0xc(%rsp),%r14
lea    0x8(%rsp),%r15
lea    0xe65(%rip),%r12
lea    0x4(%rsp),%rbx
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <calc_index_nodes@plt>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
call   1040 <printTree@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
cmp    0x0(%r13),%rax
je     11db <main+0x8b>
mov    0x4(%rsp),%edi
test   %edi,%edi
jg     11a0 <main+0x50>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%ld\00"
@EOF = global i64 0
@.str.1 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @calc_permutations()
br label %10
10: ; preds = %18, %2
%11 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %6)
%12 = load i64, i64* @EOF
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = load i32, i32* %6
%16 = icmp sle i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
br label %25
18: ; preds = %14
%19 = load i32, i32* %6
%20 = call i32 @calc_index_nodes(i32 %19, i32* %7, i32* %8)
%21 = load i32, i32* %7
%22 = load i32, i32* %8
%23 = call i32 @printTree(i32 %21, i32 %22)
%24 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %10
25: ; preds = %17, %10
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"%ld\00"
@EOF = global i64 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast i32* %5 to i8*
%9 = tail call i32 (...) @calc_permutations()
%10 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%11 = load i64, i64* @EOF
%12 = icmp eq i64 %10, %11
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 1
%15 = select i1 %12, i1 true, i1 %14
br i1 %15, label %29, label %16
16: ; preds = %2, %16
%17 = phi i32 [ %26, %16 ], [ %13, %2 ]
%18 = call i32 @calc_index_nodes(i32 %17, i32* %4, i32* %5)
%19 = load i32, i32* %4
%20 = load i32, i32* %5
%21 = call i32 @printTree(i32 %19, i32 %20)
%22 = call i32 @putchar(i32 10)
%23 = call i64 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %3)
%24 = load i64, i64* @EOF
%25 = icmp eq i64 %23, %24
%26 = load i32, i32* %3
%27 = icmp slt i32 %26, 1
%28 = select i1 %25, i1 true, i1 %27
br i1 %28, label %29, label %16
29: ; preds = %16, %2
ret i32 0
}