#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 */
typedef int /*<<< orphan*/ binstr;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
void hex_to_base2(char *hexstr, char *binstr) {
  int i = 0;
  memset(binstr, 0, sizeof(binstr));
  for (i = 0; i < strlen(hexstr); i++) {
    switch (hexstr[i]) {
    case '0':
      strcat(binstr, "0000");
      break;
    case '1':
      strcat(binstr, "0001");
      break;
    case '2':
      strcat(binstr, "0010");
      break;
    case '3':
      strcat(binstr, "0011");
      break;
    case '4':
      strcat(binstr, "0100");
      break;
    case '5':
      strcat(binstr, "0101");
      break;
    case '6':
      strcat(binstr, "0110");
      break;
    case '7':
      strcat(binstr, "0111");
      break;
    case '8':
      strcat(binstr, "1000");
      break;
    case '9':
      strcat(binstr, "1001");
      break;
    case 'a':
      strcat(binstr, "1010");
      break;
    case 'b':
      strcat(binstr, "1011");
      break;
    case 'c':
      strcat(binstr, "1100");
      break;
    case 'd':
      strcat(binstr, "1101");
      break;
    case 'e':
      strcat(binstr, "1110");
      break;
    case 'f':
      strcat(binstr, "1111");
      break;
    default:
      printf("Some wierd number is in the key \n");
      break;
    }
  }
}


x86 assembly (clang, -O0):
<hex_to_base2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    132b <hex_to_base2+0x1eb>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x36,%eax
ja     130c <hex_to_base2+0x1cc>
mov    -0x20(%rbp),%rax
lea    0xe4d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xf15(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xf05(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xef5(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xee5(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xed5(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xec5(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xe45(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xe35(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
mov    -0x10(%rbp),%rdi
lea    0xe25(%rip),%rsi
call   1060 <strcat@plt>
jmp    1318 <hex_to_base2+0x1d8>
lea    0xe19(%rip),%rdi
call   1040 <printf@plt>
jmp    131d <hex_to_base2+0x1dd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116e <hex_to_base2+0x2e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_to_base2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    12fa <hex_to_base2+0x1ba>
xor    %r12d,%r12d
lea    0xe86(%rip),%r13
lea    0xfa1(%rip),%rbp
lea    0xf9f(%rip),%r15
jmp    11b7 <hex_to_base2+0x77>
lea    0xf9b(%rip),%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r12
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%r12
jge    12fa <hex_to_base2+0x1ba>
movsbl (%rbx,%r12,1),%eax
add    $0xffffffd0,%eax
cmp    $0x36,%eax
ja     118a <hex_to_base2+0x4a>
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    %r14,%rdi
lea    0xf04(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
lea    0xef8(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
lea    0xeec(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
lea    0xee0(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
lea    0xed4(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
lea    0xec5(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
lea    0xeb6(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
lea    0xea7(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
lea    0xe98(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
lea    0xe89(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
lea    0xe7a(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
lea    0xe6b(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
lea    0xe5c(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
lea    0xe4d(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base2+0x60>
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 = [34 x i8] c"Some wierd number is in the key \0A\00"
define void @hex_to_base2(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%6 = load i8*, i8** %4
%7 = call i32 @memset(i8* %6, i32 0, i32 8)
store i32 0, i32* %5
br label %8
8: ; preds = %71, %2
%9 = load i32, i32* %5
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %74
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = load i32, i32* %5
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
switch i32 %19, label %68 [
i32 48, label %20
i32 49, label %23
i32 50, label %26
i32 51, label %29
i32 52, label %32
i32 53, label %35
i32 54, label %38
i32 55, label %41
i32 56, label %44
i32 57, label %47
i32 97, label %50
i32 98, label %53
i32 99, label %56
i32 100, label %59
i32 101, label %62
i32 102, label %65
]
20: ; preds = %13
%21 = load i8*, i8** %4
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %70
23: ; preds = %13
%24 = load i8*, i8** %4
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %70
26: ; preds = %13
%27 = load i8*, i8** %4
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %70
29: ; preds = %13
%30 = load i8*, i8** %4
%31 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %70
32: ; preds = %13
%33 = load i8*, i8** %4
%34 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %70
35: ; preds = %13
%36 = load i8*, i8** %4
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %70
38: ; preds = %13
%39 = load i8*, i8** %4
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %70
41: ; preds = %13
%42 = load i8*, i8** %4
%43 = call i32 @strcat(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %70
44: ; preds = %13
%45 = load i8*, i8** %4
%46 = call i32 @strcat(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %70
47: ; preds = %13
%48 = load i8*, i8** %4
%49 = call i32 @strcat(i8* %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %70
50: ; preds = %13
%51 = load i8*, i8** %4
%52 = call i32 @strcat(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %70
53: ; preds = %13
%54 = load i8*, i8** %4
%55 = call i32 @strcat(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %70
56: ; preds = %13
%57 = load i8*, i8** %4
%58 = call i32 @strcat(i8* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
br label %70
59: ; preds = %13
%60 = load i8*, i8** %4
%61 = call i32 @strcat(i8* %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
br label %70
62: ; preds = %13
%63 = load i8*, i8** %4
%64 = call i32 @strcat(i8* %63, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
br label %70
65: ; preds = %13
%66 = load i8*, i8** %4
%67 = call i32 @strcat(i8* %66, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
br label %70
68: ; preds = %13
%69 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.16, i64 0, i64 0))
br label %70
70: ; preds = %68, %65, %62, %59, %56, %53, %50, %47, %44, %41, %38, %35, %32, %29, %26, %23, %20
br label %71
71: ; preds = %70
%72 = load i32, i32* %5
%73 = add nsw i32 %72, 1
store i32 %73, i32* %5
br label %8
74: ; preds = %8
ret void
}

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 = [33 x i8] c"Some wierd number is in the key \00"
define void @hex_to_base2(i8* %0, i8* %1) {
%3 = tail call i32 @memset(i8* %1, i32 0, i32 8)
%4 = tail call i32 @strlen(i8* %0)
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %50
6: ; preds = %2, %45
%7 = phi i64 [ %46, %45 ], [ 0, %2 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
switch i32 %10, label %43 [
i32 48, label %11
i32 49, label %13
i32 50, label %15
i32 51, label %17
i32 52, label %19
i32 53, label %21
i32 54, label %23
i32 55, label %25
i32 56, label %27
i32 57, label %29
i32 97, label %31
i32 98, label %33
i32 99, label %35
i32 100, label %37
i32 101, label %39
i32 102, label %41
]
11: ; preds = %6
%12 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %45
13: ; preds = %6
%14 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %45
15: ; preds = %6
%16 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %45
17: ; preds = %6
%18 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %45
19: ; preds = %6
%20 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %45
21: ; preds = %6
%22 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %45
23: ; preds = %6
%24 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %45
25: ; preds = %6
%26 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %45
27: ; preds = %6
%28 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %45
29: ; preds = %6
%30 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %45
31: ; preds = %6
%32 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %45
33: ; preds = %6
%34 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %45
35: ; preds = %6
%36 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
br label %45
37: ; preds = %6
%38 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
br label %45
39: ; preds = %6
%40 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
br label %45
41: ; preds = %6
%42 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
br label %45
43: ; preds = %6
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %45
45: ; preds = %11, %13, %15, %17, %19, %21, %23, %25, %27, %29, %31, %33, %35, %37, %39, %41, %43
%46 = add nuw nsw i64 %7, 1
%47 = tail call i32 @strlen(i8* %0)
%48 = sext i32 %47 to i64
%49 = icmp slt i64 %46, %48
br i1 %49, label %6, label %50
50: ; preds = %45, %2
ret void
}