#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 */
scalar_t__ pow(int, int);
int strlen(char *);
int GetDValue(char *hex) {
  int i, n;
  int base = 16;
  int value = 0;
  int sum = 0;
  n = 0;
  for (i = strlen(hex) - 1; i >= 0; i--) {
    switch (hex[i]) {
    case '0':
      value = 0;
      break;
    case '1':
      value = 1;
      break;
    case '2':
      value = 2;
      break;
    case '3':
      value = 3;
      break;
    case '4':
      value = 4;
      break;
    case '5':
      value = 5;
      break;
    case '6':
      value = 6;
      break;
    case '7':
      value = 7;
      break;
    case '8':
      value = 8;
      break;
    case '9':
      value = 9;
      break;
    case 'A':
      value = 10;
      break;
    case 'a':
      value = 10;
      break;
    case 'B':
      value = 11;
      break;
    case 'b':
      value = 11;
      break;
    case 'C':
      value = 12;
      break;
    case 'c':
      value = 12;
      break;
    case 'D':
      value = 13;
      break;
    case 'd':
      value = 13;
      break;
    case 'E':
      value = 14;
      break;
    case 'e':
      value = 14;
      break;
    case 'F':
      value = 15;
      break;
    case 'f':
      value = 15;
      break;
    default:
      return (-1);
    }
    sum = sum + (value * (int)pow(base, n));
    n++;
  }
  return (sum);
}


x86 assembly (clang, -O0):
<GetDValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x10,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     12e6 <GetDValue+0x1c6>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x36,%eax
ja     129b <GetDValue+0x17b>
mov    -0x30(%rbp),%rax
lea    0xe76(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0x1,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0x2,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0x3,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0x4,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0x5,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0x6,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0x7,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0x8,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0x9,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0xa,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0xa,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0xb,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0xb,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0xc,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0xc,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0xd,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0xd,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0xe,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0xe,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0xf,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0xf,-0x20(%rbp)
jmp    12a7 <GetDValue+0x187>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ec <GetDValue+0x1cc>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <pow@plt>
mov    -0x38(%rbp),%ecx
mov    %rax,%rdx
mov    -0x34(%rbp),%eax
imul   %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1157 <GetDValue+0x37>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetDValue>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
test   %eax,%eax
jle    119d <GetDValue+0x7d>
mov    %eax,%ebx
add    $0xffffffffffffffff,%rbx
xor    %r15d,%r15d
movabs $0x7e0000007e03ff,%r12
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %ebx,%eax
movsbl (%r14,%rax,1),%ecx
lea    -0x30(%rcx),%edx
mov    $0xffffffff,%eax
cmp    $0x36,%edx
ja     119f <GetDValue+0x7f>
bt     %rdx,%r12
jae    119f <GetDValue+0x7f>
movslq %ecx,%r13
mov    $0x10,%edi
mov    %ebp,%esi
call   1040 <pow@plt>
lea    0xe80(%rip),%rcx
imul   -0xc0(%rcx,%r13,4),%eax
ff ff
add    %eax,%r15d
add    $0x1,%ebp
add    $0xffffffffffffffff,%rbx
mov    %r15d,%eax
cmp    $0xffffffff,%ebx
jne    1150 <GetDValue+0x30>
jmp    119f <GetDValue+0x7f>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @GetDValue(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 16, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %5
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %4
br label %12
12: ; preds = %56, %1
%13 = load i32, i32* %4
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %59
15: ; preds = %12
%16 = load i8*, i8** %3
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
switch i32 %21, label %44 [
i32 48, label %22
i32 49, label %23
i32 50, label %24
i32 51, label %25
i32 52, label %26
i32 53, label %27
i32 54, label %28
i32 55, label %29
i32 56, label %30
i32 57, label %31
i32 65, label %32
i32 97, label %33
i32 66, label %34
i32 98, label %35
i32 67, label %36
i32 99, label %37
i32 68, label %38
i32 100, label %39
i32 69, label %40
i32 101, label %41
i32 70, label %42
i32 102, label %43
]
22: ; preds = %15
store i32 0, i32* %7
br label %45
23: ; preds = %15
store i32 1, i32* %7
br label %45
24: ; preds = %15
store i32 2, i32* %7
br label %45
25: ; preds = %15
store i32 3, i32* %7
br label %45
26: ; preds = %15
store i32 4, i32* %7
br label %45
27: ; preds = %15
store i32 5, i32* %7
br label %45
28: ; preds = %15
store i32 6, i32* %7
br label %45
29: ; preds = %15
store i32 7, i32* %7
br label %45
30: ; preds = %15
store i32 8, i32* %7
br label %45
31: ; preds = %15
store i32 9, i32* %7
br label %45
32: ; preds = %15
store i32 10, i32* %7
br label %45
33: ; preds = %15
store i32 10, i32* %7
br label %45
34: ; preds = %15
store i32 11, i32* %7
br label %45
35: ; preds = %15
store i32 11, i32* %7
br label %45
36: ; preds = %15
store i32 12, i32* %7
br label %45
37: ; preds = %15
store i32 12, i32* %7
br label %45
38: ; preds = %15
store i32 13, i32* %7
br label %45
39: ; preds = %15
store i32 13, i32* %7
br label %45
40: ; preds = %15
store i32 14, i32* %7
br label %45
41: ; preds = %15
store i32 14, i32* %7
br label %45
42: ; preds = %15
store i32 15, i32* %7
br label %45
43: ; preds = %15
store i32 15, i32* %7
br label %45
44: ; preds = %15
store i32 -1, i32* %2
br label %61
45: ; preds = %43, %42, %41, %40, %39, %38, %37, %36, %35, %34, %33, %32, %31, %30, %29, %28, %27, %26, %25, %24, %23, %22
%46 = load i32, i32* %8
%47 = load i32, i32* %7
%48 = load i32, i32* %6
%49 = load i32, i32* %5
%50 = call i64 @pow(i32 %48, i32 %49)
%51 = trunc i64 %50 to i32
%52 = mul nsw i32 %47, %51
%53 = add nsw i32 %46, %52
store i32 %53, i32* %8
%54 = load i32, i32* %5
%55 = add nsw i32 %54, 1
store i32 %55, i32* %5
br label %56
56: ; preds = %45
%57 = load i32, i32* %4
%58 = add nsw i32 %57, -1
store i32 %58, i32* %4
br label %12
59: ; preds = %12
%60 = load i32, i32* %8
store i32 %60, i32* %2
br label %61
61: ; preds = %59, %44
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
@switch.table.GetDValue = [55 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8, i32 9, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 0, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15]
define i32 @GetDValue(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %32
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %22
%7 = phi i64 [ %5, %4 ], [ %10, %22 ]
%8 = phi i32 [ 0, %4 ], [ %29, %22 ]
%9 = phi i32 [ 0, %4 ], [ %30, %22 ]
%10 = add nsw i64 %7, -1
%11 = and i64 %10, 4294967295
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = add nsw i32 %14, -48
%16 = icmp ult i32 %15, 55
br i1 %16, label %17, label %32
17: ; preds = %6
%18 = zext i32 %15 to i64
%19 = lshr i64 35465847073801215, %18
%20 = and i64 %19, 1
%21 = icmp eq i64 %20, 0
br i1 %21, label %32, label %22
22: ; preds = %17
%23 = sext i32 %15 to i64
%24 = getelementptr inbounds [55 x i32], [55 x i32]* @switch.table.GetDValue, i64 0, i64 %23
%25 = load i32, i32* %24
%26 = tail call i64 @pow(i32 16, i32 %9)
%27 = trunc i64 %26 to i32
%28 = mul nsw i32 %25, %27
%29 = add nsw i32 %28, %8
%30 = add nuw nsw i32 %9, 1
%31 = icmp eq i32 %30, %2
br i1 %31, label %32, label %6
32: ; preds = %22, %6, %17, %1
%33 = phi i32 [ 0, %1 ], [ -1, %17 ], [ %29, %22 ], [ -1, %6 ]
ret i32 %33
}