#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ generate(int);
int /*<<< orphan*/ header(int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ table(int);
int main(int argc, char *argv[]) {
  int limb_bits, nail_bits, numb_bits;
  if (argc != 4) {
    fprintf(stderr, "Usage: gen-fib <header|table> <limbbits> <nailbits>\n");
    exit(1);
  }
  limb_bits = atoi(argv[2]);
  nail_bits = atoi(argv[3]);
  if (limb_bits <= 0 || nail_bits < 0 || nail_bits >= limb_bits) {
    fprintf(stderr, "Invalid limb/nail bits: %d %d\n", limb_bits, nail_bits);
    exit(1);
  }
  numb_bits = limb_bits - nail_bits;
  generate(numb_bits);
  if (strcmp(argv[1], "header") == 0)
    header(numb_bits);
  else if (strcmp(argv[1], "table") == 0)
    table(numb_bits);
  else {
    fprintf(stderr, "Invalid header/table choice: %s\n", argv[1]);
    exit(1);
  }
  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)
cmpl   $0x4,-0x8(%rbp)
je     11b1 <main+0x41>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11f1 <main+0x81>
cmpl   $0x0,-0x18(%rbp)
jl     11f1 <main+0x81>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jl     1218 <main+0xa8>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%eax
sub    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <generate@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe1c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1254 <main+0xe4>
mov    -0x1c(%rbp),%edi
call   1030 <header@plt>
jmp    12ad <main+0x13d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf8(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    127f <main+0x10f>
mov    -0x1c(%rbp),%edi
call   1040 <table@plt>
jmp    12a8 <main+0x138>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xdca(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    12ad <main+0x13d>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x4,%edi
jne    11e6 <main+0x76>
mov    %rsi,%r14
mov    0x10(%rsi),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
mov    0x18(%r14),%rdi
call   1070 <atoi@plt>
test   %ebx,%ebx
jle    1207 <main+0x97>
test   %eax,%eax
js     1207 <main+0x97>
mov    %ebx,%ebp
sub    %eax,%ebp
jle    1207 <main+0x97>
mov    %ebp,%edi
call   1090 <generate@plt>
mov    0x8(%r14),%rdi
lea    0xea4(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11d8 <main+0x68>
mov    0x8(%r14),%rdi
lea    0xe96(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    122c <main+0xbc>
mov    %ebp,%edi
call   1040 <table@plt>
jmp    11df <main+0x6f>
mov    %ebp,%edi
call   1030 <header@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe0a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2dd2(%rip),%rcx
mov    (%rcx),%edi
lea    0xe1e(%rip),%rsi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe21(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [53 x i8] c"Usage: gen-fib <header|table> <limbbits> <nailbits>\0A\00"
@.str.1 = [31 x i8] c"Invalid limb/nail bits: %d %d\0A\00"
@.str.2 = [7 x i8] c"header\00"
@.str.3 = [6 x i8] c"table\00"
@.str.4 = [33 x i8] c"Invalid header/table choice: %s\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 = load i32, i32* %4
%10 = icmp ne i32 %9, 4
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([53 x i8], [53 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 2
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %7
%24 = load i32, i32* %6
%25 = icmp sle i32 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %15
%27 = load i32, i32* %7
%28 = icmp slt i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %26
%30 = load i32, i32* %7
%31 = load i32, i32* %6
%32 = icmp sge i32 %30, %31
br i1 %32, label %33, label %39
33: ; preds = %29, %26, %15
%34 = load i32, i32* @stderr
%35 = load i32, i32* %6
%36 = load i32, i32* %7
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %36)
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %29
%40 = load i32, i32* %6
%41 = load i32, i32* %7
%42 = sub nsw i32 %40, %41
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = call i32 @generate(i32 %43)
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 1
%47 = load i8*, i8** %46
%48 = call i64 @strcmp(i8* %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %53
50: ; preds = %39
%51 = load i32, i32* %8
%52 = call i32 @header(i32 %51)
br label %70
53: ; preds = %39
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 1
%56 = load i8*, i8** %55
%57 = call i64 @strcmp(i8* %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%58 = icmp eq i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %53
%60 = load i32, i32* %8
%61 = call i32 @table(i32 %60)
br label %69
62: ; preds = %53
%63 = load i32, i32* @stderr
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %66)
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %59
br label %70
70: ; preds = %69, %50
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [53 x i8] c"Usage: gen-fib <header|table> <limbbits> <nailbits>\0A\00"
@.str.1 = [31 x i8] c"Invalid limb/nail bits: %d %d\0A\00"
@.str.2 = [7 x i8] c"header\00"
@.str.3 = [6 x i8] c"table\00"
@.str.4 = [33 x i8] c"Invalid header/table choice: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 3
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = icmp sgt i32 %11, 0
%16 = icmp sgt i32 %14, -1
%17 = select i1 %15, i1 %16, i1 false
%18 = icmp sgt i32 %11, %14
%19 = select i1 %17, i1 %18, i1 false
br i1 %19, label %24, label %20
20: ; preds = %8
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %14)
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %8
%25 = sub nsw i32 %11, %14
%26 = tail call i32 @generate(i32 %25)
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = tail call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %24
%32 = tail call i32 @header(i32 %25)
br label %44
33: ; preds = %24
%34 = load i8*, i8** %27
%35 = tail call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = tail call i32 @table(i32 %25)
br label %44
39: ; preds = %33
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %27
%42 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i8* %41)
%43 = tail call i32 @exit(i32 1)
unreachable
44: ; preds = %37, %31
ret i32 0
}