#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*/ fprintf(int /*<<< orphan*/, char *, char const *);
int opt_arg_scan(char const *, char const **);
int /*<<< orphan*/ stderr;
int set_base(const char *in, const char *out) {
  const char *tokens[] = {"b",       "o",           "d",   "h",      "bin",
                          "oct",     "dec",         "hex", "binary", "octal",
                          "decimal", "hexadecimal", "\0"};
  enum {
    A_B = 0,
    A_O,
    A_D,
    A_H,
    A_BIN,
    A_OCT,
    A_DEC,
    A_HEX,
    A_BINARY,
    A_OCTAL,
    A_DECIMAL,
    A_HEXADECIMAL
  };
  if (in == NULL || out == NULL)
    return -1;
  extern int InNumBase, OutNumBase;
  InNumBase = opt_arg_scan(in, tokens);
  OutNumBase = opt_arg_scan(out, tokens);
  int i, buff, error;
  buff = error = 0;
  for (i = 1; i <= 2; i++) {
    if (i != 1)
      buff = OutNumBase;
    else
      buff = InNumBase;
    switch (buff) {
    case A_B:
    case A_BIN:
    case A_BINARY:
      buff = 2;
      break;
    case A_O:
    case A_OCT:
    case A_OCTAL:
      buff = 8;
      break;
    case A_D:
    case A_DEC:
    case A_DECIMAL:
      buff = 10;
      break;
    case A_H:
    case A_HEX:
    case A_HEXADECIMAL:
      buff = 16;
      break;
    default:
      if (i != 1)
        fprintf(stderr, "error: '%s' is not a number base.\n", out);
      else
        fprintf(stderr, "error: '%s' is not a number base.\n", in);
      error = 1;
      break;
    }
    if (i != 1)
      OutNumBase = buff;
    else
      InNumBase = buff;
  }
  return error ? -1 : 0;
}


x86 assembly (clang, -O0):
<set_base>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
lea    0x2c52(%rip),%rsi
mov    $0x68,%edx
call   1050 <memcpy@plt>
cmpq   $0x0,-0x10(%rbp)
je     116e <set_base+0x3e>
cmpq   $0x0,-0x18(%rbp)
jne    117a <set_base+0x4a>
movl   $0xffffffff,-0x4(%rbp)
jmp    131c <set_base+0x1ec>
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1030 <opt_arg_scan@plt>
mov    %eax,%ecx
mov    0x2e50(%rip),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1030 <opt_arg_scan@plt>
mov    %eax,%ecx
mov    0x2e40(%rip),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x8c(%rbp)
movl   $0x0,-0x88(%rbp)
movl   $0x1,-0x84(%rbp)
cmpl   $0x2,-0x84(%rbp)
jg     1306 <set_base+0x1d6>
cmpl   $0x1,-0x84(%rbp)
je     11f6 <set_base+0xc6>
mov    0x2dff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
jmp    1205 <set_base+0xd5>
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    -0x88(%rbp),%eax
mov    %rax,-0x98(%rbp)
sub    $0xb,%rax
ja     126f <set_base+0x13f>
mov    -0x98(%rbp),%rax
lea    0xdd6(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x2,-0x88(%rbp)
jmp    12bd <set_base+0x18d>
movl   $0x8,-0x88(%rbp)
jmp    12bd <set_base+0x18d>
movl   $0xa,-0x88(%rbp)
jmp    12bd <set_base+0x18d>
movl   $0x10,-0x88(%rbp)
jmp    12bd <set_base+0x18d>
cmpl   $0x1,-0x84(%rbp)
je     129a <set_base+0x16a>
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdd3(%rip),%rsi
call   1040 <fprintf@plt>
jmp    12b3 <set_base+0x183>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdb5(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x1,-0x8c(%rbp)
cmpl   $0x1,-0x84(%rbp)
je     12de <set_base+0x1ae>
mov    -0x88(%rbp),%ecx
mov    0x2d11(%rip),%rax
mov    %ecx,(%rax)
jmp    12ed <set_base+0x1bd>
mov    -0x88(%rbp),%ecx
mov    0x2cf5(%rip),%rax
mov    %ecx,(%rax)
jmp    12f2 <set_base+0x1c2>
mov    -0x84(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
jmp    11c8 <set_base+0x98>
mov    -0x8c(%rbp),%edx
xor    %eax,%eax
mov    $0xffffffff,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_base>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    0x2ccb(%rip),%rax
mov    %rax,0x60(%rsp)
movaps 0x2caf(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0x2c93(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0x2c77(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0x2c5b(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0x2c3f(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0x2c23(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     127d <set_base+0x15d>
mov    %rsi,%r14
test   %rsi,%rsi
je     127d <set_base+0x15d>
mov    %rdi,%rbx
mov    %rsp,%rbp
mov    %rbp,%rsi
call   1030 <opt_arg_scan@plt>
mov    0x2e30(%rip),%r12
mov    %eax,(%r12)
mov    %r14,%rdi
mov    %rbp,%rsi
call   1030 <opt_arg_scan@plt>
mov    0x2e22(%rip),%r15
mov    %eax,(%r15)
mov    (%r12),%r13d
cmp    $0xb,%r13
ja     1201 <set_base+0xe1>
mov    %eax,%ebp
mov    $0x2,%ecx
xor    %eax,%eax
lea    0xe1d(%rip),%rdx
movslq (%rdx,%r13,4),%rsi
add    %rdx,%rsi
jmp    *%rsi
mov    $0x8,%ecx
jmp    1224 <set_base+0x104>
mov    $0xa,%ecx
jmp    1224 <set_base+0x104>
mov    $0x10,%ecx
jmp    1224 <set_base+0x104>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    (%r15),%ebp
mov    $0x1,%eax
mov    %r13d,%ecx
mov    %ecx,(%r12)
cmp    $0xb,%ebp
ja     1259 <set_base+0x139>
mov    %ebp,%ecx
lea    0xdfa(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
mov    $0x2,%ebp
jmp    *%rcx
mov    $0x8,%ebp
jmp    1276 <set_base+0x156>
mov    $0xa,%ebp
jmp    1276 <set_base+0x156>
mov    $0x10,%ebp
jmp    1276 <set_base+0x156>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
mov    $0x1,%eax
mov    %ebp,(%r15)
neg    %eax
sbb    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"b\00"
@.str.1 = [2 x i8] c"o\00"
@.str.2 = [2 x i8] c"d\00"
@.str.3 = [2 x i8] c"h\00"
@.str.4 = [4 x i8] c"bin\00"
@.str.5 = [4 x i8] c"oct\00"
@.str.6 = [4 x i8] c"dec\00"
@.str.7 = [4 x i8] c"hex\00"
@.str.8 = [7 x i8] c"binary\00"
@.str.9 = [6 x i8] c"octal\00"
@.str.10 = [8 x i8] c"decimal\00"
@.str.11 = [12 x i8] c"hexadecimal\00"
@.str.12 = [2 x i8] zeroinitializer
@__const.set_base.tokens = [13 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i32 0, i32 0)]
@InNumBase = external global i32
@OutNumBase = external global i32
@stderr = global i32 0
@.str.13 = [35 x i8] c"error: '%s' is not a number base.\0A\00"
define i32 @set_base(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [13 x i8*]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = bitcast [13 x i8*]* %6 to i8*
%11 = load i8*, i8** %4
%12 = icmp eq i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13, %2
store i32 -1, i32* %3
br label %68
17: ; preds = %13
%18 = load i8*, i8** %4
%19 = getelementptr inbounds [13 x i8*], [13 x i8*]* %6, i64 0, i64 0
%20 = call i32 @opt_arg_scan(i8* %18, i8** %19)
store i32 %20, i32* @InNumBase
%21 = load i8*, i8** %5
%22 = getelementptr inbounds [13 x i8*], [13 x i8*]* %6, i64 0, i64 0
%23 = call i32 @opt_arg_scan(i8* %21, i8** %22)
store i32 %23, i32* @OutNumBase
store i32 0, i32* %9
store i32 0, i32* %8
store i32 1, i32* %7
br label %24
24: ; preds = %60, %17
%25 = load i32, i32* %7
%26 = icmp sle i32 %25, 2
br i1 %26, label %27, label %63
27: ; preds = %24
%28 = load i32, i32* %7
%29 = icmp ne i32 %28, 1
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = load i32, i32* @OutNumBase
store i32 %31, i32* %8
br label %34
32: ; preds = %27
%33 = load i32, i32* @InNumBase
store i32 %33, i32* %8
br label %34
34: ; preds = %32, %30
%35 = load i32, i32* %8
switch i32 %35, label %40 [
i32 0, label %36
i32 4, label %36
i32 8, label %36
i32 1, label %37
i32 5, label %37
i32 9, label %37
i32 2, label %38
i32 6, label %38
i32 10, label %38
i32 3, label %39
i32 7, label %39
i32 11, label %39
]
36: ; preds = %34, %34, %34
store i32 2, i32* %8
br label %52
37: ; preds = %34, %34, %34
store i32 8, i32* %8
br label %52
38: ; preds = %34, %34, %34
store i32 10, i32* %8
br label %52
39: ; preds = %34, %34, %34
store i32 16, i32* %8
br label %52
40: ; preds = %34
%41 = load i32, i32* %7
%42 = icmp ne i32 %41, 1
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %5
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.13, i64 0, i64 0), i8* %45)
br label %51
47: ; preds = %40
%48 = load i32, i32* @stderr
%49 = load i8*, i8** %4
%50 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.13, i64 0, i64 0), i8* %49)
br label %51
51: ; preds = %47, %43
store i32 1, i32* %9
br label %52
52: ; preds = %51, %39, %38, %37, %36
%53 = load i32, i32* %7
%54 = icmp ne i32 %53, 1
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = load i32, i32* %8
store i32 %56, i32* @OutNumBase
br label %59
57: ; preds = %52
%58 = load i32, i32* %8
store i32 %58, i32* @InNumBase
br label %59
59: ; preds = %57, %55
br label %60
60: ; preds = %59
%61 = load i32, i32* %7
%62 = add nsw i32 %61, 1
store i32 %62, i32* %7
br label %24
63: ; preds = %24
%64 = load i32, i32* %9
%65 = icmp ne i32 %64, 0
%66 = zext i1 %65 to i64
%67 = select i1 %65, i32 -1, i32 0
store i32 %67, i32* %3
br label %68
68: ; preds = %63, %16
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [2 x i8] c"b\00"
@.str.1 = [2 x i8] c"o\00"
@.str.2 = [2 x i8] c"d\00"
@.str.3 = [2 x i8] c"h\00"
@.str.4 = [4 x i8] c"bin\00"
@.str.5 = [4 x i8] c"oct\00"
@.str.6 = [4 x i8] c"dec\00"
@.str.7 = [4 x i8] c"hex\00"
@.str.8 = [7 x i8] c"binary\00"
@.str.9 = [6 x i8] c"octal\00"
@.str.10 = [8 x i8] c"decimal\00"
@.str.11 = [12 x i8] c"hexadecimal\00"
@.str.12 = [2 x i8] zeroinitializer
@__const.set_base.tokens = [13 x i8*] [i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i32 0, i32 0)]
@InNumBase = external global i32
@OutNumBase = external global i32
@stderr = global i32 0
@.str.13 = [35 x i8] c"error: '%s' is not a number base.\0A\00"
define i32 @set_base(i8* %0, i8* %1) {
%3 = alloca [13 x i8*]
%4 = bitcast [13 x i8*]* %3 to i8*
%5 = icmp eq i8* %0, null
%6 = icmp eq i8* %1, null
%7 = or i1 %5, %6
br i1 %7, label %35, label %8
8: ; preds = %2
%9 = getelementptr inbounds [13 x i8*], [13 x i8*]* %3, i64 0, i64 0
%10 = call i32 @opt_arg_scan(i8* %0, i8** %9)
store i32 %10, i32* @InNumBase
%11 = call i32 @opt_arg_scan(i8* %1, i8** %9)
store i32 %11, i32* @OutNumBase
%12 = load i32, i32* @InNumBase
switch i32 %12, label %16 [
i32 0, label %20
i32 4, label %20
i32 8, label %20
i32 1, label %13
i32 5, label %13
i32 9, label %13
i32 2, label %14
i32 6, label %14
i32 10, label %14
i32 3, label %15
i32 7, label %15
i32 11, label %15
]
13: ; preds = %8, %8, %8
br label %20
14: ; preds = %8, %8, %8
br label %20
15: ; preds = %8, %8, %8
br label %20
16: ; preds = %8
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.13, i64 0, i64 0), i8* %0)
%19 = load i32, i32* @OutNumBase
br label %20
20: ; preds = %16, %8, %8, %8, %15, %14, %13
%21 = phi i32 [ %19, %16 ], [ %11, %8 ], [ %11, %8 ], [ %11, %8 ], [ %11, %15 ], [ %11, %14 ], [ %11, %13 ]
%22 = phi i32 [ 1, %16 ], [ 0, %8 ], [ 0, %8 ], [ 0, %8 ], [ 0, %15 ], [ 0, %14 ], [ 0, %13 ]
%23 = phi i32 [ %12, %16 ], [ 2, %8 ], [ 2, %8 ], [ 2, %8 ], [ 16, %15 ], [ 10, %14 ], [ 8, %13 ]
store i32 %23, i32* @InNumBase
switch i32 %21, label %27 [
i32 0, label %30
i32 4, label %30
i32 8, label %30
i32 1, label %26
i32 5, label %26
i32 9, label %26
i32 2, label %25
i32 6, label %25
i32 10, label %25
i32 3, label %24
i32 7, label %24
i32 11, label %24
]
24: ; preds = %20, %20, %20
br label %30
25: ; preds = %20, %20, %20
br label %30
26: ; preds = %20, %20, %20
br label %30
27: ; preds = %20
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.13, i64 0, i64 0), i8* %1)
br label %30
30: ; preds = %27, %26, %25, %24, %20, %20, %20
%31 = phi i32 [ 1, %27 ], [ %22, %26 ], [ %22, %25 ], [ %22, %24 ], [ %22, %20 ], [ %22, %20 ], [ %22, %20 ]
%32 = phi i32 [ %21, %27 ], [ 8, %26 ], [ 10, %25 ], [ 16, %24 ], [ 2, %20 ], [ 2, %20 ], [ 2, %20 ]
store i32 %32, i32* @OutNumBase
%33 = icmp ne i32 %31, 0
%34 = sext i1 %33 to i32
br label %35
35: ; preds = %2, %30
%36 = phi i32 [ %34, %30 ], [ -1, %2 ]
ret i32 %36
}