#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(int /*<<< orphan*/);
int getopt(int, char **, char *);
int htoi(int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ print_number_as_binary(int);
int /*<<< orphan*/ print_number_as_visualized_binary(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int num;
  int opt;
  while ((opt = getopt(argc, argv, "-d:-x:")) != -1) {
    switch (opt) {
    case 'd':
      num = atoi(optarg);
      break;
    case 'x':
      num = htoi(optarg);
      break;
    default:
      usage();
      return 1;
    }
    printf("dec: 0d%d\n", num);
    printf("hex: 0x%0X\n", num);
    printf("bin: 0b");
    print_number_as_binary(num);
    printf("\n");
    print_number_as_visualized_binary(num);
    return 0;
  }
  usage();
  return 1;
}


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    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6c(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1263 <main+0xf3>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x64,%eax
je     11ca <main+0x5a>
jmp    11b9 <main+0x49>
mov    -0x1c(%rbp),%eax
sub    $0x78,%eax
je     11e0 <main+0x70>
jmp    11f6 <main+0x86>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    1209 <main+0x99>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
call   1060 <htoi@plt>
mov    %eax,-0x14(%rbp)
jmp    1209 <main+0x99>
mov    $0x0,%al
call   1070 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    1271 <main+0x101>
mov    -0x14(%rbp),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1040 <print_number_as_binary@plt>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <print_number_as_visualized_binary@plt>
movl   $0x0,-0x4(%rbp)
jmp    1271 <main+0x101>
mov    $0x0,%al
call   1070 <usage@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xe76(%rip),%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
je     11ae <main+0x2e>
cmp    $0x78,%eax
je     11bc <main+0x3c>
cmp    $0x64,%eax
jne    11ae <main+0x2e>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
call   10a0 <atoi@plt>
jmp    11ca <main+0x4a>
xor    %eax,%eax
call   1080 <usage@plt>
mov    $0x1,%ebp
jmp    1214 <main+0x94>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1070 <htoi@plt>
mov    %eax,%ebx
lea    0xe34(%rip),%rdi
xor    %ebp,%ebp
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe2d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe29(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <print_number_as_binary@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%edi
call   1060 <print_number_as_visualized_binary@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"-d:-x:\00"
@optarg = global i32 0
@.str.1 = [11 x i8] c"dec: 0d%d\0A\00"
@.str.2 = [12 x i8] c"hex: 0x%0X\0A\00"
@.str.3 = [8 x i8] c"bin: 0b\00"
@.str.4 = [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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %2
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %7
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %34
13: ; preds = %8
%14 = load i32, i32* %7
switch i32 %14, label %21 [
i32 100, label %15
i32 120, label %18
]
15: ; preds = %13
%16 = load i32, i32* @optarg
%17 = call i32 @atoi(i32 %16)
store i32 %17, i32* %6
br label %23
18: ; preds = %13
%19 = load i32, i32* @optarg
%20 = call i32 @htoi(i32 %19)
store i32 %20, i32* %6
br label %23
21: ; preds = %13
%22 = call i32 (...) @usage()
store i32 1, i32* %3
br label %36
23: ; preds = %18, %15
%24 = load i32, i32* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %6
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* %6
%30 = call i32 @print_number_as_binary(i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%32 = load i32, i32* %6
%33 = call i32 @print_number_as_visualized_binary(i32 %32)
store i32 0, i32* %3
br label %36
34: ; preds = %8
%35 = call i32 (...) @usage()
store i32 1, i32* %3
br label %36
36: ; preds = %34, %23, %21
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [7 x i8] c"-d:-x:\00"
@optarg = global i32 0
@.str.1 = [11 x i8] c"dec: 0d%d\0A\00"
@.str.2 = [12 x i8] c"hex: 0x%0X\0A\00"
@.str.3 = [8 x i8] c"bin: 0b\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %3, label %10 [
i32 -1, label %20
i32 100, label %4
i32 120, label %7
]
4: ; preds = %2
%5 = load i32, i32* @optarg
%6 = tail call i32 @atoi(i32 %5)
br label %12
7: ; preds = %2
%8 = load i32, i32* @optarg
%9 = tail call i32 @htoi(i32 %8)
br label %12
10: ; preds = %2
%11 = tail call i32 (...) @usage()
br label %22
12: ; preds = %7, %4
%13 = phi i32 [ %9, %7 ], [ %6, %4 ]
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%17 = tail call i32 @print_number_as_binary(i32 %13)
%18 = tail call i32 @putchar(i32 10)
%19 = tail call i32 @print_number_as_visualized_binary(i32 %13)
br label %22
20: ; preds = %2
%21 = tail call i32 (...) @usage()
br label %22
22: ; preds = %20, %12, %10
%23 = phi i32 [ 1, %10 ], [ 0, %12 ], [ 1, %20 ]
ret i32 %23
}