#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 c2i(char);
int strlen(char *);
int hex2dec(char *hex) {
  int len;
  int num = 0;
  int temp;
  int bits;
  int i;
  len = strlen(hex);
  for (i = 0, temp = 0; i < len; i++, temp = 0) {
    temp = c2i(*(hex + i));
    bits = (len - i - 1) * 4;
    temp = temp << bits;
    num = num | temp;
  }
  return num;
}


x86 assembly (clang, -O0):
<hex2dec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a5 <hex2dec+0x85>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <c2i@plt>
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x1c(%rbp),%eax
sub    $0x1,%eax
shl    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x18(%rbp),%ecx
shl    %cl,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x14(%rbp)
jmp    114d <hex2dec+0x2d>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2dec>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    116f <hex2dec+0x4f>
mov    %eax,%r15d
lea    -0x4(,%rax,4),%ebp
xor    %ebx,%ebx
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl (%r14,%rbx,1),%edi
call   1040 <c2i@plt>
mov    %ebp,%ecx
shl    %cl,%eax
or     %eax,%r12d
add    $0x1,%rbx
add    $0xfffffffc,%ebp
cmp    %rbx,%r15
jne    1150 <hex2dec+0x30>
jmp    1172 <hex2dec+0x52>
xor    %r12d,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @hex2dec(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %3
store i32 0, i32* %7
store i32 0, i32* %5
br label %10
10: ; preds = %32, %1
%11 = load i32, i32* %7
%12 = load i32, i32* %3
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %35
14: ; preds = %10
%15 = load i8*, i8** %2
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @c2i(i8 signext %19)
store i32 %20, i32* %5
%21 = load i32, i32* %3
%22 = load i32, i32* %7
%23 = sub nsw i32 %21, %22
%24 = sub nsw i32 %23, 1
%25 = mul nsw i32 %24, 4
store i32 %25, i32* %6
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = shl i32 %26, %27
store i32 %28, i32* %5
%29 = load i32, i32* %4
%30 = load i32, i32* %5
%31 = or i32 %29, %30
store i32 %31, i32* %4
br label %32
32: ; preds = %14
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
store i32 0, i32* %5
br label %10
35: ; preds = %10
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
define i32 @hex2dec(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %20
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %18, %6 ]
%8 = phi i32 [ 0, %4 ], [ %17, %6 ]
%9 = trunc i64 %7 to i32
%10 = getelementptr inbounds i8, i8* %0, i64 %7
%11 = load i8, i8* %10
%12 = tail call i32 @c2i(i8 signext %11)
%13 = xor i32 %9, -1
%14 = add i32 %2, %13
%15 = shl nsw i32 %14, 2
%16 = shl i32 %12, %15
%17 = or i32 %16, %8
%18 = add nuw nsw i64 %7, 1
%19 = icmp eq i64 %18, %5
br i1 %19, label %20, label %6
20: ; preds = %6, %1
%21 = phi i32 [ 0, %1 ], [ %17, %6 ]
ret i32 %21
}