#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 int64_t;

/* Variables and functions */
int pow(int, int);
int64_t heximal_decimal(int64_t n) {
  int64_t decimal = 0, i = 0, rem;
  while (n != 0) {
    rem = n % 10;
    n /= 10;
    decimal += rem * pow(16, i);
    ++i;
  }
  return decimal;
}


x86 assembly (clang, -O0):
<heximal_decimal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     117e <heximal_decimal+0x6e>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%esi
mov    $0x10,%edi
call   1030 <pow@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
imul   %ecx,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1129 <heximal_decimal+0x19>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heximal_decimal>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
je     1175 <heximal_decimal+0x65>
mov    %edi,%ebx
xor    %r15d,%r15d
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %ebx,%r12
imul   $0x66666667,%r12,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x22,%rbx
add    %eax,%ebx
lea    (%rbx,%rbx,1),%eax
lea    (%rax,%rax,4),%eax
mov    %r12d,%ebp
sub    %eax,%ebp
mov    $0x10,%edi
mov    %r15d,%esi
call   1030 <pow@plt>
imul   %ebp,%eax
add    %eax,%r14d
add    $0x1,%r15d
add    $0x9,%r12d
cmp    $0x12,%r12d
ja     1130 <heximal_decimal+0x20>
jmp    1178 <heximal_decimal+0x68>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @heximal_decimal(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %9, %1
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = load i32, i32* %2
%11 = srem i32 %10, 10
store i32 %11, i32* %5
%12 = load i32, i32* %2
%13 = sdiv i32 %12, 10
store i32 %13, i32* %2
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = call i32 @pow(i32 16, i32 %15)
%17 = mul nsw i32 %14, %16
%18 = load i32, i32* %3
%19 = add nsw i32 %18, %17
store i32 %19, i32* %3
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %6
22: ; preds = %6
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
define i32 @heximal_decimal(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %15, label %3
3: ; preds = %1, %3
%4 = phi i32 [ %8, %3 ], [ %0, %1 ]
%5 = phi i32 [ %12, %3 ], [ 0, %1 ]
%6 = phi i32 [ %11, %3 ], [ 0, %1 ]
%7 = srem i32 %4, 10
%8 = sdiv i32 %4, 10
%9 = tail call i32 @pow(i32 16, i32 %5)
%10 = mul nsw i32 %9, %7
%11 = add nsw i32 %10, %6
%12 = add nuw nsw i32 %5, 1
%13 = add i32 %4, 9
%14 = icmp ult i32 %13, 19
br i1 %14, label %15, label %3
15: ; preds = %3, %1
%16 = phi i32 [ 0, %1 ], [ %11, %3 ]
ret i32 %16
}