#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 rand();
void keyGen(unsigned char *key) {
  int i;
  for (i = 0; i < 8; i++) {
    key[i] = rand() % 255;
  }
}


x86 assembly (clang, -O0):
<keyGen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x8,-0xc(%rbp)
jge    1155 <keyGen+0x45>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1123 <keyGen+0x13>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<keyGen>:
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
add    %eax,%ecx
mov    %cl,(%rbx)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
add    %eax,%ecx
mov    %cl,0x1(%rbx)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
add    %eax,%ecx
mov    %cl,0x2(%rbx)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
add    %eax,%ecx
mov    %cl,0x3(%rbx)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
add    %eax,%ecx
mov    %cl,0x4(%rbx)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
add    %eax,%ecx
mov    %cl,0x5(%rbx)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
add    %eax,%ecx
mov    %cl,0x6(%rbx)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0xffffffff80808081,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x7,%ecx
add    %edx,%ecx
add    %eax,%ecx
mov    %cl,0x7(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define void @keyGen(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %3
br label %4
4: ; preds = %15, %1
%5 = load i32, i32* %3
%6 = icmp slt i32 %5, 8
br i1 %6, label %7, label %18
7: ; preds = %4
%8 = call i32 (...) @rand()
%9 = srem i32 %8, 255
%10 = trunc i32 %9 to i8
%11 = load i8*, i8** %2
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
store i8 %10, i8* %14
br label %15
15: ; preds = %7
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %4
18: ; preds = %4
ret void
}

LLVM IR (-O2):
define void @keyGen(i8* nocapture writeonly %0) {
%2 = tail call i32 (...) @rand()
%3 = srem i32 %2, 255
%4 = trunc i32 %3 to i8
store i8 %4, i8* %0
%5 = tail call i32 (...) @rand()
%6 = srem i32 %5, 255
%7 = trunc i32 %6 to i8
%8 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %7, i8* %8
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 255
%11 = trunc i32 %10 to i8
%12 = getelementptr inbounds i8, i8* %0, i64 2
store i8 %11, i8* %12
%13 = tail call i32 (...) @rand()
%14 = srem i32 %13, 255
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds i8, i8* %0, i64 3
store i8 %15, i8* %16
%17 = tail call i32 (...) @rand()
%18 = srem i32 %17, 255
%19 = trunc i32 %18 to i8
%20 = getelementptr inbounds i8, i8* %0, i64 4
store i8 %19, i8* %20
%21 = tail call i32 (...) @rand()
%22 = srem i32 %21, 255
%23 = trunc i32 %22 to i8
%24 = getelementptr inbounds i8, i8* %0, i64 5
store i8 %23, i8* %24
%25 = tail call i32 (...) @rand()
%26 = srem i32 %25, 255
%27 = trunc i32 %26 to i8
%28 = getelementptr inbounds i8, i8* %0, i64 6
store i8 %27, i8* %28
%29 = tail call i32 (...) @rand()
%30 = srem i32 %29, 255
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds i8, i8* %0, i64 7
store i8 %31, i8* %32
ret void
}