#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_base4(char *hexstr, char *base4str, size_t b4slen) {
  int i = 0;
  memset(base4str, 0, b4slen);
  for (i = 0; i < strlen(hexstr); i++) {
    switch (hexstr[i]) {
    case '0':
      strcat(base4str, "00");
      break;
    case '1':
      strcat(base4str, "01");
      break;
    case '2':
      strcat(base4str, "02");
      break;
    case '3':
      strcat(base4str, "03");
      break;
    case '4':
      strcat(base4str, "10");
      break;
    case '5':
      strcat(base4str, "11");
      break;
    case '6':
      strcat(base4str, "12");
      break;
    case '7':
      strcat(base4str, "13");
      break;
    case '8':
      strcat(base4str, "20");
      break;
    case '9':
      strcat(base4str, "21");
      break;
    case 'a':
      strcat(base4str, "22");
      break;
    case 'b':
      strcat(base4str, "23");
      break;
    case 'c':
      strcat(base4str, "30");
      break;
    case 'd':
      strcat(base4str, "31");
      break;
    case 'e':
      strcat(base4str, "32");
      break;
    case 'f':
      strcat(base4str, "33");
      break;
    default:
      printf("Some wierd number is in the key \n");
      break;
    }
  }
}


x86 assembly (clang, -O0):
<hex_to_base4>:
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_base4+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_base4+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_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xf00(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xeee(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xedc(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xeca(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xeb8(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe94(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe82(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe70(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
mov    -0x10(%rbp),%rdi
lea    0xe04(%rip),%rsi
call   1060 <strcat@plt>
jmp    131b <hex_to_base4+0x1db>
lea    0xdf6(%rip),%rdi
call   1040 <printf@plt>
jmp    1320 <hex_to_base4+0x1e0>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1171 <hex_to_base4+0x31>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hex_to_base4>:
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_base4+0x1ba>
xor    %r12d,%r12d
lea    0xe8b(%rip),%r13
lea    0xf8a(%rip),%rbp
lea    0xf86(%rip),%r15
jmp    11b7 <hex_to_base4+0x77>
lea    0xf80(%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_base4+0x1ba>
movsbl (%rbx,%r12,1),%eax
add    $0xffffffd0,%eax
cmp    $0x36,%eax
ja     1185 <hex_to_base4+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_base4+0x60>
mov    %r14,%rdi
lea    0xef6(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
lea    0xee8(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
lea    0xeda(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
lea    0xecc(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
lea    0xebb(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
lea    0xeaa(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
lea    0xe99(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
lea    0xe88(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
lea    0xe77(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
lea    0xe66(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
lea    0xe55(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
lea    0xe44(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
lea    0xe33(%rip),%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
jmp    11a0 <hex_to_base4+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"00\00"
@.str.1 = [3 x i8] c"01\00"
@.str.2 = [3 x i8] c"02\00"
@.str.3 = [3 x i8] c"03\00"
@.str.4 = [3 x i8] c"10\00"
@.str.5 = [3 x i8] c"11\00"
@.str.6 = [3 x i8] c"12\00"
@.str.7 = [3 x i8] c"13\00"
@.str.8 = [3 x i8] c"20\00"
@.str.9 = [3 x i8] c"21\00"
@.str.10 = [3 x i8] c"22\00"
@.str.11 = [3 x i8] c"23\00"
@.str.12 = [3 x i8] c"30\00"
@.str.13 = [3 x i8] c"31\00"
@.str.14 = [3 x i8] c"32\00"
@.str.15 = [3 x i8] c"33\00"
@.str.16 = [34 x i8] c"Some wierd number is in the key \0A\00"
define void @hex_to_base4(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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 ([3 x i8], [3 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 = [3 x i8] c"00\00"
@.str.1 = [3 x i8] c"01\00"
@.str.2 = [3 x i8] c"02\00"
@.str.3 = [3 x i8] c"03\00"
@.str.4 = [3 x i8] c"10\00"
@.str.5 = [3 x i8] c"11\00"
@.str.6 = [3 x i8] c"12\00"
@.str.7 = [3 x i8] c"13\00"
@.str.8 = [3 x i8] c"20\00"
@.str.9 = [3 x i8] c"21\00"
@.str.10 = [3 x i8] c"22\00"
@.str.11 = [3 x i8] c"23\00"
@.str.12 = [3 x i8] c"30\00"
@.str.13 = [3 x i8] c"31\00"
@.str.14 = [3 x i8] c"32\00"
@.str.15 = [3 x i8] c"33\00"
@str = [33 x i8] c"Some wierd number is in the key \00"
define void @hex_to_base4(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 ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %46
14: ; preds = %7
%15 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %46
16: ; preds = %7
%17 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %46
18: ; preds = %7
%19 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %46
20: ; preds = %7
%21 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
br label %46
22: ; preds = %7
%23 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %46
24: ; preds = %7
%25 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
br label %46
26: ; preds = %7
%27 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
br label %46
28: ; preds = %7
%29 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
br label %46
30: ; preds = %7
%31 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
br label %46
32: ; preds = %7
%33 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0))
br label %46
34: ; preds = %7
%35 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
br label %46
36: ; preds = %7
%37 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
br label %46
38: ; preds = %7
%39 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
br label %46
40: ; preds = %7
%41 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.14, i64 0, i64 0))
br label %46
42: ; preds = %7
%43 = tail call i32 @strcat(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 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
}