#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 */
typedef int /*<<< orphan*/ word;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int rand();
void generate_word(char *word) {
  memset(word, 0, sizeof(word));
  int length = rand() % 10 + 1, i = 0;
  for (; length > 0; length--) {
    word[i++] = (char)(rand() % 26 + 65);
  }
}


x86 assembly (clang, -O0):
<generate_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1197 <generate_word+0x77>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x10(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1158 <generate_word+0x38>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_word>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
xor    %eax,%eax
call   1040 <rand@plt>
movslq %eax,%rbx
imul   $0x66666667,%rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x22,%rax
add    %ecx,%eax
add    %eax,%eax
lea    (%rax,%rax,4),%eax
sub    %eax,%ebx
js     1198 <generate_word+0x78>
add    $0x2,%ebx
nopl   (%rax)
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,(%r14)
add    $0x1,%r14
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1160 <generate_word+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @generate_word(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @memset(i8* %5, i32 0, i32 8)
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 10
%9 = add nsw i32 %8, 1
store i32 %9, i32* %3
store i32 0, i32* %4
br label %10
10: ; preds = %23, %1
%11 = load i32, i32* %3
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %10
%14 = call i32 (...) @rand()
%15 = srem i32 %14, 26
%16 = add nsw i32 %15, 65
%17 = trunc i32 %16 to i8
%18 = load i8*, i8** %2
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
store i32 %20, i32* %4
%21 = sext i32 %19 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8 %17, i8* %22
br label %23
23: ; preds = %13
%24 = load i32, i32* %3
%25 = add nsw i32 %24, -1
store i32 %25, i32* %3
br label %10
26: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @generate_word(i8* %0) {
%2 = tail call i32 @memset(i8* %0, i32 0, i32 8)
%3 = tail call i32 (...) @rand()
%4 = srem i32 %3, 10
%5 = icmp sgt i32 %4, -1
br i1 %5, label %6, label %19
6: ; preds = %1
%7 = add nuw nsw i32 %4, 1
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ 0, %6 ], [ %15, %8 ]
%10 = phi i32 [ %7, %6 ], [ %17, %8 ]
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 26
%13 = trunc i32 %12 to i8
%14 = add nsw i8 %13, 65
%15 = add nuw nsw i64 %9, 1
%16 = getelementptr inbounds i8, i8* %0, i64 %9
store i8 %14, i8* %16
%17 = add nsw i32 %10, -1
%18 = icmp ugt i32 %10, 1
br i1 %18, label %8, label %19
19: ; preds = %8, %1
ret void
}