#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 */
char *malloc(int);
unsigned int strlen(char const *);
unsigned char *createKey(const char *state, char input) {
  unsigned int stateLen = strlen(state);
  char *key = malloc((3 + stateLen) * sizeof(char));
  for (unsigned int i = 0; i < stateLen; ++i) {
    key[i] = state[i];
  }
  key[stateLen + 0] = ' ';
  key[stateLen + 1] = input;
  key[stateLen + 2] = 0;
  return (unsigned char *)key;
}


x86 assembly (clang, -O0):
<createKey>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x3,%eax
mov    %eax,%eax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jae    118a <createKey+0x6a>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115c <createKey+0x3c>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x0,%ecx
mov    %ecx,%ecx
movb   $0x20,(%rax,%rcx,1)
mov    -0x9(%rbp),%dl
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createKey>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r14d
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    0x3(%rbx),%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
test   %ebx,%ebx
je     1167 <createKey+0x37>
mov    %ebx,%r12d
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <memcpy@plt>
jmp    116a <createKey+0x3a>
xor    %r12d,%r12d
movb   $0x20,0x0(%rbp,%r12,1)
lea    0x1(%rbx),%eax
mov    %r14b,0x0(%rbp,%rax,1)
add    $0x2,%ebx
movb   $0x0,0x0(%rbp,%rbx,1)
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define noalias i8* @createKey(i8* %0, i8 signext %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add i32 %3, 3
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp eq i32 %3, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = zext i32 %3 to i64
br label %9
9: ; preds = %2, %7
%10 = phi i64 [ %8, %7 ], [ 0, %2 ]
%11 = getelementptr inbounds i8, i8* %5, i64 %10
store i8 32, i8* %11
%12 = add i32 %3, 1
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %5, i64 %13
store i8 %1, i8* %14
%15 = add i32 %3, 2
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %5, i64 %16
store i8 0, i8* %17
ret i8* %5
}