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

/* Variables and functions */
unsigned long long RAND_MAX;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
unsigned long long rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  printf("+===================================================================="
         "==+\n"
         "|                              Cygnet XIV                            "
         "  |\n"
         "| Copyright (C) 2011-2014 William Breathitt Gray                     "
         "  |\n"
         "+===================================================================="
         "==+\n"
         "|  This program comes with ABSOLUTELY NO WARRANTY. This is free      "
         "  |\n"
         "|  software, and you are welcome to redistribute it under certain    "
         "  |\n"
         "|  conditions; for further details, please refer to the GNU General  "
         "  |\n"
         "|  Public License provided with this program.                        "
         "  |\n"
         "+===================================================================="
         "==+\n\n");
  const char *fLocation = "compliments.txt";
  FILE *lines = fopen(fLocation, "r");
  if (!lines) {
    fprintf(stderr, "Error opening \"%s\"\n", fLocation);
    return 1;
  }
  unsigned long long total_lines = 0;
  char buffer[256];
  srand(time(NULL));
  char compliment[256] = "";
  while (fgets(buffer, sizeof(buffer), lines)) {
    total_lines++;
    if (!total_lines || total_lines == RAND_MAX) {
      fprintf(stderr, "Cygnet XIV cannot parse further compliments;"
                      "a compliment has been chosen from the parsed lines.\n");
      break;
    }
    if (rand() < RAND_MAX / total_lines) {
      strcpy(compliment, buffer);
    }
  }
  if (ferror(lines)) {
    fprintf(stderr, "Error reading \"%s\"\n", fLocation);
    fclose(lines);
    return 1;
  }
  fclose(lines);
  printf("%s", compliment);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0x10bc(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0x10bd(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1221 <main+0x71>
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0x1097(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1365 <main+0x1b5>
movq   $0x0,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x100,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     12fd <main+0x14d>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1296 <main+0xe6>
mov    -0x20(%rbp),%rax
mov    0x2d5b(%rip),%rcx
cmp    (%rcx),%rax
jne    12b2 <main+0x102>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0x1013(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
jmp    12fd <main+0x14d>
mov    $0x0,%al
call   10d0 <rand@plt>
mov    %rax,-0x228(%rbp)
mov    0x2d21(%rip),%rax
mov    (%rax),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x20(%rbp)
mov    %rax,%rcx
mov    -0x228(%rbp),%rax
cmp    %rcx,%rax
jae    12f8 <main+0x148>
lea    -0x220(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    124c <main+0x9c>
mov    -0x18(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1340 <main+0x190>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xff6(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1365 <main+0x1b5>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x220(%rbp),%rsi
lea    0xfd7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200,%rsp
lea    0xed7(%rip),%rdi
call   1040 <puts@plt>
lea    0xe2d(%rip),%rdi
lea    0xe36(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     1306 <main+0x156>
mov    %rax,%r12
xor    %edi,%edi
call   10b0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0x100(%rsp),%rdi
mov    $0x100,%esi
mov    %r12,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     1342 <main+0x192>
mov    $0x1,%ebx
mov    0x2d5b(%rip),%r13
mov    %rsp,%r14
lea    0x100(%rsp),%r15
jmp    12bd <main+0x10d>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
call   1090 <fgets@plt>
add    $0x1,%rbx
test   %rax,%rax
je     1342 <main+0x192>
test   %rbx,%rbx
je     132b <main+0x17b>
cmp    0x0(%r13),%rbx
je     132b <main+0x17b>
xor    %eax,%eax
call   10d0 <rand@plt>
mov    %rax,%rcx
mov    0x0(%r13),%rax
mov    %rax,%rdx
or     %rbx,%rdx
shr    $0x20,%rdx
je     12f0 <main+0x140>
xor    %edx,%edx
div    %rbx
cmp    %rax,%rcx
jae    12a0 <main+0xf0>
jmp    12f9 <main+0x149>
xchg   %ax,%ax
xor    %edx,%edx
div    %ebx
cmp    %rax,%rcx
jae    12a0 <main+0xf0>
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
jmp    12a0 <main+0xf0>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
lea    0xcfc(%rip),%rsi
lea    0xce3(%rip),%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%ebx
jmp    1397 <main+0x1e7>
mov    0x2ca6(%rip),%rax
mov    (%rax),%edi
lea    0xceb(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r12,%rdi
call   1050 <ferror@plt>
test   %rax,%rax
je     137c <main+0x1cc>
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
lea    0xd28(%rip),%rsi
lea    0xc9a(%rip),%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
mov    $0x1,%ebx
jmp    1397 <main+0x1e7>
mov    %r12,%rdi
call   1060 <fclose@plt>
lea    0xd10(%rip),%rdi
xor    %ebx,%ebx
mov    %rsp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [659 x i8] c"+======================================================================+\0A| Cygnet XIV |\0A| Copyright (C) 2011-2014 William Breathitt Gray |\0A+======================================================================+\0A| This program comes with ABSOLUTELY NO WARRANTY. This is free |\0A| software, and you are welcome to redistribute it under certain |\0A| conditions; for further details, please refer to the GNU General |\0A| Public License provided with this program. |\0A+======================================================================+\0A\0A\00"
@.str.1 = [16 x i8] c"compliments.txt\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [20 x i8] c"Error opening \22%s\22\0A\00"
@RAND_MAX = global i64 0
@.str.4 = [97 x i8] c"Cygnet XIV cannot parse further compliments;a compliment has been chosen from the parsed lines.\0A\00"
@.str.5 = [20 x i8] c"Error reading \22%s\22\0A\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([659 x i8], [659 x i8]* @.str, i64 0, i64 0))
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp ne i32* %10, null
br i1 %11, label %16, label %12
12: ; preds = %0
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %2
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %14)
store i32 1, i32* %1
br label %63
16: ; preds = %0
store i64 0, i64* %4
%17 = call i32 @time(i32* null)
%18 = call i32 @srand(i32 %17)
%19 = bitcast [256 x i8]* %6 to i8*
br label %20
20: ; preds = %47, %16
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%22 = load i32*, i32** %3
%23 = call i64 @fgets(i8* %21, i32 256, i32* %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %48
25: ; preds = %20
%26 = load i64, i64* %4
%27 = add i64 %26, 1
store i64 %27, i64* %4
%28 = load i64, i64* %4
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i64, i64* %4
%32 = load i64, i64* @RAND_MAX
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %37
34: ; preds = %30, %25
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.4, i64 0, i64 0))
br label %48
37: ; preds = %30
%38 = call i64 (...) @rand()
%39 = load i64, i64* @RAND_MAX
%40 = load i64, i64* %4
%41 = udiv i64 %39, %40
%42 = icmp ult i64 %38, %41
br i1 %42, label %43, label %47
43: ; preds = %37
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%46 = call i32 @strcpy(i8* %44, i8* %45)
br label %47
47: ; preds = %43, %37
br label %20
48: ; preds = %34, %20
%49 = load i32*, i32** %3
%50 = call i64 @ferror(i32* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %2
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %54)
%56 = load i32*, i32** %3
%57 = call i32 @fclose(i32* %56)
store i32 1, i32* %1
br label %63
58: ; preds = %48
%59 = load i32*, i32** %3
%60 = call i32 @fclose(i32* %59)
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %61)
store i32 0, i32* %1
br label %63
63: ; preds = %58, %52, %12
%64 = load i32, i32* %1
ret i32 %64
}

LLVM IR (-O2):
@.str.1 = [16 x i8] c"compliments.txt\00"
@.str.2 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.3 = [20 x i8] c"Error opening \22%s\22\0A\00"
@RAND_MAX = global i64 0
@.str.4 = [97 x i8] c"Cygnet XIV cannot parse further compliments;a compliment has been chosen from the parsed lines.\0A\00"
@.str.5 = [20 x i8] c"Error reading \22%s\22\0A\00"
@.str.6 = [3 x i8] c"%s\00"
@str = [658 x i8] c"+======================================================================+\0A| Cygnet XIV |\0A| Copyright (C) 2011-2014 William Breathitt Gray |\0A+======================================================================+\0A| This program comes with ABSOLUTELY NO WARRANTY. This is free |\0A| software, and you are welcome to redistribute it under certain |\0A| conditions; for further details, please refer to the GNU General |\0A| Public License provided with this program. |\0A+======================================================================+\0A\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca [256 x i8]
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([658 x i8], [658 x i8]* @str, i64 0, i64 0))
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %48
9: ; preds = %0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%11 = tail call i32 @time(i32* null)
%12 = tail call i32 @srand(i32 %11)
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%14 = call i64 @fgets(i8* %10, i32 256, i32* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %36, label %16
16: ; preds = %9, %33
%17 = phi i64 [ %18, %33 ], [ 0, %9 ]
%18 = add i64 %17, 1
%19 = icmp eq i64 %18, 0
%20 = load i64, i64* @RAND_MAX
%21 = icmp eq i64 %18, %20
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i32, i32* @stderr
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([97 x i8], [97 x i8]* @.str.4, i64 0, i64 0))
br label %36
26: ; preds = %16
%27 = call i64 (...) @rand()
%28 = load i64, i64* @RAND_MAX
%29 = udiv i64 %28, %18
%30 = icmp ult i64 %27, %29
br i1 %30, label %31, label %33
31: ; preds = %26
%32 = call i32 @strcpy(i8* %13, i8* %10)
br label %33
33: ; preds = %31, %26
%34 = call i64 @fgets(i8* %10, i32 256, i32* %4)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %16
36: ; preds = %33, %9, %23
%37 = call i64 @ferror(i32* %4)
%38 = icmp eq i64 %37, 0
br i1 %38, label %43, label %39
39: ; preds = %36
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%42 = call i32 @fclose(i32* %4)
br label %46
43: ; preds = %36
%44 = call i32 @fclose(i32* %4)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %13)
br label %46
46: ; preds = %43, %39
%47 = phi i32 [ 1, %39 ], [ 0, %43 ]
br label %48
48: ; preds = %46, %6
%49 = phi i32 [ %47, %46 ], [ 1, %6 ]
ret i32 %49
}