#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*/ free(char *);
int get_int_from_hex(char);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sBox_converter(char *, char, int, int);
void convert_key_to_bits(char *input, char *output) {
  char *out = (char *)malloc(sizeof(char) * 8);
  int i;
  int ivals[8];
  for (i = 0; i < 8; i++)
    ivals[i] = get_int_from_hex(input[i]);
  for (i = 0; i < 8; i++) {
    printf("test\n");
    sBox_converter(out, (char)ivals[i], 32, 8);
    int j;
    for (j = 0; j < 8; j++)
      output[j + (8 * i)] = out[j];
  }
  free(out);
}


x86 assembly (clang, -O0):
<convert_key_to_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    11a8 <convert_key_to_bits+0x58>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1070 <get_int_from_hex@plt>
mov    %eax,%ecx
movslq -0x1c(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1175 <convert_key_to_bits+0x25>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8,-0x1c(%rbp)
jge    1235 <convert_key_to_bits+0xe5>
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
movslq -0x1c(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%eax
mov    $0x20,%edx
mov    $0x8,%ecx
movsbl %al,%esi
call   1060 <sBox_converter@plt>
movl   $0x0,-0x44(%rbp)
cmpl   $0x8,-0x44(%rbp)
jge    1222 <convert_key_to_bits+0xd2>
mov    -0x18(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
mov    -0x44(%rbp),%ecx
mov    -0x1c(%rbp),%esi
shl    $0x3,%esi
add    %esi,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11ea <convert_key_to_bits+0x9a>
jmp    1227 <convert_key_to_bits+0xd7>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11af <convert_key_to_bits+0x5f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_key_to_bits>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%r12
movsbl (%r15),%edi
call   1070 <get_int_from_hex@plt>
mov    %eax,(%rsp)
movsbl 0x1(%r15),%edi
call   1070 <get_int_from_hex@plt>
mov    %eax,0x4(%rsp)
movsbl 0x2(%r15),%edi
call   1070 <get_int_from_hex@plt>
mov    %eax,0x8(%rsp)
movsbl 0x3(%r15),%edi
call   1070 <get_int_from_hex@plt>
mov    %eax,0xc(%rsp)
movsbl 0x4(%r15),%edi
call   1070 <get_int_from_hex@plt>
mov    %eax,0x10(%rsp)
movsbl 0x5(%r15),%edi
call   1070 <get_int_from_hex@plt>
mov    %eax,0x14(%rsp)
movsbl 0x6(%r15),%edi
call   1070 <get_int_from_hex@plt>
mov    %eax,0x18(%rsp)
movsbl 0x7(%r15),%edi
call   1070 <get_int_from_hex@plt>
mov    %eax,0x1c(%rsp)
xor    %ebx,%ebx
lea    0xe1b(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1040 <puts@plt>
movsbl (%rsp,%rbx,4),%esi
mov    %r12,%rdi
mov    $0x20,%edx
mov    $0x8,%ecx
call   1060 <sBox_converter@plt>
movzbl (%r12),%eax
mov    %al,(%r14,%rbx,8)
movzbl 0x1(%r12),%eax
mov    %al,0x1(%r14,%rbx,8)
movzbl 0x2(%r12),%eax
mov    %al,0x2(%r14,%rbx,8)
movzbl 0x3(%r12),%eax
mov    %al,0x3(%r14,%rbx,8)
movzbl 0x4(%r12),%eax
mov    %al,0x4(%r14,%rbx,8)
movzbl 0x5(%r12),%eax
mov    %al,0x5(%r14,%rbx,8)
movzbl 0x6(%r12),%eax
mov    %al,0x6(%r14,%rbx,8)
movzbl 0x7(%r12),%eax
mov    %al,0x7(%r14,%rbx,8)
add    $0x1,%rbx
cmp    $0x8,%rbx
jne    11f0 <convert_key_to_bits+0xa0>
mov    %r12,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"test\0A\00"
define void @convert_key_to_bits(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [8 x i32]
%8 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = call i64 @malloc(i32 8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %5
store i32 0, i32* %6
br label %11
11: ; preds = %24, %2
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 8
br i1 %13, label %14, label %27
14: ; preds = %11
%15 = load i8*, i8** %3
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @get_int_from_hex(i8 signext %19)
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [8 x i32], [8 x i32]* %7, i64 0, i64 %22
store i32 %20, i32* %23
br label %24
24: ; preds = %14
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %11
27: ; preds = %11
store i32 0, i32* %6
br label %28
28: ; preds = %60, %27
%29 = load i32, i32* %6
%30 = icmp slt i32 %29, 8
br i1 %30, label %31, label %63
31: ; preds = %28
%32 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%33 = load i8*, i8** %5
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [8 x i32], [8 x i32]* %7, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = trunc i32 %37 to i8
%39 = call i32 @sBox_converter(i8* %33, i8 signext %38, i32 32, i32 8)
store i32 0, i32* %8
br label %40
40: ; preds = %56, %31
%41 = load i32, i32* %8
%42 = icmp slt i32 %41, 8
br i1 %42, label %43, label %59
43: ; preds = %40
%44 = load i8*, i8** %5
%45 = load i32, i32* %8
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
%48 = load i8, i8* %47
%49 = load i8*, i8** %4
%50 = load i32, i32* %8
%51 = load i32, i32* %6
%52 = mul nsw i32 8, %51
%53 = add nsw i32 %50, %52
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %49, i64 %54
store i8 %48, i8* %55
br label %56
56: ; preds = %43
%57 = load i32, i32* %8
%58 = add nsw i32 %57, 1
store i32 %58, i32* %8
br label %40
59: ; preds = %40
br label %60
60: ; preds = %59
%61 = load i32, i32* %6
%62 = add nsw i32 %61, 1
store i32 %62, i32* %6
br label %28
63: ; preds = %28
%64 = load i8*, i8** %5
%65 = call i32 @free(i8* %64)
ret void
}

LLVM IR (-O2):
@str = [5 x i8] c"test\00"
define void @convert_key_to_bits(i8* nocapture %0, i8* nocapture writeonly %1) {
%3 = alloca [8 x i32]
%4 = tail call i64 @malloc(i32 8)
%5 = bitcast [8 x i32]* %3 to i8*
%6 = load i8, i8* %0
%7 = tail call i32 @get_int_from_hex(i8 signext %6)
%8 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 0
store i32 %7, i32* %8
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = load i8, i8* %9
%11 = tail call i32 @get_int_from_hex(i8 signext %10)
%12 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 1
store i32 %11, i32* %12
%13 = getelementptr inbounds i8, i8* %0, i64 2
%14 = load i8, i8* %13
%15 = tail call i32 @get_int_from_hex(i8 signext %14)
%16 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 2
store i32 %15, i32* %16
%17 = getelementptr inbounds i8, i8* %0, i64 3
%18 = load i8, i8* %17
%19 = tail call i32 @get_int_from_hex(i8 signext %18)
%20 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 3
store i32 %19, i32* %20
%21 = getelementptr inbounds i8, i8* %0, i64 4
%22 = load i8, i8* %21
%23 = tail call i32 @get_int_from_hex(i8 signext %22)
%24 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 4
store i32 %23, i32* %24
%25 = getelementptr inbounds i8, i8* %0, i64 5
%26 = load i8, i8* %25
%27 = tail call i32 @get_int_from_hex(i8 signext %26)
%28 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 5
store i32 %27, i32* %28
%29 = getelementptr inbounds i8, i8* %0, i64 6
%30 = load i8, i8* %29
%31 = tail call i32 @get_int_from_hex(i8 signext %30)
%32 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 6
store i32 %31, i32* %32
%33 = getelementptr inbounds i8, i8* %0, i64 7
%34 = load i8, i8* %33
%35 = tail call i32 @get_int_from_hex(i8 signext %34)
%36 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 7
store i32 %35, i32* %36
%37 = inttoptr i64 %4 to i8*
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = getelementptr inbounds i8, i8* %37, i64 2
%40 = getelementptr inbounds i8, i8* %37, i64 3
%41 = getelementptr inbounds i8, i8* %37, i64 4
%42 = getelementptr inbounds i8, i8* %37, i64 5
%43 = getelementptr inbounds i8, i8* %37, i64 6
%44 = getelementptr inbounds i8, i8* %37, i64 7
br label %45
45: ; preds = %2, %45
%46 = phi i64 [ 0, %2 ], [ %76, %45 ]
%47 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%48 = getelementptr inbounds [8 x i32], [8 x i32]* %3, i64 0, i64 %46
%49 = load i32, i32* %48
%50 = trunc i32 %49 to i8
%51 = tail call i32 @sBox_converter(i8* %37, i8 signext %50, i32 32, i32 8)
%52 = shl nsw i64 %46, 3
%53 = load i8, i8* %37
%54 = getelementptr inbounds i8, i8* %1, i64 %52
store i8 %53, i8* %54
%55 = load i8, i8* %38
%56 = or i64 %52, 1
%57 = getelementptr inbounds i8, i8* %1, i64 %56
store i8 %55, i8* %57
%58 = load i8, i8* %39
%59 = or i64 %52, 2
%60 = getelementptr inbounds i8, i8* %1, i64 %59
store i8 %58, i8* %60
%61 = load i8, i8* %40
%62 = or i64 %52, 3
%63 = getelementptr inbounds i8, i8* %1, i64 %62
store i8 %61, i8* %63
%64 = load i8, i8* %41
%65 = or i64 %52, 4
%66 = getelementptr inbounds i8, i8* %1, i64 %65
store i8 %64, i8* %66
%67 = load i8, i8* %42
%68 = or i64 %52, 5
%69 = getelementptr inbounds i8, i8* %1, i64 %68
store i8 %67, i8* %69
%70 = load i8, i8* %43
%71 = or i64 %52, 6
%72 = getelementptr inbounds i8, i8* %1, i64 %71
store i8 %70, i8* %72
%73 = load i8, i8* %44
%74 = or i64 %52, 7
%75 = getelementptr inbounds i8, i8* %1, i64 %74
store i8 %73, i8* %75
%76 = add nuw nsw i64 %46, 1
%77 = icmp eq i64 %76, 8
br i1 %77, label %78, label %45
78: ; preds = %45
%79 = tail call i32 @free(i8* %37)
ret void
}