#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 *calloc(unsigned int, int);
unsigned int dice_roll(int);
char get_consonant();
char get_vowel();
unsigned int const rand();
char *generate_word(const unsigned max_word_length) {
  unsigned i, word_length = rand() % max_word_length + 1,
              is_consonant = dice_roll(2);
  char *word = calloc(word_length + 2, sizeof(char));
  for (i = 0; i < word_length; ++i) {
    if ((!is_consonant && dice_roll(5)) || is_consonant || 1 == word_length) {
      word[i] = get_vowel();
      is_consonant = 0;
      continue;
    }
    word[i] = get_consonant();
    is_consonant = 1;
  }
  word[word_length] = ' ';
  return word;
}


x86 assembly (clang, -O0):
<generate_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
xor    %edx,%edx
divl   -0x4(%rbp)
add    $0x1,%edx
mov    %edx,-0xc(%rbp)
mov    $0x2,%edi
call   1040 <dice_roll@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
add    $0x2,%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    121d <generate_word+0xcd>
cmpl   $0x0,-0x10(%rbp)
jne    11be <generate_word+0x6e>
mov    $0x5,%edi
call   1040 <dice_roll@plt>
cmp    $0x0,%eax
jne    11d6 <generate_word+0x86>
cmpl   $0x0,-0x10(%rbp)
jne    11d6 <generate_word+0x86>
mov    $0x1,%eax
cmp    -0xc(%rbp),%eax
jne    11f5 <generate_word+0xa5>
mov    $0x0,%al
call   1060 <get_vowel@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
movl   $0x0,-0x10(%rbp)
jmp    120f <generate_word+0xbf>
mov    $0x0,%al
call   1050 <get_consonant@plt>
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
movl   $0x1,-0x10(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1195 <generate_word+0x45>
mov    -0x18(%rbp),%rax
mov    -0xc(%rbp),%ecx
movb   $0x20,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_word>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%r12d
xor    %edx,%edx
div    %r15d
mov    %edx,%r14d
mov    $0x2,%edi
call   1040 <dice_roll@plt>
mov    %eax,%ebp
lea    0x3(%r14),%edi
mov    $0x1,%esi
call   1030 <calloc@plt>
mov    %rax,%r13
xor    %ebx,%ebx
jmp    11c1 <generate_word+0x71>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <get_vowel@plt>
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
mov    %r12d,%eax
xor    %edx,%edx
div    %r15d
add    $0x1,%edx
cmp    %edx,%ebx
je     11e6 <generate_word+0x96>
test   %ebp,%ebp
jne    11a0 <generate_word+0x50>
mov    $0x5,%edi
call   1040 <dice_roll@plt>
test   %eax,%eax
jne    11a0 <generate_word+0x50>
test   %r14d,%r14d
je     11a0 <generate_word+0x50>
xor    %eax,%eax
call   1050 <get_consonant@plt>
mov    $0x1,%ebp
jmp    11a9 <generate_word+0x59>
mov    %r14d,%eax
movb   $0x20,0x1(%rax,%r13,1)
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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