#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 /*<<< orphan*/ isdigit(char const);
int /*<<< orphan*/ print_bin(unsigned long long);
int /*<<< orphan*/ print_chr(unsigned long long);
int /*<<< orphan*/ print_dec(unsigned long long);
int /*<<< orphan*/ print_hex(unsigned long long);
int /*<<< orphan*/ print_oct(unsigned long long);
unsigned long long read_bin(char const *);
unsigned long long read_dec(char const *);
unsigned long long read_hex(char const *);
unsigned long long read_oct(char const *);
int /*<<< orphan*/ usage();
void hex(const char *s) {
  unsigned long long i = 0;
  switch (s[0]) {
  case 'b':
  case 'B':
    i = read_bin(s + 1);
    break;
  case 'x':
  case 'X':
    i = read_hex(s + 1);
    break;
  case '0':
    if (s[1] == '\0')
      i = read_dec(s);
    else if (s[1] == 'x' || s[1] == 'X')
      i = read_hex(s + 2);
    else
      i = read_oct(s + 1);
    break;
  default:
    if (isdigit(*s))
      i = read_dec(s);
    else
      usage();
    break;
  }
  print_bin(i);
  print_chr(i);
  print_dec(i);
  print_hex(i);
  print_oct(i);
}


x86 assembly (clang, -O0):
<hex>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x14(%rbp)
sub    $0x30,%eax
je     124c <hex+0x9c>
jmp    11dc <hex+0x2c>
mov    -0x14(%rbp),%eax
sub    $0x42,%eax
je     1220 <hex+0x70>
jmp    11ed <hex+0x3d>
mov    -0x14(%rbp),%eax
sub    $0x58,%eax
je     1236 <hex+0x86>
jmp    11fe <hex+0x4e>
mov    -0x14(%rbp),%eax
sub    $0x62,%eax
je     1220 <hex+0x70>
jmp    120f <hex+0x5f>
mov    -0x14(%rbp),%eax
sub    $0x78,%eax
je     1236 <hex+0x86>
jmp    12c2 <hex+0x112>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1040 <read_bin@plt>
mov    %rax,-0x10(%rbp)
jmp    12f5 <hex+0x145>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1050 <read_hex@plt>
mov    %rax,-0x10(%rbp)
jmp    12f5 <hex+0x145>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    126f <hex+0xbf>
mov    -0x8(%rbp),%rdi
call   10d0 <read_dec@plt>
mov    %rax,-0x10(%rbp)
jmp    12bd <hex+0x10d>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x78,%eax
je     1291 <hex+0xe1>
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x58,%eax
jne    12a7 <hex+0xf7>
mov    -0x8(%rbp),%rdi
add    $0x2,%rdi
call   1050 <read_hex@plt>
mov    %rax,-0x10(%rbp)
jmp    12b8 <hex+0x108>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1070 <read_oct@plt>
mov    %rax,-0x10(%rbp)
jmp    12bd <hex+0x10d>
jmp    12f5 <hex+0x145>
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
je     12e9 <hex+0x139>
mov    -0x8(%rbp),%rdi
call   10d0 <read_dec@plt>
mov    %rax,-0x10(%rbp)
jmp    12f0 <hex+0x140>
mov    $0x0,%al
call   10c0 <usage@plt>
jmp    12f5 <hex+0x145>
mov    -0x10(%rbp),%rdi
call   10b0 <print_bin@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <print_chr@plt>
mov    -0x10(%rbp),%rdi
call   1060 <print_dec@plt>
mov    -0x10(%rbp),%rdi
call   1090 <print_hex@plt>
mov    -0x10(%rbp),%rdi
call   1080 <print_oct@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex>:
push   %rbx
mov    %rdi,%rbx
movsbl (%rdi),%edi
cmp    $0x57,%edi
jle    11d9 <hex+0x29>
cmp    $0x58,%edi
je     11f7 <hex+0x47>
cmp    $0x78,%edi
je     11f7 <hex+0x47>
cmp    $0x62,%edi
jne    11e3 <hex+0x33>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1040 <read_bin@plt>
jmp    1222 <hex+0x72>
cmp    $0x30,%edi
je     11fd <hex+0x4d>
cmp    $0x42,%edi
je     11cb <hex+0x1b>
call   1030 <isdigit@plt>
test   %eax,%eax
jne    120c <hex+0x5c>
xor    %ebx,%ebx
xor    %eax,%eax
call   10c0 <usage@plt>
jmp    1225 <hex+0x75>
add    $0x1,%rbx
jmp    121a <hex+0x6a>
mov    0x1(%rbx),%al
cmp    $0x78,%al
je     1216 <hex+0x66>
cmp    $0x58,%al
je     1216 <hex+0x66>
test   %al,%al
jne    124e <hex+0x9e>
mov    %rbx,%rdi
call   10d0 <read_dec@plt>
jmp    1222 <hex+0x72>
add    $0x2,%rbx
mov    %rbx,%rdi
call   1050 <read_hex@plt>
mov    %rax,%rbx
mov    %rbx,%rdi
call   10b0 <print_bin@plt>
mov    %rbx,%rdi
call   10a0 <print_chr@plt>
mov    %rbx,%rdi
call   1060 <print_dec@plt>
mov    %rbx,%rdi
call   1090 <print_hex@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1080 <print_oct@plt>
add    $0x1,%rbx
mov    %rbx,%rdi
call   1070 <read_oct@plt>
jmp    1222 <hex+0x72>

LLVM IR (-O0):
define void @hex(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %3
%4 = load i8*, i8** %2
%5 = getelementptr inbounds i8, i8* %4, i64 0
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
switch i32 %7, label %47 [
i32 98, label %8
i32 66, label %8
i32 120, label %12
i32 88, label %12
i32 48, label %16
]
8: ; preds = %1, %1
%9 = load i8*, i8** %2
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = call i64 @read_bin(i8* %10)
store i64 %11, i64* %3
br label %58
12: ; preds = %1, %1
%13 = load i8*, i8** %2
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = call i64 @read_hex(i8* %14)
store i64 %15, i64* %3
br label %58
16: ; preds = %1
%17 = load i8*, i8** %2
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i8*, i8** %2
%24 = call i64 @read_dec(i8* %23)
store i64 %24, i64* %3
br label %46
25: ; preds = %16
%26 = load i8*, i8** %2
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 120
br i1 %30, label %37, label %31
31: ; preds = %25
%32 = load i8*, i8** %2
%33 = getelementptr inbounds i8, i8* %32, i64 1
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 88
br i1 %36, label %37, label %41
37: ; preds = %31, %25
%38 = load i8*, i8** %2
%39 = getelementptr inbounds i8, i8* %38, i64 2
%40 = call i64 @read_hex(i8* %39)
store i64 %40, i64* %3
br label %45
41: ; preds = %31
%42 = load i8*, i8** %2
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = call i64 @read_oct(i8* %43)
store i64 %44, i64* %3
br label %45
45: ; preds = %41, %37
br label %46
46: ; preds = %45, %22
br label %58
47: ; preds = %1
%48 = load i8*, i8** %2
%49 = load i8, i8* %48
%50 = call i32 @isdigit(i8 signext %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = load i8*, i8** %2
%54 = call i64 @read_dec(i8* %53)
store i64 %54, i64* %3
br label %57
55: ; preds = %47
%56 = call i32 (...) @usage()
br label %57
57: ; preds = %55, %52
br label %58
58: ; preds = %57, %46, %12, %8
%59 = load i64, i64* %3
%60 = call i32 @print_bin(i64 %59)
%61 = load i64, i64* %3
%62 = call i32 @print_chr(i64 %61)
%63 = load i64, i64* %3
%64 = call i32 @print_dec(i64 %63)
%65 = load i64, i64* %3
%66 = call i32 @print_hex(i64 %65)
%67 = load i64, i64* %3
%68 = call i32 @print_oct(i64 %67)
ret void
}

LLVM IR (-O2):
define void @hex(i8* %0) {
%2 = load i8, i8* %0
%3 = sext i8 %2 to i32
switch i32 %3, label %20 [
i32 98, label %4
i32 66, label %4
i32 120, label %7
i32 88, label %7
i32 48, label %10
]
4: ; preds = %1, %1
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = tail call i64 @read_bin(i8* %5)
br label %27
7: ; preds = %1, %1
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = tail call i64 @read_hex(i8* %8)
br label %27
10: ; preds = %1
%11 = getelementptr inbounds i8, i8* %0, i64 1
%12 = load i8, i8* %11
switch i8 %12, label %18 [
i8 0, label %13
i8 120, label %15
i8 88, label %15
]
13: ; preds = %10
%14 = tail call i64 @read_dec(i8* %0)
br label %27
15: ; preds = %10, %10
%16 = getelementptr inbounds i8, i8* %0, i64 2
%17 = tail call i64 @read_hex(i8* %16)
br label %27
18: ; preds = %10
%19 = tail call i64 @read_oct(i8* %11)
br label %27
20: ; preds = %1
%21 = tail call i32 @isdigit(i8 signext %2)
%22 = icmp eq i32 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = tail call i64 @read_dec(i8* %0)
br label %27
25: ; preds = %20
%26 = tail call i32 (...) @usage()
br label %27
27: ; preds = %23, %25, %13, %18, %15, %7, %4
%28 = phi i64 [ %24, %23 ], [ 0, %25 ], [ %14, %13 ], [ %17, %15 ], [ %19, %18 ], [ %9, %7 ], [ %6, %4 ]
%29 = tail call i32 @print_bin(i64 %28)
%30 = tail call i32 @print_chr(i64 %28)
%31 = tail call i32 @print_dec(i64 %28)
%32 = tail call i32 @print_hex(i64 %28)
%33 = tail call i32 @print_oct(i64 %28)
ret void
}