#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ hanoi2(int, int *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  FILE *fp, *op;
  int count, input;
  if (argc != 3) {
    printf("Input ERROR!!\n");
    exit(1);
  }
  fp = fopen(argv[1], "r");
  op = fopen(argv[2], "w");
  if (fp == NULL) {
    printf("Cannot open the file!!\n");
    exit(1);
  }
  while (fscanf(fp, "%d", &input) == 1) {
    input /= 2;
    count = 3;
    hanoi2(input, &count);
    fprintf(op, "%d\n", count);
  }
  fclose(fp);
  fclose(op);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11a6 <main+0x36>
lea    0xe69(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe5a(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe44(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f7 <main+0x87>
lea    0xe2b(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11fc <main+0x8c>
mov    -0x18(%rbp),%rdi
lea    0xe24(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    1252 <main+0xe2>
mov    -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x28(%rbp)
movl   $0x3,-0x24(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x24(%rbp),%rsi
call   1030 <hanoi2@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xde6(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11fc <main+0x8c>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
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
cmp    $0x3,%edi
jne    1252 <main+0xe2>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe6e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1080 <fopen@plt>
test   %rbx,%rbx
je     125b <main+0xeb>
mov    %rax,%r14
lea    0xe47(%rip),%rsi
mov    %rsp,%rdx
mov    %rbx,%rdi
call   1060 <fscanf@plt>
cmp    $0x1,%eax
jne    1231 <main+0xc1>
lea    0x4(%rsp),%r15
lea    0xe2e(%rip),%r12
lea    0xe24(%rip),%r13
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rsp),%eax
mov    %eax,%edi
shr    $0x1f,%edi
add    %eax,%edi
sar    %edi
mov    %edi,(%rsp)
movl   $0x3,0x4(%rsp)
mov    %r15,%rsi
call   1040 <hanoi2@plt>
mov    0x4(%rsp),%edx
mov    %r14,%rdi
mov    %r12,%rsi
call   1070 <fprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1060 <fscanf@plt>
cmp    $0x1,%eax
je     11f0 <main+0x80>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc9(%rip),%rdi
jmp    1262 <main+0xf2>
lea    0xda9(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"Input ERROR!!\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [24 x i8] c"Cannot open the file!!\0A\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c"%d\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
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %19, i32** %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %23, i32** %7
%24 = load i32*, i32** %6
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %29
26: ; preds = %15
%27 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %15
br label %30
30: ; preds = %34, %29
%31 = load i32*, i32** %6
%32 = call i32 @fscanf(i32* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %9)
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %42
34: ; preds = %30
%35 = load i32, i32* %9
%36 = sdiv i32 %35, 2
store i32 %36, i32* %9
store i32 3, i32* %8
%37 = load i32, i32* %9
%38 = call i32 @hanoi2(i32 %37, i32* %8)
%39 = load i32*, i32** %7
%40 = load i32, i32* %8
%41 = call i32 @fprintf(i32* %39, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %40)
br label %30
42: ; preds = %30
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
%45 = load i32*, i32** %7
%46 = call i32 @fclose(i32* %45)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [4 x i8] c"%d\0A\00"
@str = [23 x i8] c"Cannot open the file!!\00"
@str.6 = [14 x i8] c"Input ERROR!!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = icmp eq i32 %0, 3
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds i8*, i8** %1, i64 2
%16 = load i8*, i8** %15
%17 = tail call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32* %14, null
br i1 %18, label %22, label %19
19: ; preds = %11
%20 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%21 = icmp eq i32 %20, 1
br i1 %21, label %25, label %33
22: ; preds = %11
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %19, %25
%26 = load i32, i32* %4
%27 = sdiv i32 %26, 2
store i32 %27, i32* %4
store i32 3, i32* %3
%28 = call i32 @hanoi2(i32 %27, i32* %3)
%29 = load i32, i32* %3
%30 = call i32 @fprintf(i32* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %29)
%31 = call i32 @fscanf(i32* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32* %4)
%32 = icmp eq i32 %31, 1
br i1 %32, label %25, label %33
33: ; preds = %25, %19
%34 = call i32 @fclose(i32* %14)
%35 = call i32 @fclose(i32* %17)
ret i32 0
}