char *fix_key(char *str) {
  static char key[9];
  int n;
  if (!str)
    str = "";
  for (n = 0; *str && n < 8; ++n)
    key[n] = *str++;
  while (n < 8)
    key[n++] = ' ';
  key[8] = '\0';
  return key;
}


x86 assembly (clang, -O0):
<fix_key>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    111e <fix_key+0x1e>
lea    0xee6(%rip),%rax
mov    %rax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd(%rbp)
je     1144 <fix_key+0x44>
cmpl   $0x8,-0xc(%rbp)
setl   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    1154 <fix_key+0x54>
jmp    1181 <fix_key+0x81>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%dl
movslq -0xc(%rbp),%rcx
lea    0x2eb1(%rip),%rax
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1125 <fix_key+0x25>
jmp    1186 <fix_key+0x86>
cmpl   $0x8,-0xc(%rbp)
jge    11ae <fix_key+0xae>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0xc(%rbp)
movslq %eax,%rcx
lea    0x2e7c(%rip),%rax
movb   $0x20,(%rax,%rcx,1)
jmp    1186 <fix_key+0x86>
movb   $0x0,0x2e74(%rip)
lea    0x2e65(%rip),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<fix_key>:
push   %rax
test   %rdi,%rdi
lea    0xee5(%rip),%rcx
cmovne %rdi,%rcx
mov    (%rcx),%al
test   %al,%al
je     1191 <fix_key+0x81>
mov    %al,0x2efe(%rip)
mov    0x1(%rcx),%dl
mov    $0x1,%al
test   %dl,%dl
je     1195 <fix_key+0x85>
mov    %dl,0x2ef0(%rip)
mov    0x2(%rcx),%dl
test   %dl,%dl
je     119c <fix_key+0x8c>
mov    %dl,0x2ee4(%rip)
mov    0x3(%rcx),%dl
test   %dl,%dl
je     11a3 <fix_key+0x93>
mov    %dl,0x2ed8(%rip)
mov    0x4(%rcx),%dl
test   %dl,%dl
je     11aa <fix_key+0x9a>
mov    %dl,0x2ecc(%rip)
mov    0x5(%rcx),%dl
test   %dl,%dl
je     11b1 <fix_key+0xa1>
mov    %dl,0x2ec0(%rip)
mov    0x6(%rcx),%dl
test   %dl,%dl
je     11b8 <fix_key+0xa8>
mov    %dl,0x2eb4(%rip)
mov    0x7(%rcx),%cl
test   %cl,%cl
je     11bf <fix_key+0xaf>
mov    %cl,0x2ea8(%rip)
mov    $0x8,%ecx
xor    %eax,%eax
jmp    11c4 <fix_key+0xb4>
xor    %ecx,%ecx
jmp    11c8 <fix_key+0xb8>
mov    $0x1,%ecx
jmp    11c4 <fix_key+0xb4>
mov    $0x2,%ecx
jmp    11c4 <fix_key+0xb4>
mov    $0x3,%ecx
jmp    11c4 <fix_key+0xb4>
mov    $0x4,%ecx
jmp    11c4 <fix_key+0xb4>
mov    $0x5,%ecx
jmp    11c4 <fix_key+0xb4>
mov    $0x6,%ecx
jmp    11c4 <fix_key+0xb4>
mov    $0x7,%ecx
test   %al,%al
je     11e9 <fix_key+0xd9>
mov    %ecx,%eax
lea    0x2e58(%rip),%rdi
add    %rax,%rdi
mov    $0x7,%edx
sub    %ecx,%edx
add    $0x1,%rdx
mov    $0x20,%esi
call   1030 <memset@plt>
movb   $0x0,0x2e41(%rip)
lea    0x2e32(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
@fix_key.key = internal global [9 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
define i8* @fix_key(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %2
br label %7
7: ; preds = %6, %1
store i32 0, i32* %3
br label %8
8: ; preds = %25, %7
%9 = load i8*, i8** %2
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 8
br label %16
16: ; preds = %13, %8
%17 = phi i1 [ false, %8 ], [ %15, %13 ]
br i1 %17, label %18, label %28
18: ; preds = %16
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %2
%21 = load i8, i8* %19
%22 = load i32, i32* %3
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 %23
store i8 %21, i8* %24
br label %25
25: ; preds = %18
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %8
28: ; preds = %16
br label %29
29: ; preds = %32, %28
%30 = load i32, i32* %3
%31 = icmp slt i32 %30, 8
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
store i32 %34, i32* %3
%35 = sext i32 %33 to i64
%36 = getelementptr inbounds [9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 %35
store i8 32, i8* %36
br label %29
37: ; preds = %29
store i8 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 8)
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 0)
}

LLVM IR (-O2):
@fix_key.key = internal global [9 x i8] zeroinitializer
@.str = [1 x i8] zeroinitializer
define i8* @fix_key(i8* %0) {
%2 = icmp eq i8* %0, null
%3 = select i1 %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8* %0
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 0
br i1 %5, label %9, label %16
6: ; preds = %44, %40, %36, %32, %28, %24, %20, %16
%7 = phi i1 [ false, %44 ], [ true, %40 ], [ true, %36 ], [ true, %32 ], [ true, %28 ], [ true, %24 ], [ true, %20 ], [ true, %16 ]
%8 = phi i32 [ 8, %44 ], [ 7, %40 ], [ 6, %36 ], [ 5, %32 ], [ 4, %28 ], [ 3, %24 ], [ 2, %20 ], [ 1, %16 ]
br i1 %7, label %9, label %45
9: ; preds = %1, %6
%10 = phi i32 [ %8, %6 ], [ 0, %1 ]
%11 = zext i32 %10 to i64
%12 = getelementptr [9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 %11
%13 = sub nuw nsw i32 7, %10
%14 = zext i32 %13 to i64
%15 = add nuw nsw i64 %14, 1
br label %45
16: ; preds = %1
%17 = getelementptr inbounds i8, i8* %3, i64 1
store i8 %4, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 0)
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %6, label %20
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %3, i64 2
store i8 %18, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 1)
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
br i1 %23, label %6, label %24
24: ; preds = %20
%25 = getelementptr inbounds i8, i8* %3, i64 3
store i8 %22, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 2)
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %6, label %28
28: ; preds = %24
%29 = getelementptr inbounds i8, i8* %3, i64 4
store i8 %26, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 3)
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
br i1 %31, label %6, label %32
32: ; preds = %28
%33 = getelementptr inbounds i8, i8* %3, i64 5
store i8 %30, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 4)
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
br i1 %35, label %6, label %36
36: ; preds = %32
%37 = getelementptr inbounds i8, i8* %3, i64 6
store i8 %34, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 5)
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 0
br i1 %39, label %6, label %40
40: ; preds = %36
%41 = getelementptr inbounds i8, i8* %3, i64 7
store i8 %38, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 6)
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 0
br i1 %43, label %6, label %44
44: ; preds = %40
store i8 %42, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 7)
br label %6
45: ; preds = %9, %6
store i8 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 8)
ret i8* getelementptr inbounds ([9 x i8], [9 x i8]* @fix_key.key, i64 0, i64 0)
}