#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*/ memset(char *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
void hex_to_base2(char *hexstr, char *binstr, size_t b2slen) {
  int i = 0;
  memset(binstr, 0, b2slen);
  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    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    132e <hex_to_base2+0x1ee>
mov    -0x8(%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     130f <hex_to_base2+0x1cf>
mov    -0x28(%rbp),%rax
lea    0xe4a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
lea    0xf12(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xf02(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xef2(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xee2(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xed2(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xec2(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xeb2(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe52(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe32(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base2+0x1db>
lea    0xe16(%rip),%rdi
call   1040 <printf@plt>
jmp    1320 <hex_to_base2+0x1e0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1171 <hex_to_base2+0x31>
add    $0x30,%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
call   1050 <memset@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    12fa <hex_to_base2+0x1ba>
xor    %r12d,%r12d
lea    0xe8b(%rip),%r13
lea    0xfa6(%rip),%rbp
lea    0xfa4(%rip),%r15
jmp    11b7 <hex_to_base2+0x77>
lea    0xfa0(%rip),%rdi
call   1030 <puts@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   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     1185 <hex_to_base2+0x45>
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, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i32 0, i32* %7
%8 = load i8*, i8** %5
%9 = load i64, i64* %6
%10 = call i32 @memset(i8* %8, i32 0, i64 %9)
store i32 0, i32* %7
br label %11
11: ; preds = %74, %3
%12 = load i32, i32* %7
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %77
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = load i32, i32* %7
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
switch i32 %22, label %71 [
i32 48, label %23
i32 49, label %26
i32 50, label %29
i32 51, label %32
i32 52, label %35
i32 53, label %38
i32 54, label %41
i32 55, label %44
i32 56, label %47
i32 57, label %50
i32 97, label %53
i32 98, label %56
i32 99, label %59
i32 100, label %62
i32 101, label %65
i32 102, label %68
]
23: ; preds = %16
%24 = load i8*, i8** %5
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %73
26: ; preds = %16
%27 = load i8*, i8** %5
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %73
29: ; preds = %16
%30 = load i8*, i8** %5
%31 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %73
32: ; preds = %16
%33 = load i8*, i8** %5
%34 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %73
35: ; preds = %16
%36 = load i8*, i8** %5
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %73
38: ; preds = %16
%39 = load i8*, i8** %5
%40 = call i32 @strcat(i8* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %73
41: ; preds = %16
%42 = load i8*, i8** %5
%43 = call i32 @strcat(i8* %42, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %73
44: ; preds = %16
%45 = load i8*, i8** %5
%46 = call i32 @strcat(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %73
47: ; preds = %16
%48 = load i8*, i8** %5
%49 = call i32 @strcat(i8* %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %73
50: ; preds = %16
%51 = load i8*, i8** %5
%52 = call i32 @strcat(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %73
53: ; preds = %16
%54 = load i8*, i8** %5
%55 = call i32 @strcat(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %73
56: ; preds = %16
%57 = load i8*, i8** %5
%58 = call i32 @strcat(i8* %57, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %73
59: ; preds = %16
%60 = load i8*, i8** %5
%61 = call i32 @strcat(i8* %60, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
br label %73
62: ; preds = %16
%63 = load i8*, i8** %5
%64 = call i32 @strcat(i8* %63, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
br label %73
65: ; preds = %16
%66 = load i8*, i8** %5
%67 = call i32 @strcat(i8* %66, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
br label %73
68: ; preds = %16
%69 = load i8*, i8** %5
%70 = call i32 @strcat(i8* %69, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
br label %73
71: ; preds = %16
%72 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.16, i64 0, i64 0))
br label %73
73: ; preds = %71, %68, %65, %62, %59, %56, %53, %50, %47, %44, %41, %38, %35, %32, %29, %26, %23
br label %74
74: ; preds = %73
%75 = load i32, i32* %7
%76 = add nsw i32 %75, 1
store i32 %76, i32* %7
br label %11
77: ; preds = %11
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, i64 %2) {
%4 = tail call i32 @memset(i8* %1, i32 0, i64 %2)
%5 = tail call i32 @strlen(i8* %0)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %51
7: ; preds = %3, %46
%8 = phi i64 [ %47, %46 ], [ 0, %3 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
switch i32 %11, label %44 [
i32 48, label %12
i32 49, label %14
i32 50, label %16
i32 51, label %18
i32 52, label %20
i32 53, label %22
i32 54, label %24
i32 55, label %26
i32 56, label %28
i32 57, label %30
i32 97, label %32
i32 98, label %34
i32 99, label %36
i32 100, label %38
i32 101, label %40
i32 102, label %42
]
12: ; preds = %7
%13 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %46
14: ; preds = %7
%15 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %46
16: ; preds = %7
%17 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %46
18: ; preds = %7
%19 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %46
20: ; preds = %7
%21 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %46
22: ; preds = %7
%23 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %46
24: ; preds = %7
%25 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %46
26: ; preds = %7
%27 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %46
28: ; preds = %7
%29 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
br label %46
30: ; preds = %7
%31 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %46
32: ; preds = %7
%33 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %46
34: ; preds = %7
%35 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %46
36: ; preds = %7
%37 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
br label %46
38: ; preds = %7
%39 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
br label %46
40: ; preds = %7
%41 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0))
br label %46
42: ; preds = %7
%43 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
br label %46
44: ; preds = %7
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
br label %46
46: ; preds = %12, %14, %16, %18, %20, %22, %24, %26, %28, %30, %32, %34, %36, %38, %40, %42, %44
%47 = add nuw nsw i64 %8, 1
%48 = tail call i32 @strlen(i8* %0)
%49 = sext i32 %48 to i64
%50 = icmp slt i64 %47, %49
br i1 %50, label %7, label %51
51: ; preds = %46, %3
ret void
}