#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 *);
int b10to2(int);
int b2to10(char *, int);
int b8to10(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("We be broke\n");
    return 1;
  }
  char *str = argv[2];
  int lng = strlen(str);
  int num = atoi(argv[argc - 1]);
  switch (atoi(argv[1])) {
  case 2:
    printf("%i\n", b2to10(str, lng));
    break;
  case 8:
    printf("%i\n", b8to10(str, lng));
    break;
  case 10:
    printf("%i\n", b10to2(num));
    break;
  default:
    printf("We be broke\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119a <main+0x3a>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    128d <main+0x12d>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%ecx
add    $0xffffffff,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,%ecx
mov    %ecx,-0x24(%rbp)
sub    $0x2,%eax
je     120d <main+0xad>
jmp    11eb <main+0x8b>
mov    -0x24(%rbp),%eax
sub    $0x8,%eax
je     122e <main+0xce>
jmp    11fc <main+0x9c>
mov    -0x24(%rbp),%eax
sub    $0xa,%eax
je     124f <main+0xef>
jmp    126c <main+0x10c>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <b2to10@plt>
mov    %eax,%esi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1286 <main+0x126>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <b8to10@plt>
mov    %eax,%esi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1286 <main+0x126>
mov    -0x20(%rbp),%edi
call   1060 <b10to2@plt>
mov    %eax,%esi
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1286 <main+0x126>
lea    0xd8d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    128d <main+0x12d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x3,%edi
jne    11b0 <main+0x40>
mov    %rsi,%rbp
mov    0x10(%rsi),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    0x8(%rbp),%rdi
call   1090 <atoi@plt>
cmp    $0xa,%eax
je     11c3 <main+0x53>
cmp    $0x8,%eax
je     11d5 <main+0x65>
cmp    $0x2,%eax
jne    11b0 <main+0x40>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1080 <b2to10@plt>
jmp    11e0 <main+0x70>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    11f2 <main+0x82>
mov    0x10(%rbp),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   1070 <b10to2@plt>
jmp    11e0 <main+0x70>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1060 <b8to10@plt>
lea    0xe19(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"We be broke\0A\00"
@.str.1 = [4 x i8] c"%i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %47
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = call i32 @strlen(i8* %17)
store i32 %18, i32* %7
%19 = load i8**, i8*** %5
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %19, i64 %22
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %8
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
switch i32 %29, label %44 [
i32 2, label %30
i32 8, label %35
i32 10, label %40
]
30: ; preds = %13
%31 = load i8*, i8** %6
%32 = load i32, i32* %7
%33 = call i32 @b2to10(i8* %31, i32 %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %33)
br label %46
35: ; preds = %13
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = call i32 @b8to10(i8* %36, i32 %37)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
br label %46
40: ; preds = %13
%41 = load i32, i32* %8
%42 = call i32 @b10to2(i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %42)
br label %46
44: ; preds = %13
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %47
46: ; preds = %40, %35, %30
store i32 0, i32* %3
br label %47
47: ; preds = %46, %44, %11
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str.1 = [4 x i8] c"%i\0A\00"
@str.2 = [12 x i8] c"We be broke\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.2, i64 0, i64 0))
br label %26
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32 @strlen(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
switch i32 %12, label %24 [
i32 2, label %13
i32 8, label %16
i32 10, label %19
]
13: ; preds = %6
%14 = tail call i32 @b2to10(i8* %8, i32 %9)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %26
16: ; preds = %6
%17 = tail call i32 @b8to10(i8* %8, i32 %9)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %26
19: ; preds = %6
%20 = load i8*, i8** %7
%21 = tail call i32 @atoi(i8* %20)
%22 = tail call i32 @b10to2(i32 %21)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %26
24: ; preds = %6
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %19, %16, %13, %4
%27 = phi i32 [ 1, %4 ], [ 1, %24 ], [ 0, %19 ], [ 0, %16 ], [ 0, %13 ]
ret i32 %27
}