#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);
int rand();
char *generate_key(int length) {
  char *key = malloc(sizeof(char) * length);
  int i;
  for (i = 0; i < length; i++) {
    if ((rand() % (10) + 1) == 3 || (rand() % (10) + 1) == 6) {
      key[i] = ' ';
    } else {
      key[i] = (rand() % (90 + 1 - 65) + 65);
    }
  }
  key[i] = '\0';
  return key;
}


x86 assembly (clang, -O0):
<generate_key>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c8 <generate_key+0xa8>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
cmp    $0x3,%edx
je     1187 <generate_key+0x67>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
cmp    $0x6,%edx
jne    1198 <generate_key+0x78>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
jmp    11b5 <generate_key+0x95>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    11ba <generate_key+0x9a>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1145 <generate_key+0x25>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_key>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
call   1030 <malloc@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    11d5 <generate_key+0xb5>
mov    %ebp,%r14d
xor    %ebp,%ebp
jmp    1151 <generate_key+0x31>
mov    %bl,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%r14
je     11d8 <generate_key+0xb8>
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
mov    $0x20,%bl
cmp    $0x2,%eax
je     1140 <generate_key+0x20>
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
cmp    $0x5,%eax
je     1140 <generate_key+0x20>
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%rbx
imul   $0x4ec4ec4f,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
shr    $0x23,%rax
add    %ecx,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rcx,%rcx,4),%ecx
add    %eax,%ecx
sub    %ecx,%ebx
add    $0x41,%bl
jmp    1140 <generate_key+0x20>
xor    %r14d,%r14d
movb   $0x0,(%r15,%r14,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define noalias i8* @generate_key(i32 %0) {
%2 = tail call i8* @malloc(i32 %0)
%3 = icmp sgt i32 %0, 0
br i1 %3, label %4, label %27
4: ; preds = %1
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %20
%7 = phi i64 [ 0, %4 ], [ %23, %20 ]
%8 = tail call i32 (...) @rand()
%9 = srem i32 %8, 10
%10 = icmp eq i32 %9, 2
br i1 %10, label %20, label %11
11: ; preds = %6
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, 10
%14 = icmp eq i32 %13, 5
br i1 %14, label %20, label %15
15: ; preds = %11
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, 26
%18 = trunc i32 %17 to i8
%19 = add nsw i8 %18, 65
br label %20
20: ; preds = %6, %11, %15
%21 = phi i8 [ %19, %15 ], [ 32, %11 ], [ 32, %6 ]
%22 = getelementptr inbounds i8, i8* %2, i64 %7
store i8 %21, i8* %22
%23 = add nuw nsw i64 %7, 1
%24 = icmp eq i64 %23, %5
br i1 %24, label %25, label %6
25: ; preds = %20
%26 = zext i32 %0 to i64
br label %27
27: ; preds = %1, %25
%28 = phi i64 [ %26, %25 ], [ 0, %1 ]
%29 = getelementptr inbounds i8, i8* %2, i64 %28
store i8 0, i8* %29
ret i8* %2
}