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

/* Variables and functions */
int converter_string_base(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, char *, char *, char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ representar_num_base(char *, int, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strtoul(char *, char **, int);
int main(int argc, char *argv[]) {
  char buffer[33];
  uint8_t base_entrada, base_saida;
  uint32_t valor;
  if (argc != 4) {
    printf("Uso %s [BASE DE ENTRADA] [BASE DE SAIDA] valor\n"
           "\n"
           "Programa simpes de conversão de bases que segue a filosofia UN"
           "IX. Aceita qualquer valor inteiro de 32 bits (entre 0 e 4,967."
           "295, em decimal) e converte para qualquer valor nessa mesma fa"
           "ixa. Aceita bases entre 2 e 36, devido a limitação representat"
           "iva de 10 digitos (0-9) + 26 letras (a-z ou A-Z)."
           "\n"
           "  Exemplo:\n"
           "    %s 10 16 1028\n"
           "    %s 16 10 deadbeef\n"
           "    %s 2 16 10100111001\n"
           "\n"
           "2014 Victor \"vtfrvl\" Franco (https://github.com/vtfrvl/)\n",
           argv[0], argv[0], argv[0], argv[0]);
    return 1;
  }
  base_entrada = converter_string_base(argv[1]);
  base_saida = converter_string_base(argv[2]);
  if ((base_saida < 2 || base_saida > 36) ||
      (base_entrada < 2 || base_entrada > 36)) {
    fprintf(stderr, "Base invalida. As bases devem ser "
                    "valores numéricos entre 2 e 36\n");
    return 2;
  }
  valor = strtoul(argv[3], &argv[3], base_entrada);
  if (*argv[3] != '\0') {
    fprintf(stderr, "Fragmento \"%s\" inesperado.\n", argv[3]);
    return 3;
  }
  representar_num_base(buffer, 32, valor, base_saida);
  puts(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11b4 <main+0x54>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
mov    (%rax),%r8
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    129d <main+0x13d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <converter_string_base@plt>
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <converter_string_base@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x2,-0x48(%rbp)
jl     11fc <main+0x9c>
cmpl   $0x24,-0x48(%rbp)
jg     11fc <main+0x9c>
cmpl   $0x2,-0x44(%rbp)
jl     11fc <main+0x9c>
cmpl   $0x24,-0x44(%rbp)
jle    121f <main+0xbf>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xfd7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    129d <main+0x13d>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x18,%rsi
mov    -0x44(%rbp),%edx
call   1080 <strtoul@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1279 <main+0x119>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xfc0(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    129d <main+0x13d>
lea    -0x40(%rbp),%rdi
mov    -0x4c(%rbp),%edx
mov    -0x48(%rbp),%ecx
mov    $0x20,%esi
call   1070 <representar_num_base@plt>
lea    -0x40(%rbp),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
cmp    $0x4,%edi
jne    11d0 <main+0x70>
mov    0x8(%rbx),%rdi
call   1040 <converter_string_base@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   1040 <converter_string_base@plt>
mov    %eax,%r14d
lea    -0x25(%r14),%eax
cmp    $0xffffffdd,%eax
jb     11ef <main+0x8f>
cmp    $0x2,%ebp
jl     11ef <main+0x8f>
cmp    $0x25,%ebp
jge    11ef <main+0x8f>
lea    0x18(%rbx),%rsi
mov    0x18(%rbx),%rdi
mov    %ebp,%edx
call   1080 <strtoul@plt>
mov    0x18(%rbx),%rdx
cmpb   $0x0,(%rdx)
je     120d <main+0xad>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
lea    0x1064(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x3,%eax
jmp    122c <main+0xcc>
mov    (%rbx),%rcx
lea    0xe26(%rip),%rdi
mov    %rcx,%rsi
mov    %rcx,%rdx
mov    %rcx,%r8
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    122c <main+0xcc>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xfe4(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%eax
jmp    122c <main+0xcc>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x20,%esi
mov    %eax,%edx
mov    %r14d,%ecx
call   1070 <representar_num_base@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [483 x i8] c"Uso %s [BASE DE ENTRADA] [BASE DE SAIDA] valor\0A\0APrograma simpes de convers\C3\A3o de bases que segue a filosofia UNIX. Aceita qualquer valor inteiro de 32 bits (entre 0 e 4,967.295, em decimal) e converte para qualquer valor nessa mesma faixa. Aceita bases entre 2 e 36, devido a limita\C3\A7\C3\A3o representativa de 10 digitos (0-9) + 26 letras (a-z ou A-Z).\0A Exemplo:\0A %s 10 16 1028\0A %s 16 10 deadbeef\0A %s 2 16 10100111001\0A\0A2014 Victor \22vtfrvl\22 Franco (https://github.com/vtfrvl/)\0A\00"
@stderr = global i32 0
@.str.1 = [67 x i8] c"Base invalida. As bases devem ser valores num\C3\A9ricos entre 2 e 36\0A\00"
@.str.2 = [28 x i8] c"Fragmento \22%s\22 inesperado.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [33 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 4
br i1 %11, label %12, label %26
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 @printf(i8* getelementptr inbounds ([483 x i8], [483 x i8]* @.str, i64 0, i64 0), i8* %15, i8* %18, i8* %21, i8* %24)
store i32 1, i32* %3
br label %76
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @converter_string_base(i8* %29)
store i32 %30, i32* %7
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @converter_string_base(i8* %33)
store i32 %34, i32* %8
%35 = load i32, i32* %8
%36 = icmp slt i32 %35, 2
br i1 %36, label %46, label %37
37: ; preds = %26
%38 = load i32, i32* %8
%39 = icmp sgt i32 %38, 36
br i1 %39, label %46, label %40
40: ; preds = %37
%41 = load i32, i32* %7
%42 = icmp slt i32 %41, 2
br i1 %42, label %46, label %43
43: ; preds = %40
%44 = load i32, i32* %7
%45 = icmp sgt i32 %44, 36
br i1 %45, label %46, label %49
46: ; preds = %43, %40, %37, %26
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0))
store i32 2, i32* %3
br label %76
49: ; preds = %43
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 3
%52 = load i8*, i8** %51
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 3
%55 = load i32, i32* %7
%56 = call i32 @strtoul(i8* %52, i8** %54, i32 %55)
store i32 %56, i32* %9
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 3
%59 = load i8*, i8** %58
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %69
63: ; preds = %49
%64 = load i32, i32* @stderr
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 3
%67 = load i8*, i8** %66
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %67)
store i32 3, i32* %3
br label %76
69: ; preds = %49
%70 = getelementptr inbounds [33 x i8], [33 x i8]* %6, i64 0, i64 0
%71 = load i32, i32* %9
%72 = load i32, i32* %8
%73 = call i32 @representar_num_base(i8* %70, i32 32, i32 %71, i32 %72)
%74 = getelementptr inbounds [33 x i8], [33 x i8]* %6, i64 0, i64 0
%75 = call i32 @puts(i8* %74)
store i32 0, i32* %3
br label %76
76: ; preds = %69, %63, %46, %12
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str = [483 x i8] c"Uso %s [BASE DE ENTRADA] [BASE DE SAIDA] valor\0A\0APrograma simpes de convers\C3\A3o de bases que segue a filosofia UNIX. Aceita qualquer valor inteiro de 32 bits (entre 0 e 4,967.295, em decimal) e converte para qualquer valor nessa mesma faixa. Aceita bases entre 2 e 36, devido a limita\C3\A7\C3\A3o representativa de 10 digitos (0-9) + 26 letras (a-z ou A-Z).\0A Exemplo:\0A %s 10 16 1028\0A %s 16 10 deadbeef\0A %s 2 16 10100111001\0A\0A2014 Victor \22vtfrvl\22 Franco (https://github.com/vtfrvl/)\0A\00"
@stderr = global i32 0
@.str.1 = [67 x i8] c"Base invalida. As bases devem ser valores num\C3\A9ricos entre 2 e 36\0A\00"
@.str.2 = [28 x i8] c"Fragmento \22%s\22 inesperado.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [33 x i8]
%4 = getelementptr inbounds [33 x i8], [33 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 4
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @printf(i8* getelementptr inbounds ([483 x i8], [483 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %7, i8* %7, i8* %7)
br label %38
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @converter_string_base(i8* %11)
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @converter_string_base(i8* %14)
%16 = add i32 %15, -37
%17 = icmp ult i32 %16, -35
%18 = icmp slt i32 %12, 2
%19 = select i1 %17, i1 true, i1 %18
%20 = icmp sgt i32 %12, 36
%21 = select i1 %19, i1 true, i1 %20
br i1 %21, label %22, label %25
22: ; preds = %9
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0))
br label %38
25: ; preds = %9
%26 = getelementptr inbounds i8*, i8** %1, i64 3
%27 = load i8*, i8** %26
%28 = tail call i32 @strtoul(i8* %27, i8** %26, i32 %12)
%29 = load i8*, i8** %26
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = tail call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %38
35: ; preds = %25
%36 = call i32 @representar_num_base(i8* %4, i32 32, i32 %28, i32 %15)
%37 = call i32 @puts(i8* %4)
br label %38
38: ; preds = %35, %32, %22, %6
%39 = phi i32 [ 1, %6 ], [ 2, %22 ], [ 3, %32 ], [ 0, %35 ]
ret i32 %39
}