#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 EXIT_FAILURE;
int btoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char getopt(int, char **, char *);
int htoi(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int optind;
int otoi(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  char str[1024];
  int num = 0;
  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]);
  }
  switch (format) {
  case 16:
    num = htoi(str);
    break;
  case 8:
    num = otoi(str);
    break;
  case 2:
    num = btoi(str);
    break;
  default:
    num = -1;
  }
  if (num == -1) {
    fprintf(stderr, "Error: incorrectly formatted string %s\n", str);
    return EXIT_FAILURE;
  }
  printf("%d\n", num);
  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   $0x0,-0x414(%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    0xe12(%rip),%rdx
call   10b0 <getopt@plt>
mov    %al,-0x419(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     1286 <main+0xe6>
movsbl -0x419(%rbp),%eax
mov    %eax,-0x420(%rbp)
sub    $0x62,%eax
je     1266 <main+0xc6>
jmp    1220 <main+0x80>
mov    -0x420(%rbp),%eax
sub    $0x6f,%eax
je     1248 <main+0xa8>
jmp    1234 <main+0x94>
mov    -0x420(%rbp),%eax
sub    $0x78,%eax
je     1257 <main+0xb7>
jmp    1275 <main+0xd5>
movl   $0x8,-0x418(%rbp)
jmp    1281 <main+0xe1>
movl   $0x10,-0x418(%rbp)
jmp    1281 <main+0xe1>
movl   $0x2,-0x418(%rbp)
jmp    1281 <main+0xe1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <usage@plt>
jmp    11e0 <main+0x40>
mov    0x2d5b(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jl     12b0 <main+0x110>
lea    -0x410(%rbp),%rsi
lea    0xd5e(%rip),%rdi
call   10a0 <scanf@plt>
jmp    12ce <main+0x12e>
lea    -0x410(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x2d26(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
call   1030 <strcpy@plt>
mov    -0x418(%rbp),%eax
mov    %eax,-0x424(%rbp)
sub    $0x2,%eax
je     133e <main+0x19e>
jmp    12e8 <main+0x148>
mov    -0x424(%rbp),%eax
sub    $0x8,%eax
je     1327 <main+0x187>
jmp    12fc <main+0x15c>
mov    -0x424(%rbp),%eax
sub    $0x10,%eax
jne    1355 <main+0x1b5>
jmp    1310 <main+0x170>
lea    -0x410(%rbp),%rdi
call   1080 <htoi@plt>
mov    %eax,-0x414(%rbp)
jmp    135f <main+0x1bf>
lea    -0x410(%rbp),%rdi
call   1070 <otoi@plt>
mov    %eax,-0x414(%rbp)
jmp    135f <main+0x1bf>
lea    -0x410(%rbp),%rdi
call   10c0 <btoi@plt>
mov    %eax,-0x414(%rbp)
jmp    135f <main+0x1bf>
movl   $0xffffffff,-0x414(%rbp)
ff ff ff
cmpl   $0xffffffff,-0x414(%rbp)
jne    1399 <main+0x1f9>
mov    0x2c65(%rip),%rax
mov    (%rax),%edi
lea    -0x410(%rbp),%rdx
lea    0xc84(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2c41(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13b2 <main+0x212>
mov    -0x414(%rbp),%esi
lea    0xc89(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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    0xe38(%rip),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   10b0 <getopt@plt>
mov    $0x10,%r15d
cmp    $0xff,%al
je     124a <main+0xaa>
lea    0xe1d(%rip),%r14
jmp    1207 <main+0x67>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x2,%r15d
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   10b0 <getopt@plt>
cmp    $0xff,%al
je     124a <main+0xaa>
movsbl %al,%eax
cmp    $0x62,%eax
je     11f0 <main+0x50>
cmp    $0x6f,%eax
je     1230 <main+0x90>
cmp    $0x78,%eax
jne    1240 <main+0xa0>
mov    $0x10,%r15d
jmp    11f6 <main+0x56>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x8,%r15d
jmp    11f6 <main+0x56>
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rdi
call   1090 <usage@plt>
jmp    11f6 <main+0x56>
mov    0x2d97(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    1285 <main+0xe5>
mov    (%rbx,%rax,8),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
cmp    $0x2,%r15d
je     129a <main+0xfa>
cmp    $0x8,%r15d
je     12b9 <main+0x119>
cmp    $0x10,%r15d
jne    12c6 <main+0x126>
mov    %rsp,%rdi
call   1080 <htoi@plt>
cmp    $0xffffffff,%eax
jne    12a7 <main+0x107>
jmp    12c6 <main+0x126>
lea    0xd78(%rip),%rdi
mov    %rsp,%rsi
call   10a0 <scanf@plt>
cmp    $0x2,%r15d
jne    126a <main+0xca>
mov    %rsp,%rdi
call   10c0 <btoi@plt>
cmp    $0xffffffff,%eax
je     12c6 <main+0x126>
lea    0xd81(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
jmp    12e7 <main+0x147>
mov    %rsp,%rdi
call   1070 <otoi@plt>
cmp    $0xffffffff,%eax
jne    12a7 <main+0x107>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
lea    0xd31(%rip),%rsi
mov    %rsp,%rdx
call   1060 <fprintf@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%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"
@stderr = global i32 0
@.str.2 = [40 x i8] c"Error: incorrectly formatted string %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%d\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 0, i32* %7
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 = load i32, i32* %8
switch i32 %46, label %56 [
i32 16, label %47
i32 8, label %50
i32 2, label %53
]
47: ; preds = %45
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%49 = call i32 @htoi(i8* %48)
store i32 %49, i32* %7
br label %57
50: ; preds = %45
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%52 = call i32 @otoi(i8* %51)
store i32 %52, i32* %7
br label %57
53: ; preds = %45
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%55 = call i32 @btoi(i8* %54)
store i32 %55, i32* %7
br label %57
56: ; preds = %45
store i32 -1, i32* %7
br label %57
57: ; preds = %56, %53, %50, %47
%58 = load i32, i32* %7
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %65
60: ; preds = %57
%61 = load i32, i32* @stderr
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%63 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %62)
%64 = load i32, i32* @EXIT_FAILURE
store i32 %64, i32* %3
br label %68
65: ; preds = %57
%66 = load i32, i32* %7
%67 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %66)
store i32 0, i32* %3
br label %68
68: ; preds = %65, %60
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [4 x i8] c"oxb\00"
@optind = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@stderr = global i32 0
@.str.2 = [40 x i8] c"Error: incorrectly formatted string %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%d\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
switch i32 %22, label %42 [
i32 16, label %33
i32 8, label %35
i32 2, label %37
]
33: ; preds = %32
%34 = call i32 @htoi(i8* %4)
br label %39
35: ; preds = %32
%36 = call i32 @otoi(i8* %4)
br label %39
37: ; preds = %32
%38 = call i32 @btoi(i8* %4)
br label %39
39: ; preds = %37, %35, %33
%40 = phi i32 [ %38, %37 ], [ %36, %35 ], [ %34, %33 ]
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %32, %39
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%45 = load i32, i32* @EXIT_FAILURE
br label %48
46: ; preds = %39
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %48
48: ; preds = %46, %42
%49 = phi i32 [ %45, %42 ], [ 0, %46 ]
ret i32 %49
}