#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 /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
int val(char);
int main(int argc, char *argv[]) {
  int base = atoi(argv[2]);
  printf("El numero es %s y su base es %d\n", argv[1], base);
  int len = strlen(argv[1]);
  int power = 1;
  int num = 0;
  int i;
  for (i = len - 1; i >= 0; i--) {
    num += val(argv[1][i]) * power;
    power *= base;
  }
  printf("El numero en base decimal es: %d\n", num);
}


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)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x14(%rbp),%edx
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11e7 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <val@plt>
imul   -0x1c(%rbp),%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
imul   -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    11a6 <main+0x66>
mov    -0x20(%rbp),%esi
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    0x10(%rsi),%rdi
call   1060 <atoi@plt>
mov    %eax,%r14d
mov    0x8(%r15),%rsi
lea    0xe9e(%rip),%rdi
xor    %r12d,%r12d
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%r15),%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11b4 <main+0x74>
mov    %eax,%ebx
add    $0x1,%rbx
mov    $0x1,%ebp
xor    %r12d,%r12d
nopl   0x0(%rax)
lea    -0x2(%rbx),%eax
mov    0x8(%r15),%rcx
movsbl (%rcx,%rax,1),%edi
call   1050 <val@plt>
imul   %ebp,%eax
add    %eax,%r12d
imul   %r14d,%ebp
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1190 <main+0x50>
lea    0xe66(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"El numero es %s y su base es %d\0A\00"
@.str.1 = [34 x i8] c"El numero en base decimal es: %d\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
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 2
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %18)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %7
store i32 1, i32* %8
store i32 0, i32* %9
%24 = load i32, i32* %7
%25 = sub nsw i32 %24, 1
store i32 %25, i32* %10
br label %26
26: ; preds = %45, %2
%27 = load i32, i32* %10
%28 = icmp sge i32 %27, 0
br i1 %28, label %29, label %48
29: ; preds = %26
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = load i32, i32* %10
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %32, i64 %34
%36 = load i8, i8* %35
%37 = call i32 @val(i8 signext %36)
%38 = load i32, i32* %8
%39 = mul nsw i32 %37, %38
%40 = load i32, i32* %9
%41 = add nsw i32 %40, %39
store i32 %41, i32* %9
%42 = load i32, i32* %6
%43 = load i32, i32* %8
%44 = mul nsw i32 %43, %42
store i32 %44, i32* %8
br label %45
45: ; preds = %29
%46 = load i32, i32* %10
%47 = add nsw i32 %46, -1
store i32 %47, i32* %10
br label %26
48: ; preds = %26
%49 = load i32, i32* %9
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %49)
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [33 x i8] c"El numero es %s y su base es %d\0A\00"
@.str.1 = [34 x i8] c"El numero en base decimal es: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 2
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %5)
%9 = load i8*, i8** %6
%10 = tail call i32 @strlen(i8* %9)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %2
%13 = zext i32 %10 to i64
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ %13, %12 ], [ %18, %14 ]
%16 = phi i32 [ 0, %12 ], [ %25, %14 ]
%17 = phi i32 [ 1, %12 ], [ %26, %14 ]
%18 = add nsw i64 %15, -1
%19 = load i8*, i8** %6
%20 = and i64 %18, 4294967295
%21 = getelementptr inbounds i8, i8* %19, i64 %20
%22 = load i8, i8* %21
%23 = tail call i32 @val(i8 signext %22)
%24 = mul nsw i32 %23, %17
%25 = add nsw i32 %24, %16
%26 = mul nsw i32 %17, %5
%27 = icmp ugt i64 %15, 1
br i1 %27, label %14, label %28
28: ; preds = %14, %2
%29 = phi i32 [ 0, %2 ], [ %25, %14 ]
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 %29)
ret i32 0
}