int main(int argc, char **argv) {
  char *s = argv[1];
  int value = 0;
  static const char xd[] = {"0123456789abcdefABCDEF"};
  static const char xv[] = {0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10,
                            11, 12, 13, 14, 15, 10, 11, 12, 13, 14, 15};
  for (value = 0; isxdigit(*s); ++s) {
    value = (value << 4) + xv[strchr(xd, *s) - xd];
  }
  printf("value:%d", value);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isxdigit@plt>
cmp    $0x0,%eax
je     11c2 <main+0x92>
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%esi
lea    0xe74(%rip),%rdi
call   1030 <strchr@plt>
mov    %rax,%rdx
mov    -0x20(%rbp),%eax
lea    0xe62(%rip),%rcx
sub    %rcx,%rdx
lea    0xe78(%rip),%rcx
movsbl (%rcx,%rdx,1),%ecx
add    %ecx,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1160 <main+0x30>
mov    -0x1c(%rbp),%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x8(%rsi),%rbp
movsbl 0x0(%rbp),%r15d
mov    %r15d,%edi
call   1050 <isxdigit@plt>
test   %eax,%eax
je     11a4 <main+0x74>
add    $0x1,%rbp
xor    %ebx,%ebx
lea    0xea6(%rip),%r14
lea    0xebf(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
shl    $0x4,%ebx
mov    $0x17,%edx
mov    %r14,%rdi
mov    %r15d,%esi
call   1040 <memchr@plt>
sub    %r14,%rax
movsbl (%rax,%r12,1),%eax
add    %eax,%ebx
movsbl 0x0(%rbp),%r15d
mov    %r15d,%edi
call   1050 <isxdigit@plt>
add    $0x1,%rbp
test   %eax,%eax
jne    1170 <main+0x40>
jmp    11a6 <main+0x76>
xor    %ebx,%ebx
lea    0xe89(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@main.xd = internal constant [23 x i8] c"0123456789abcdefABCDEF\00"
@main.xv = internal constant [22 x i8] c"\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\0A\0B\0C\0D\0E\0F"
@.str = [9 x i8] c"value:%d\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
store i8* %10, i8** %6
store i32 0, i32* %7
store i32 0, i32* %7
br label %11
11: ; preds = %30, %2
%12 = load i8*, i8** %6
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = call i32 @isxdigit(i32 %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %33
17: ; preds = %11
%18 = load i32, i32* %7
%19 = shl i32 %18, 4
%20 = load i8*, i8** %6
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = call i8* @strchr(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @main.xd, i64 0, i64 0), i32 %22)
%24 = ptrtoint i8* %23 to i64
%25 = sub i64 %24, ptrtoint ([23 x i8]* @main.xd to i64)
%26 = getelementptr inbounds [22 x i8], [22 x i8]* @main.xv, i64 0, i64 %25
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = add nsw i32 %19, %28
store i32 %29, i32* %7
br label %30
30: ; preds = %17
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %6
br label %11
33: ; preds = %11
%34 = load i32, i32* %7
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@main.xd = internal constant [23 x i8] c"0123456789abcdefABCDEF\00"
@main.xv = internal unnamed_addr constant [22 x i8] c"\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F\0A\0B\0C\0D\0E\0F"
@.str = [9 x i8] c"value:%d\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
%7 = tail call i32 @isxdigit(i32 %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %26, label %9
9: ; preds = %2, %9
%10 = phi i32 [ %23, %9 ], [ %6, %2 ]
%11 = phi i32 [ %20, %9 ], [ 0, %2 ]
%12 = phi i8* [ %21, %9 ], [ %4, %2 ]
%13 = shl i32 %11, 4
%14 = tail call i8* @memchr(i8* dereferenceable(23) getelementptr inbounds ([23 x i8], [23 x i8]* @main.xd, i64 0, i64 0), i32 %10, i64 23)
%15 = ptrtoint i8* %14 to i64
%16 = sub i64 %15, ptrtoint ([23 x i8]* @main.xd to i64)
%17 = getelementptr inbounds [22 x i8], [22 x i8]* @main.xv, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = add nsw i32 %13, %19
%21 = getelementptr inbounds i8, i8* %12, i64 1
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = tail call i32 @isxdigit(i32 %23)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %9
26: ; preds = %9, %2
%27 = phi i32 [ 0, %2 ], [ %20, %9 ]
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %27)
ret i32 0
}