#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 INT_MAX;
int atoi(char const *);
int /*<<< orphan*/ dec2bin(int);
int /*<<< orphan*/ dec2hexa(int);
int /*<<< orphan*/ dec2oct(int);
int lookup_opt(int, char const **);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usage();
int main(int argc, const char *argv[]) {
  int decimal;
  if (argc < 2) {
    usage();
    return -1;
  }
  decimal = atoi(argv[argc - 1]);
  if (decimal < 0) {
    printf("ERROR: decimal number must be greater than zero (0).\n");
    return -1;
  }
  if (decimal > INT_MAX) {
    printf("ERROR: maximum decimal number supported is %d.\n", INT_MAX);
    return -1;
  }
  switch (lookup_opt(argc, argv)) {
  case 1:
    dec2bin(decimal);
    break;
  case 2:
    dec2oct(decimal);
    break;
  case 3:
    dec2hexa(decimal);
    break;
  default:
    dec2bin(decimal);
    break;
  }
  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   $0x2,-0x8(%rbp)
jge    11a3 <main+0x33>
mov    $0x0,%al
call   1070 <usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128c <main+0x11c>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11e0 <main+0x70>
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128c <main+0x11c>
mov    -0x14(%rbp),%eax
mov    0x2dfe(%rip),%rcx
cmp    (%rcx),%eax
jle    1215 <main+0xa5>
mov    0x2def(%rip),%rax
mov    (%rax),%esi
lea    0xe34(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    128c <main+0x11c>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <lookup_opt@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
sub    $0x1,%eax
je     1256 <main+0xe6>
jmp    1234 <main+0xc4>
mov    -0x18(%rbp),%eax
sub    $0x2,%eax
je     1263 <main+0xf3>
jmp    1245 <main+0xd5>
mov    -0x18(%rbp),%eax
sub    $0x3,%eax
je     1270 <main+0x100>
jmp    127d <main+0x10d>
mov    -0x14(%rbp),%edi
call   1080 <dec2bin@plt>
jmp    1285 <main+0x115>
mov    -0x14(%rbp),%edi
call   1060 <dec2oct@plt>
jmp    1285 <main+0x115>
mov    -0x14(%rbp),%edi
call   1050 <dec2hexa@plt>
jmp    1285 <main+0x115>
mov    -0x14(%rbp),%edi
call   1080 <dec2bin@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x1,%edi
jg     119a <main+0x1a>
xor    %eax,%eax
call   1080 <usage@plt>
mov    $0xffffffff,%eax
jmp    121d <main+0x9d>
mov    %rsi,%rbx
mov    %edi,%ebp
lea    -0x1(%rbp),%eax
mov    (%rsi,%rax,8),%rdi
call   10a0 <atoi@plt>
test   %eax,%eax
js     11d5 <main+0x55>
mov    %eax,%r14d
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
cmp    %esi,%r14d
jle    11e8 <main+0x68>
lea    0xe39(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xffffffff,%eax
jmp    121d <main+0x9d>
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    121d <main+0x9d>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <lookup_opt@plt>
cmp    $0x3,%eax
je     1209 <main+0x89>
cmp    $0x2,%eax
je     1213 <main+0x93>
cmp    $0x1,%eax
mov    %r14d,%edi
call   1090 <dec2bin@plt>
jmp    121b <main+0x9b>
mov    %r14d,%edi
call   1060 <dec2hexa@plt>
jmp    121b <main+0x9b>
mov    %r14d,%edi
call   1070 <dec2oct@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [54 x i8] c"ERROR: decimal number must be greater than zero (0).\0A\00"
@INT_MAX = global i32 0
@.str.1 = [48 x i8] c"ERROR: maximum decimal number supported is %d.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (...) @usage()
store i32 -1, i32* %3
br label %47
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %12, i64 %15
%17 = load i8*, i8** %16
%18 = call i32 @atoi(i8* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %11
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %47
23: ; preds = %11
%24 = load i32, i32* %6
%25 = load i32, i32* @INT_MAX
%26 = icmp sgt i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* @INT_MAX
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %28)
store i32 -1, i32* %3
br label %47
30: ; preds = %23
%31 = load i32, i32* %4
%32 = load i8**, i8*** %5
%33 = call i32 @lookup_opt(i32 %31, i8** %32)
switch i32 %33, label %43 [
i32 1, label %34
i32 2, label %37
i32 3, label %40
]
34: ; preds = %30
%35 = load i32, i32* %6
%36 = call i32 @dec2bin(i32 %35)
br label %46
37: ; preds = %30
%38 = load i32, i32* %6
%39 = call i32 @dec2oct(i32 %38)
br label %46
40: ; preds = %30
%41 = load i32, i32* %6
%42 = call i32 @dec2hexa(i32 %41)
br label %46
43: ; preds = %30
%44 = load i32, i32* %6
%45 = call i32 @dec2bin(i32 %44)
br label %46
46: ; preds = %43, %40, %37, %34
store i32 0, i32* %3
br label %47
47: ; preds = %46, %27, %21, %9
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@INT_MAX = global i32 0
@.str.1 = [48 x i8] c"ERROR: maximum decimal number supported is %d.\0A\00"
@str = [53 x i8] c"ERROR: decimal number must be greater than zero (0).\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %30
6: ; preds = %2
%7 = add nsw i32 %0, -1
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8*, i8** %1, i64 %8
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %6
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str, i64 0, i64 0))
br label %30
15: ; preds = %6
%16 = load i32, i32* @INT_MAX
%17 = icmp sgt i32 %11, %16
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %30
20: ; preds = %15
%21 = tail call i32 @lookup_opt(i32 %0, i8** %1)
switch i32 %21, label %28 [
i32 1, label %22
i32 2, label %24
i32 3, label %26
]
22: ; preds = %20
%23 = tail call i32 @dec2bin(i32 %11)
br label %30
24: ; preds = %20
%25 = tail call i32 @dec2oct(i32 %11)
br label %30
26: ; preds = %20
%27 = tail call i32 @dec2hexa(i32 %11)
br label %30
28: ; preds = %20
%29 = tail call i32 @dec2bin(i32 %11)
br label %30
30: ; preds = %22, %24, %26, %28, %18, %13, %4
%31 = phi i32 [ -1, %4 ], [ -1, %13 ], [ -1, %18 ], [ 0, %28 ], [ 0, %26 ], [ 0, %24 ], [ 0, %22 ]
ret i32 %31
}