#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 MacGetPosPower(int, int);
int strlen(char *);
unsigned char MacAtoX(char *str) {
  int len, count = 0;
  int num = 0;
  unsigned char c;
  len = strlen(str);
  while (len) {
    switch (*str) {
    case '0':
      count = 0;
      break;
    case '1':
      count = 1;
      break;
    case '2':
      count = 2;
      break;
    case '3':
      count = 3;
      break;
    case '4':
      count = 4;
      break;
    case '5':
      count = 5;
      break;
    case '6':
      count = 6;
      break;
    case '7':
      count = 7;
      break;
    case '8':
      count = 8;
      break;
    case '9':
      count = 9;
      break;
    case 'a':
    case 'A':
      count = 10;
      break;
    case 'b':
    case 'B':
      count = 11;
      break;
    case 'c':
    case 'C':
      count = 12;
      break;
    case 'd':
    case 'D':
      count = 13;
      break;
    case 'e':
    case 'E':
      count = 14;
      break;
    case 'f':
    case 'F':
      count = 15;
      break;
    }
    num += count * (MacGetPosPower(16, len - 1));
    str++;
    len--;
  }
  c = (unsigned char)num;
  return c;
}


x86 assembly (clang, -O0):
<MacAtoX>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1276 <MacAtoX+0x156>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x36,%eax
ja     1238 <MacAtoX+0x118>
mov    -0x20(%rbp),%rax
lea    0xe8c(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0x1,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0x2,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0x3,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0x4,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0x5,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0x6,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0x7,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0x8,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0x9,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0xa,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0xb,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0xc,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0xd,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0xe,-0x10(%rbp)
jmp    1238 <MacAtoX+0x118>
movl   $0xf,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%esi
sub    $0x1,%esi
mov    $0x10,%edi
call   1040 <MacGetPosPower@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
imul   %ecx,%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1146 <MacAtoX+0x26>
mov    -0x14(%rbp),%eax
mov    %al,-0x15(%rbp)
movzbl -0x15(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MacAtoX>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <strlen@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     1199 <MacAtoX+0x79>
mov    %eax,%ebp
add    $0xffffffff,%ebp
movabs $0x7e0000007e03ff,%r15
lea    0xeb0(%rip),%r12
xor    %r13d,%r13d
jmp    117c <MacAtoX+0x5c>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x10,%edi
mov    %ebp,%esi
call   1040 <MacGetPosPower@plt>
imul   %r13d,%eax
add    %eax,%r14d
add    $0x1,%rbx
add    $0xffffffff,%ebp
jae    1199 <MacAtoX+0x79>
movsbl (%rbx),%eax
lea    -0x30(%rax),%ecx
cmp    $0x36,%ecx
ja     1160 <MacAtoX+0x40>
bt     %rcx,%r15
jae    1160 <MacAtoX+0x40>
cltq
mov    -0xc0(%r12,%rax,4),%r13d
ff
jmp    1160 <MacAtoX+0x40>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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