#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 */
typedef int /*<<< orphan*/ mpz_t;

/* Variables and functions */
int atoi(char *);
char *mpz_get_str(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ mpz_init_set_str(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  if (argc < 4) {
    printf(
        "Usage: %s <starting base> <ending base> <number in starting base>\n",
        argv[0]);
    printf("For example %s 10 16 255\n", argv[0]);
    return 1;
  }
  int starting_base = atoi(argv[1]);
  int ending_base = atoi(argv[2]);
  if (starting_base < 2 || starting_base > 32 || ending_base < 2 ||
      ending_base > 32) {
    printf("A base must be between 2 and 32.");
    return 1;
  }
  mpz_t number;
  mpz_init_set_str(number, argv[3], starting_base);
  printf("%s\n", mpz_get_str(NULL, ending_base, number));
  return 0;
}


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)
cmpl   $0x4,-0x8(%rbp)
jge    1196 <main+0x56>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xec0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1232 <main+0xf2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x2,-0x14(%rbp)
jl     11de <main+0x9e>
cmpl   $0x20,-0x14(%rbp)
jg     11de <main+0x9e>
cmpl   $0x2,-0x18(%rbp)
jl     11de <main+0x9e>
cmpl   $0x20,-0x18(%rbp)
jle    11f8 <main+0xb8>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1232 <main+0xf2>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x14(%rbp),%edx
call   1040 <mpz_init_set_str@plt>
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
xor    %eax,%eax
mov    %eax,%edi
call   1050 <mpz_get_str@plt>
mov    %rax,%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jg     1180 <main+0x30>
mov    (%rbx),%rsi
lea    0xe9a(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%rbx),%rsi
lea    0xecc(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11d9 <main+0x89>
mov    0x8(%rbx),%rdi
call   1070 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
lea    -0x21(%r14),%eax
cmp    $0xffffffe1,%eax
jb     11cb <main+0x7b>
cmp    $0x2,%ebp
jl     11cb <main+0x7b>
cmp    $0x21,%ebp
jge    11cb <main+0x7b>
mov    0x18(%rbx),%rsi
mov    %r14d,%edx
call   1050 <mpz_init_set_str@plt>
xor    %ebx,%ebx
xor    %edi,%edi
mov    %ebp,%esi
call   1060 <mpz_get_str@plt>
mov    %rax,%rdi
call   1030 <puts@plt>
jmp    11de <main+0x8e>
lea    0xe8b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [67 x i8] c"Usage: %s <starting base> <ending base> <number in starting base>\0A\00"
@.str.1 = [26 x i8] c"For example %s 10 16 255\0A\00"
@.str.2 = [33 x i8] c"A base must be between 2 and 32.\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%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 slt i32 %9, 4
br i1 %10, label %11, label %20
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %18)
store i32 1, i32* %3
br label %53
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32 @atoi(i8* %23)
store i32 %24, i32* %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %7
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 2
br i1 %30, label %40, label %31
31: ; preds = %20
%32 = load i32, i32* %6
%33 = icmp sgt i32 %32, 32
br i1 %33, label %40, label %34
34: ; preds = %31
%35 = load i32, i32* %7
%36 = icmp slt i32 %35, 2
br i1 %36, label %40, label %37
37: ; preds = %34
%38 = load i32, i32* %7
%39 = icmp sgt i32 %38, 32
br i1 %39, label %40, label %42
40: ; preds = %37, %34, %31, %20
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %53
42: ; preds = %37
%43 = load i32, i32* %8
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 3
%46 = load i8*, i8** %45
%47 = load i32, i32* %6
%48 = call i32 @mpz_init_set_str(i32 %43, i8* %46, i32 %47)
%49 = load i32, i32* %7
%50 = load i32, i32* %8
%51 = call i8* @mpz_get_str(i32* null, i32 %49, i32 %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %51)
store i32 0, i32* %3
br label %53
53: ; preds = %42, %40, %11
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [67 x i8] c"Usage: %s <starting base> <ending base> <number in starting base>\0A\00"
@.str.1 = [26 x i8] c"For example %s 10 16 255\0A\00"
@.str.2 = [33 x i8] c"A base must be between 2 and 32.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = load i8*, i8** %1
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %7)
br label %30
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = add i32 %12, -33
%17 = icmp ult i32 %16, -31
%18 = icmp slt i32 %15, 2
%19 = select i1 %17, i1 true, i1 %18
%20 = icmp sgt i32 %15, 32
%21 = select i1 %19, i1 true, i1 %20
br i1 %21, label %22, label %24
22: ; preds = %9
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %30
24: ; preds = %9
%25 = getelementptr inbounds i8*, i8** %1, i64 3
%26 = load i8*, i8** %25
%27 = tail call i32 @mpz_init_set_str(i32 undef, i8* %26, i32 %12)
%28 = tail call i8* @mpz_get_str(i32* null, i32 %15, i32 undef)
%29 = tail call i32 @puts(i8* dereferenceable(1) %28)
br label %30
30: ; preds = %22, %24, %4
%31 = phi i32 [ 1, %4 ], [ 1, %22 ], [ 0, %24 ]
ret i32 %31
}