#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 /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ strcat(char *, char *);
int hex2bin(char *hex, char *bin) {
  int i, j;
  for (j = 0; j < 7; j++)
    for (i = 0; i < 16; i++) {
      switch (hex[i]) {
      case '0':
        strcat(bin, "0000");
        break;
      case '1':
        strcat(bin, "0001");
        break;
      case '2':
        strcat(bin, "0010");
        break;
      case '3':
        strcat(bin, "0011");
        break;
      case '4':
        strcat(bin, "0100");
        break;
      case '5':
        strcat(bin, "0101");
        break;
      case '6':
        strcat(bin, "0110");
        break;
      case '7':
        strcat(bin, "0111");
        break;
      case '8':
        strcat(bin, "1000");
        break;
      case '9':
        strcat(bin, "1001");
        break;
      case 'a':
        strcat(bin, "1010");
        break;
      case 'b':
        strcat(bin, "1011");
        break;
      case 'c':
        strcat(bin, "1100");
        break;
      case 'd':
        strcat(bin, "1101");
        break;
      case 'e':
        strcat(bin, "1110");
        break;
      case 'f':
        strcat(bin, "1111");
        break;
      default:
        printf("\n Invalid hex digit %c ", hex[i]);
        return 0;
      }
    }
  return 1;
}


x86 assembly (clang, -O0):
<hex2bin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x7,-0x20(%rbp)
jge    131e <hex2bin+0x1fe>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x10,-0x1c(%rbp)
jge    130b <hex2bin+0x1eb>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x36,%eax
ja     12d4 <hex2bin+0x1b4>
mov    -0x28(%rbp),%rax
lea    0xe85(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
lea    0xf4d(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xf3d(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xf2d(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xf1d(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xf0d(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xefd(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xeed(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xedd(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xecd(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xebd(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xe9d(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x18(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1040 <strcat@plt>
jmp    12f8 <hex2bin+0x1d8>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
lea    0xe49(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1325 <hex2bin+0x205>
jmp    12fd <hex2bin+0x1dd>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1148 <hex2bin+0x28>
jmp    1310 <hex2bin+0x1f0>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1137 <hex2bin+0x17>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex2bin>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r13
xor    %r15d,%r15d
lea    0xfa1(%rip),%r12
lea    0xebe(%rip),%rbx
jmp    115e <hex2bin+0x3e>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%r15d
cmp    $0x7,%r15d
je     1243 <hex2bin+0x123>
xor    %ebp,%ebp
jmp    1182 <hex2bin+0x62>
lea    0xf78(%rip),%rsi
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <strcat@plt>
add    $0x1,%rbp
cmp    $0x10,%rbp
je     1150 <hex2bin+0x30>
movsbl 0x0(%r13,%rbp,1),%eax
lea    -0x30(%rax),%ecx
cmp    $0x36,%ecx
ja     1230 <hex2bin+0x110>
movslq (%rbx,%rcx,4),%rcx
add    %rbx,%rcx
mov    %r12,%rsi
jmp    *%rcx
lea    0xf3f(%rip),%rsi
jmp    1170 <hex2bin+0x50>
lea    0xf3b(%rip),%rsi
jmp    1170 <hex2bin+0x50>
lea    0xf37(%rip),%rsi
jmp    1170 <hex2bin+0x50>
lea    0xf33(%rip),%rsi
jmp    1170 <hex2bin+0x50>
lea    0xf2f(%rip),%rsi
jmp    1170 <hex2bin+0x50>
lea    0xf30(%rip),%rsi
jmp    1170 <hex2bin+0x50>
lea    0xf36(%rip),%rsi
jmp    1170 <hex2bin+0x50>
lea    0xf37(%rip),%rsi
jmp    1170 <hex2bin+0x50>
lea    0xf10(%rip),%rsi
jmp    1170 <hex2bin+0x50>
lea    0xf0e(%rip),%rsi
jmp    1170 <hex2bin+0x50>
lea    0xf07(%rip),%rsi
jmp    1170 <hex2bin+0x50>
lea    0xf05(%rip),%rsi
jmp    1170 <hex2bin+0x50>
lea    0xf03(%rip),%rsi
jmp    1170 <hex2bin+0x50>
lea    0xefc(%rip),%rsi
jmp    1170 <hex2bin+0x50>
movsbl %al,%esi
lea    0xef2(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    1248 <hex2bin+0x128>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"0000\00"
@.str.1 = [5 x i8] c"0001\00"
@.str.2 = [5 x i8] c"0010\00"
@.str.3 = [5 x i8] c"0011\00"
@.str.4 = [5 x i8] c"0100\00"
@.str.5 = [5 x i8] c"0101\00"
@.str.6 = [5 x i8] c"0110\00"
@.str.7 = [5 x i8] c"0111\00"
@.str.8 = [5 x i8] c"1000\00"
@.str.9 = [5 x i8] c"1001\00"
@.str.10 = [5 x i8] c"1010\00"
@.str.11 = [5 x i8] c"1011\00"
@.str.12 = [5 x i8] c"1100\00"
@.str.13 = [5 x i8] c"1101\00"
@.str.14 = [5 x i8] c"1110\00"
@.str.15 = [5 x i8] c"1111\00"
@.str.16 = [24 x i8] c"\0A Invalid hex digit %c \00"
define i32 @hex2bin(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %7
br label %8
8: ; preds = %82, %2
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 7
br i1 %10, label %11, label %85
11: ; preds = %8
store i32 0, i32* %6
br label %12
12: ; preds = %78, %11
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 16
br i1 %14, label %15, label %81
15: ; preds = %12
%16 = load i8*, i8** %4
%17 = load i32, i32* %6
%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 %70 [
i32 48, label %22
i32 49, label %25
i32 50, label %28
i32 51, label %31
i32 52, label %34
i32 53, label %37
i32 54, label %40
i32 55, label %43
i32 56, label %46
i32 57, label %49
i32 97, label %52
i32 98, label %55
i32 99, label %58
i32 100, label %61
i32 101, label %64
i32 102, label %67
]
22: ; preds = %15
%23 = load i8*, i8** %5
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %77
25: ; preds = %15
%26 = load i8*, i8** %5
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %77
28: ; preds = %15
%29 = load i8*, i8** %5
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %77
31: ; preds = %15
%32 = load i8*, i8** %5
%33 = call i32 @strcat(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %77
34: ; preds = %15
%35 = load i8*, i8** %5
%36 = call i32 @strcat(i8* %35, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %77
37: ; preds = %15
%38 = load i8*, i8** %5
%39 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %77
40: ; preds = %15
%41 = load i8*, i8** %5
%42 = call i32 @strcat(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %77
43: ; preds = %15
%44 = load i8*, i8** %5
%45 = call i32 @strcat(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %77
46: ; preds = %15
%47 = load i8*, i8** %5
%48 = call i32 @strcat(i8* %47, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %77
49: ; preds = %15
%50 = load i8*, i8** %5
%51 = call i32 @strcat(i8* %50, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %77
52: ; preds = %15
%53 = load i8*, i8** %5
%54 = call i32 @strcat(i8* %53, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %77
55: ; preds = %15
%56 = load i8*, i8** %5
%57 = call i32 @strcat(i8* %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %77
58: ; preds = %15
%59 = load i8*, i8** %5
%60 = call i32 @strcat(i8* %59, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
br label %77
61: ; preds = %15
%62 = load i8*, i8** %5
%63 = call i32 @strcat(i8* %62, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
br label %77
64: ; preds = %15
%65 = load i8*, i8** %5
%66 = call i32 @strcat(i8* %65, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
br label %77
67: ; preds = %15
%68 = load i8*, i8** %5
%69 = call i32 @strcat(i8* %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
br label %77
70: ; preds = %15
%71 = load i8*, i8** %4
%72 = load i32, i32* %6
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds i8, i8* %71, i64 %73
%75 = load i8, i8* %74
%76 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.16, i64 0, i64 0), i8 signext %75)
store i32 0, i32* %3
br label %86
77: ; preds = %67, %64, %61, %58, %55, %52, %49, %46, %43, %40, %37, %34, %31, %28, %25, %22
br label %78
78: ; preds = %77
%79 = load i32, i32* %6
%80 = add nsw i32 %79, 1
store i32 %80, i32* %6
br label %12
81: ; preds = %12
br label %82
82: ; preds = %81
%83 = load i32, i32* %7
%84 = add nsw i32 %83, 1
store i32 %84, i32* %7
br label %8
85: ; preds = %8
store i32 1, i32* %3
br label %86
86: ; preds = %85, %70
%87 = load i32, i32* %3
ret i32 %87
}

LLVM IR (-O2):
@.str = [5 x i8] c"0000\00"
@.str.1 = [5 x i8] c"0001\00"
@.str.2 = [5 x i8] c"0010\00"
@.str.3 = [5 x i8] c"0011\00"
@.str.4 = [5 x i8] c"0100\00"
@.str.5 = [5 x i8] c"0101\00"
@.str.6 = [5 x i8] c"0110\00"
@.str.7 = [5 x i8] c"0111\00"
@.str.8 = [5 x i8] c"1000\00"
@.str.9 = [5 x i8] c"1001\00"
@.str.10 = [5 x i8] c"1010\00"
@.str.11 = [5 x i8] c"1011\00"
@.str.12 = [5 x i8] c"1100\00"
@.str.13 = [5 x i8] c"1101\00"
@.str.14 = [5 x i8] c"1110\00"
@.str.15 = [5 x i8] c"1111\00"
@.str.16 = [24 x i8] c"\0A Invalid hex digit %c \00"
define i32 @hex2bin(i8* nocapture %0, i8* %1) {
br label %3
3: ; preds = %2, %32
%4 = phi i32 [ 0, %2 ], [ %33, %32 ]
br label %5
5: ; preds = %3, %27
%6 = phi i64 [ 0, %3 ], [ %30, %27 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
switch i32 %9, label %25 [
i32 48, label %27
i32 49, label %10
i32 50, label %11
i32 51, label %12
i32 52, label %13
i32 53, label %14
i32 54, label %15
i32 55, label %16
i32 56, label %17
i32 57, label %18
i32 97, label %19
i32 98, label %20
i32 99, label %21
i32 100, label %22
i32 101, label %23
i32 102, label %24
]
10: ; preds = %5
br label %27
11: ; preds = %5
br label %27
12: ; preds = %5
br label %27
13: ; preds = %5
br label %27
14: ; preds = %5
br label %27
15: ; preds = %5
br label %27
16: ; preds = %5
br label %27
17: ; preds = %5
br label %27
18: ; preds = %5
br label %27
19: ; preds = %5
br label %27
20: ; preds = %5
br label %27
21: ; preds = %5
br label %27
22: ; preds = %5
br label %27
23: ; preds = %5
br label %27
24: ; preds = %5
br label %27
25: ; preds = %5
%26 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.16, i64 0, i64 0), i8 signext %8)
br label %35
27: ; preds = %5, %10, %11, %12, %13, %14, %15, %16, %17, %18, %19, %20, %21, %22, %23, %24
%28 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %10 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), %11 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %12 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %13 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %14 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), %15 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), %16 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), %17 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), %18 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), %19 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0), %20 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), %21 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0), %22 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), %23 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0), %24 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %5 ]
%29 = tail call i32 @strcat(i8* %1, i8* %28)
%30 = add nuw nsw i64 %6, 1
%31 = icmp eq i64 %30, 16
br i1 %31, label %32, label %5
32: ; preds = %27
%33 = add nuw nsw i32 %4, 1
%34 = icmp eq i32 %33, 7
br i1 %34, label %35, label %3
35: ; preds = %32, %25
%36 = phi i32 [ 0, %25 ], [ 1, %32 ]
ret i32 %36
}