#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 *);
char getopt(int, char **, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int optind;
int /*<<< orphan*/ print_binary(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  char str[1024];
  int num;
  int format = 16;
  char opt;
  memset(str, 0, 1024);
  while ((opt = getopt(argc, argv, "oxb")) != -1) {
    switch (opt) {
    case 'o':
      format = 8;
      break;
    case 'x':
      format = 16;
      break;
    case 'b':
      format = 2;
      break;
    default:
      usage(argv[0]);
    }
  }
  if (optind >= argc) {
    scanf("%s", str);
  } else {
    strcpy(str, argv[optind]);
  }
  num = atoi(str);
  switch (format) {
  case 16:
    printf("%x\n", num);
    break;
  case 8:
    printf("%o\n", num);
    break;
  case 2:
    print_binary(num);
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x10,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe3c(%rip),%rdx
call   1090 <getopt@plt>
mov    %al,-0x419(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     125c <main+0xdc>
movsbl -0x419(%rbp),%eax
mov    %eax,-0x420(%rbp)
sub    $0x62,%eax
je     123c <main+0xbc>
jmp    11f6 <main+0x76>
mov    -0x420(%rbp),%eax
sub    $0x6f,%eax
je     121e <main+0x9e>
jmp    120a <main+0x8a>
mov    -0x420(%rbp),%eax
sub    $0x78,%eax
je     122d <main+0xad>
jmp    124b <main+0xcb>
movl   $0x8,-0x418(%rbp)
jmp    1257 <main+0xd7>
movl   $0x10,-0x418(%rbp)
jmp    1257 <main+0xd7>
movl   $0x2,-0x418(%rbp)
jmp    1257 <main+0xd7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
jmp    11b6 <main+0x36>
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     1286 <main+0x106>
lea    -0x410(%rbp),%rsi
lea    0xd88(%rip),%rdi
call   1080 <scanf@plt>
jmp    12a4 <main+0x124>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x2d50(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x414(%rbp)
mov    -0x418(%rbp),%eax
mov    %eax,-0x424(%rbp)
sub    $0x2,%eax
je     1326 <main+0x1a6>
jmp    12d0 <main+0x150>
mov    -0x424(%rbp),%eax
sub    $0x8,%eax
je     130f <main+0x18f>
jmp    12e4 <main+0x164>
mov    -0x424(%rbp),%eax
sub    $0x10,%eax
jne    1331 <main+0x1b1>
jmp    12f8 <main+0x178>
mov    -0x414(%rbp),%esi
lea    0xd02(%rip),%rdi
call   1040 <printf@plt>
jmp    1331 <main+0x1b1>
mov    -0x414(%rbp),%esi
lea    0xcef(%rip),%rdi
call   1040 <printf@plt>
jmp    1331 <main+0x1b1>
mov    -0x414(%rbp),%edi
call   1060 <print_binary@plt>
xor    %eax,%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    0xe58(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1090 <getopt@plt>
mov    $0x10,%r15d
cmp    $0xff,%al
je     122a <main+0xaa>
lea    0xe3d(%rip),%r14
jmp    11e7 <main+0x67>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x2,%r15d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1090 <getopt@plt>
cmp    $0xff,%al
je     122a <main+0xaa>
movsbl %al,%eax
cmp    $0x62,%eax
je     11d0 <main+0x50>
cmp    $0x6f,%eax
je     1210 <main+0x90>
cmp    $0x78,%eax
jne    1220 <main+0xa0>
mov    $0x10,%r15d
jmp    11d6 <main+0x56>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x8,%r15d
jmp    11d6 <main+0x56>
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rdi
call   1070 <usage@plt>
jmp    11d6 <main+0x56>
mov    0x2db7(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    1246 <main+0xc6>
mov    (%rbx,%rax,8),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
jmp    1255 <main+0xd5>
lea    0xdb7(%rip),%rdi
mov    %rsp,%rsi
call   1080 <scanf@plt>
mov    %rsp,%rdi
call   10a0 <atoi@plt>
cmp    $0x2,%r15d
je     1278 <main+0xf8>
cmp    $0x8,%r15d
je     1281 <main+0x101>
cmp    $0x10,%r15d
jne    128f <main+0x10f>
lea    0xd91(%rip),%rdi
jmp    1288 <main+0x108>
mov    %eax,%edi
call   1060 <print_binary@plt>
jmp    128f <main+0x10f>
lea    0xd83(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"oxb\00"
@optind = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%x\0A\00"
@.str.3 = [4 x i8] c"%o\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 16, i32* %8
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 1024)
br label %12
12: ; preds = %29, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call signext i8 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8 %15, i8* %9
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %30
18: ; preds = %12
%19 = load i8, i8* %9
%20 = sext i8 %19 to i32
switch i32 %20, label %24 [
i32 111, label %21
i32 120, label %22
i32 98, label %23
]
21: ; preds = %18
store i32 8, i32* %8
br label %29
22: ; preds = %18
store i32 16, i32* %8
br label %29
23: ; preds = %18
store i32 2, i32* %8
br label %29
24: ; preds = %18
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 @usage(i8* %27)
br label %29
29: ; preds = %24, %23, %22, %21
br label %12
30: ; preds = %12
%31 = load i32, i32* @optind
%32 = load i32, i32* %4
%33 = icmp sge i32 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %35)
br label %45
37: ; preds = %30
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%39 = load i8**, i8*** %5
%40 = load i32, i32* @optind
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %39, i64 %41
%43 = load i8*, i8** %42
%44 = call i32 @strcpy(i8* %38, i8* %43)
br label %45
45: ; preds = %37, %34
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%47 = call i32 @atoi(i8* %46)
store i32 %47, i32* %7
%48 = load i32, i32* %8
switch i32 %48, label %58 [
i32 16, label %49
i32 8, label %52
i32 2, label %55
]
49: ; preds = %45
%50 = load i32, i32* %7
%51 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %50)
br label %58
52: ; preds = %45
%53 = load i32, i32* %7
%54 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %53)
br label %58
55: ; preds = %45
%56 = load i32, i32* %7
%57 = call i32 @print_binary(i32 %56)
br label %58
58: ; preds = %45, %55, %52, %49
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c"oxb\00"
@optind = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [4 x i8] c"%x\0A\00"
@.str.3 = [4 x i8] c"%o\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 1024)
%6 = call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8 %6, -1
br i1 %7, label %21, label %8
8: ; preds = %2, %17
%9 = phi i8 [ %19, %17 ], [ %6, %2 ]
%10 = phi i32 [ %18, %17 ], [ 16, %2 ]
%11 = sext i8 %9 to i32
switch i32 %11, label %14 [
i32 111, label %17
i32 120, label %12
i32 98, label %13
]
12: ; preds = %8
br label %17
13: ; preds = %8
br label %17
14: ; preds = %8
%15 = load i8*, i8** %1
%16 = call i32 @usage(i8* %15)
br label %17
17: ; preds = %8, %14, %13, %12
%18 = phi i32 [ %10, %14 ], [ 2, %13 ], [ 16, %12 ], [ 8, %8 ]
%19 = call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i8 %19, -1
br i1 %20, label %21, label %8
21: ; preds = %17, %2
%22 = phi i32 [ 16, %2 ], [ %18, %17 ]
%23 = load i32, i32* @optind
%24 = icmp slt i32 %23, %0
br i1 %24, label %27, label %25
25: ; preds = %21
%26 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %32
27: ; preds = %21
%28 = sext i32 %23 to i64
%29 = getelementptr inbounds i8*, i8** %1, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 @strcpy(i8* %4, i8* %30)
br label %32
32: ; preds = %27, %25
%33 = call i32 @atoi(i8* %4)
switch i32 %22, label %40 [
i32 16, label %34
i32 8, label %36
i32 2, label %38
]
34: ; preds = %32
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %40
36: ; preds = %32
%37 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %40
38: ; preds = %32
%39 = call i32 @print_binary(i32 %33)
br label %40
40: ; preds = %32, %38, %36, %34
ret i32 0
}