#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 /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int random_word(char *, int);
int /*<<< orphan*/ write(int, char *, int);
void gen_word(int fd, int word_num, int opt) {
  char word[20] = {0};
  int true_word_len = 0;
  while (word_num--) {
    memset(word, 0, 20);
    true_word_len = random_word(word, opt);
    word[true_word_len] = '\n';
    write(fd, word, true_word_len + 1);
  }
}


x86 assembly (clang, -O0):
<gen_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     11ab <gen_word+0x7b>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
lea    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <random_word@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
movb   $0xa,-0x20(%rbp,%rax,1)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
call   1030 <write@plt>
jmp    1158 <gen_word+0x28>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_word>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
test   %esi,%esi
je     1194 <gen_word+0x64>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%r15d
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <random_word@plt>
movslq %eax,%rdx
movb   $0xa,(%rsp,%rdx,1)
add    $0x1,%edx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
add    $0xffffffff,%ebp
jne    1160 <gen_word+0x30>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @gen_word(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [20 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = bitcast [20 x i8]* %7 to i8*
store i32 0, i32* %8
br label %10
10: ; preds = %14, %3
%11 = load i32, i32* %5
%12 = add nsw i32 %11, -1
store i32 %12, i32* %5
%13 = icmp ne i32 %11, 0
br i1 %13, label %14, label %28
14: ; preds = %10
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%16 = call i32 @memset(i8* %15, i32 0, i32 20)
%17 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%18 = load i32, i32* %6
%19 = call i32 @random_word(i8* %17, i32 %18)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 %21
store i8 10, i8* %22
%23 = load i32, i32* %4
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
%27 = call i32 @write(i32 %23, i8* %24, i32 %26)
br label %10
28: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @gen_word(i32 %0, i32 %1, i32 %2) {
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%6 = icmp eq i32 %1, 0
br i1 %6, label %17, label %7
7: ; preds = %3, %7
%8 = phi i32 [ %9, %7 ], [ %1, %3 ]
%9 = add nsw i32 %8, -1
%10 = call i32 @memset(i8* %5, i32 0, i32 20)
%11 = call i32 @random_word(i8* %5, i32 %2)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 %12
store i8 10, i8* %13
%14 = add nsw i32 %11, 1
%15 = call i32 @write(i32 %0, i8* %5, i32 %14)
%16 = icmp eq i32 %9, 0
br i1 %16, label %17, label %7
17: ; preds = %7, %3
ret void
}