#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
char *malloc(int);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/);
char *random_name() {
  FILE *f;
  int nLines = 0;
  char line[1024];
  int randLine;
  int i;
  char *name;
  name = malloc(1024);
  srand(time(0));
  f = fopen("names.txt", "r");
  while (!feof(f)) {
    fgets(line, 1024, f);
    nLines++;
  }
  randLine = rand() % nLines;
  fseek(f, 0, SEEK_SET);
  for (i = 0; !feof(f) && i <= randLine; i++)
    fgets(line, 1024, f);
  line[strlen(line) - 1] = '\0';
  if (rand() % 2 == 0) {
    strcpy(name, "Mr. ");
  } else {
    strcpy(name, "Mrs. ");
  }
  strcat(name, line);
  return name;
}


x86 assembly (clang, -O0):
<random_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0xc(%rbp)
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,-0x420(%rbp)
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xe18(%rip),%rdi
lea    0xe1b(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1216 <random_name+0x66>
jmp    1239 <random_name+0x89>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11f8 <random_name+0x48>
mov    $0x0,%al
call   10d0 <rand@plt>
cltd
idivl  -0xc(%rbp)
mov    %edx,-0x414(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2d8b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
movl   $0x0,-0x418(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x421(%rbp)
jne    1299 <random_name+0xe9>
mov    -0x418(%rbp),%eax
cmp    -0x414(%rbp),%eax
setle  %al
mov    %al,-0x421(%rbp)
mov    -0x421(%rbp),%al
test   $0x1,%al
jne    12ac <random_name+0xfc>
jmp    12d5 <random_name+0x125>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    1268 <random_name+0xb8>
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x410(%rbp,%rax,1)
mov    $0x0,%al
call   10d0 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    131e <random_name+0x16e>
mov    -0x420(%rbp),%rdi
lea    0xcf8(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1331 <random_name+0x181>
mov    -0x420(%rbp),%rdi
lea    0xce5(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x420(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x420(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_name>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    $0x400,%edi
call   1090 <malloc@plt>
mov    %rax,%r14
xor    %ebp,%ebp
xor    %edi,%edi
call   1080 <time@plt>
mov    %eax,%edi
call   1050 <srand@plt>
lea    0xe1d(%rip),%rdi
lea    0xe20(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    122f <random_name+0x7f>
xor    %ebp,%ebp
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     1210 <random_name+0x60>
xor    %eax,%eax
call   10d0 <rand@plt>
cltd
idiv   %ebp
mov    %edx,%r12d
mov    0x2d9d(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1296 <random_name+0xe6>
test   %r12d,%r12d
js     1296 <random_name+0xe6>
xor    %ebp,%ebp
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1296 <random_name+0xe6>
lea    0x1(%rbp),%eax
cmp    %r12d,%ebp
mov    %eax,%ebp
jl     1270 <random_name+0xc0>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
xor    %eax,%eax
call   10d0 <rand@plt>
test   $0x1,%al
lea    0xd54(%rip),%rax
lea    0xd52(%rip),%rsi
cmove  %rax,%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10c0 <strcat@plt>
mov    %r14,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"names.txt\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.2 = [5 x i8] c"Mr. \00"
@.str.3 = [6 x i8] c"Mrs. \00"
define i8* @random_name() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 0, i32* %2
%7 = call i8* @malloc(i32 1024)
store i8* %7, i8** %6
%8 = call i32 @time(i32 0)
%9 = call i32 @srand(i32 %8)
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %10, i32** %1
br label %11
11: ; preds = %16, %0
%12 = load i32*, i32** %1
%13 = call i32 @feof(i32* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %22
16: ; preds = %11
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = load i32*, i32** %1
%19 = call i32 @fgets(i8* %17, i32 1024, i32* %18)
%20 = load i32, i32* %2
%21 = add nsw i32 %20, 1
store i32 %21, i32* %2
br label %11
22: ; preds = %11
%23 = call i32 (...) @rand()
%24 = load i32, i32* %2
%25 = srem i32 %23, %24
store i32 %25, i32* %4
%26 = load i32*, i32** %1
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %26, i32 0, i32 %27)
store i32 0, i32* %5
br label %29
29: ; preds = %43, %22
%30 = load i32*, i32** %1
%31 = call i32 @feof(i32* %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %37, label %33
33: ; preds = %29
%34 = load i32, i32* %5
%35 = load i32, i32* %4
%36 = icmp sle i32 %34, %35
br label %37
37: ; preds = %33, %29
%38 = phi i1 [ false, %29 ], [ %36, %33 ]
br i1 %38, label %39, label %46
39: ; preds = %37
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%41 = load i32*, i32** %1
%42 = call i32 @fgets(i8* %40, i32 1024, i32* %41)
br label %43
43: ; preds = %39
%44 = load i32, i32* %5
%45 = add nsw i32 %44, 1
store i32 %45, i32* %5
br label %29
46: ; preds = %37
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%48 = call i32 @strlen(i8* %47)
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %50
store i8 0, i8* %51
%52 = call i32 (...) @rand()
%53 = srem i32 %52, 2
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %46
%56 = load i8*, i8** %6
%57 = call i32 @strcpy(i8* %56, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %61
58: ; preds = %46
%59 = load i8*, i8** %6
%60 = call i32 @strcpy(i8* %59, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %61
61: ; preds = %58, %55
%62 = load i8*, i8** %6
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%64 = call i32 @strcat(i8* %62, i8* %63)
%65 = load i8*, i8** %6
ret i8* %65
}

LLVM IR (-O2):
@.str = [10 x i8] c"names.txt\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_SET = global i32 0
@.str.2 = [5 x i8] c"Mr. \00"
@.str.3 = [6 x i8] c"Mrs. \00"
define i8* @random_name() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%4 = tail call i32 @time(i32 0)
%5 = tail call i32 @srand(i32 %4)
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @feof(i32* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0, %9
%10 = phi i32 [ %12, %9 ], [ 0, %0 ]
%11 = call i32 @fgets(i8* %2, i32 1024, i32* %6)
%12 = add nuw nsw i32 %10, 1
%13 = call i32 @feof(i32* %6)
%14 = icmp eq i32 %13, 0
br i1 %14, label %9, label %15
15: ; preds = %9, %0
%16 = phi i32 [ 0, %0 ], [ %12, %9 ]
%17 = call i32 (...) @rand()
%18 = srem i32 %17, %16
%19 = load i32, i32* @SEEK_SET
%20 = call i32 @fseek(i32* %6, i32 0, i32 %19)
%21 = call i32 @feof(i32* %6)
%22 = icmp eq i32 %21, 0
%23 = icmp sgt i32 %18, -1
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %25, label %33
25: ; preds = %15, %25
%26 = phi i32 [ %28, %25 ], [ 0, %15 ]
%27 = call i32 @fgets(i8* %2, i32 1024, i32* %6)
%28 = add nuw nsw i32 %26, 1
%29 = call i32 @feof(i32* %6)
%30 = icmp eq i32 %29, 0
%31 = icmp slt i32 %26, %18
%32 = select i1 %30, i1 %31, i1 false
br i1 %32, label %25, label %33
33: ; preds = %25, %15
%34 = call i32 @strlen(i8* %2)
%35 = add nsw i32 %34, -1
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 %36
store i8 0, i8* %37
%38 = call i32 (...) @rand()
%39 = and i32 %38, 1
%40 = icmp eq i32 %39, 0
%41 = select i1 %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0)
%42 = call i32 @strcpy(i8* %3, i8* %41)
%43 = call i32 @strcat(i8* %3, i8* %2)
ret i8* %3
}