#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
unsigned char *translate_char_to_binary_string(unsigned char);
unsigned char *generate_binary_key_string(unsigned char *key) {
  int key_size = strlen((char *)key);
  int binary_key_string_size;
  unsigned char *binary_key_string =
      (unsigned char *)malloc(key_size * 8 * sizeof(char) + 1);
  unsigned char *binary_char_string;
  for (int i = 0; i < key_size; i++) {
    binary_char_string = translate_char_to_binary_string(key[i]);
    if (i == 0) {
      strcpy((char *)binary_key_string, (char *)binary_char_string);
    } else {
      strncat((char *)binary_key_string, (char *)binary_char_string, 8);
    }
  }
  binary_key_string_size = strlen((char *)binary_key_string);
  binary_key_string[binary_key_string_size] = '\0';
  return binary_key_string;
}


x86 assembly (clang, -O0):
<generate_binary_key_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11ec <generate_binary_key_string+0x9c>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1060 <translate_char_to_binary_string@plt>
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11c7 <generate_binary_key_string+0x77>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    11d9 <generate_binary_key_string+0x89>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x8,%edx
call   1050 <strncat@plt>
jmp    11de <generate_binary_key_string+0x8e>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118a <generate_binary_key_string+0x3a>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_binary_key_string>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    0x1(,%r15,8),%edi
call   1070 <malloc@plt>
mov    %rax,%r12
test   %r15d,%r15d
jle    11c3 <generate_binary_key_string+0x73>
movzbl (%r14),%edi
call   1060 <translate_char_to_binary_string@plt>
mov    %r12,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
cmp    $0x1,%r15d
je     11c3 <generate_binary_key_string+0x73>
mov    %r15d,%r15d
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%edi
call   1060 <translate_char_to_binary_string@plt>
mov    %r12,%rdi
mov    %rax,%rsi
mov    $0x8,%edx
call   1050 <strncat@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11a0 <generate_binary_key_string+0x50>
mov    %r12,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @generate_binary_key_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32 @strlen(i8* %8)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = mul nsw i32 %10, 8
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 1
%14 = add i64 %13, 1
%15 = trunc i64 %14 to i32
%16 = call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %5
store i32 0, i32* %7
br label %18
18: ; preds = %40, %1
%19 = load i32, i32* %7
%20 = load i32, i32* %3
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %43
22: ; preds = %18
%23 = load i8*, i8** %2
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
%27 = load i8, i8* %26
%28 = call i8* @translate_char_to_binary_string(i8 zeroext %27)
store i8* %28, i8** %6
%29 = load i32, i32* %7
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %22
%32 = load i8*, i8** %5
%33 = load i8*, i8** %6
%34 = call i32 @strcpy(i8* %32, i8* %33)
br label %39
35: ; preds = %22
%36 = load i8*, i8** %5
%37 = load i8*, i8** %6
%38 = call i32 @strncat(i8* %36, i8* %37, i32 8)
br label %39
39: ; preds = %35, %31
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %18
43: ; preds = %18
%44 = load i8*, i8** %5
%45 = call i32 @strlen(i8* %44)
store i32 %45, i32* %4
%46 = load i8*, i8** %5
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
%50 = load i8*, i8** %5
ret i8* %50
}

LLVM IR (-O2):
define i8* @generate_binary_key_string(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = shl nsw i32 %2, 3
%4 = or i32 %3, 1
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = zext i32 %2 to i64
%10 = load i8, i8* %0
%11 = tail call i8* @translate_char_to_binary_string(i8 zeroext %10)
%12 = tail call i32 @strcpy(i8* %6, i8* %11)
%13 = icmp eq i32 %2, 1
br i1 %13, label %14, label %18
14: ; preds = %18, %8, %1
%15 = tail call i32 @strlen(i8* %6)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %6, i64 %16
store i8 0, i8* %17
ret i8* %6
18: ; preds = %8, %18
%19 = phi i64 [ %24, %18 ], [ 1, %8 ]
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = tail call i8* @translate_char_to_binary_string(i8 zeroext %21)
%23 = tail call i32 @strncat(i8* %6, i8* %22, i32 8)
%24 = add nuw nsw i64 %19, 1
%25 = icmp eq i64 %24, %9
br i1 %25, label %14, label %18
}