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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *memchr(char *, char, int);
int open(char *, int /*<<< orphan*/);
int rand();
size_t read(int, char *, int);
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ stdout;
int strlen(char *);
scalar_t__ time(int /*<<< orphan*/ *);
void print_random(char *filename) {
  FILE *fp;
  int fd;
  int lines = 0;
  int max, random_line_number;
  size_t bytes_read;
  char buf[(16 * 1024) + 1];
  fd = open(filename, 0);
  while ((bytes_read = read(fd, buf, (16 * 1024))) > 0) {
    char *p = buf;
    while ((p = memchr(p, '\n', (buf + bytes_read) - p))) {
      ++p;
      ++lines;
    }
  }
  close(fd);
  srand((unsigned)time(NULL));
  random_line_number = rand() % lines;
  if (random_line_number % 2 == 1)
    random_line_number -= 1;
  fp = fopen(filename, "rb");
  for (max = 0; !feof(fp); max++) {
    fgets(buf, sizeof(buf), fp);
    if (max == random_line_number) {
      buf[strlen(buf) - 2] = '\0';
      fprintf(stdout, "%s : ", buf);
      fgets(buf, sizeof(buf), fp);
      buf[strlen(buf) - 2] = '\0';
      fprintf(stdout, "%s\n", buf);
      break;
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<print_random>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4040,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   10d0 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x4030(%rbp),%rsi
mov    $0x4000,%edx
call   1070 <read@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jbe    1282 <print_random+0xb2>
lea    -0x4030(%rbp),%rax
mov    %rax,-0x4038(%rbp)
mov    -0x4038(%rbp),%rdi
lea    -0x4030(%rbp),%rax
add    -0x28(%rbp),%rax
mov    -0x4038(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
mov    $0xa,%esi
call   1060 <memchr@plt>
mov    %rax,-0x4038(%rbp)
cmp    $0x0,%rax
je     127d <print_random+0xad>
mov    -0x4038(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x4038(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1224 <print_random+0x54>
jmp    11f4 <print_random+0x24>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
mov    $0x0,%al
call   10f0 <rand@plt>
cltd
idivl  -0x18(%rbp)
mov    %edx,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    12c5 <print_random+0xf5>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xd30(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12fe <print_random+0x12e>
jmp    13b6 <print_random+0x1e6>
lea    -0x4030(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x4001,%esi
call   1090 <fgets@plt>
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jne    13a3 <print_random+0x1d3>
lea    -0x4030(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x2,%eax
cltq
movb   $0x0,-0x4030(%rbp,%rax,1)
mov    0x2ca1(%rip),%rax
mov    (%rax),%edi
lea    -0x4030(%rbp),%rdx
lea    0xcb4(%rip),%rsi
call   10a0 <fprintf@plt>
lea    -0x4030(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x4001,%esi
call   1090 <fgets@plt>
lea    -0x4030(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x2,%eax
cltq
movb   $0x0,-0x4030(%rbp,%rax,1)
mov    0x2c57(%rip),%rax
mov    (%rax),%edi
lea    -0x4030(%rbp),%rdx
lea    0xc70(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    13b6 <print_random+0x1e6>
jmp    13a8 <print_random+0x1d8>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12e0 <print_random+0x110>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x4040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_random>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x4010,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %esi,%esi
call   10d0 <open@plt>
mov    %eax,%r15d
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x4000,%edx
call   1070 <read@plt>
test   %rax,%rax
je     125f <print_random+0x8f>
mov    %rax,%rbp
xor    %ebx,%ebx
mov    %rsp,%r12
jmp    1228 <print_random+0x58>
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0x4000,%edx
call   1070 <read@plt>
mov    %rax,%rbp
test   %rax,%rax
je     125f <print_random+0x8f>
mov    %r12,%rdi
mov    $0xa,%esi
mov    %ebp,%edx
call   1060 <memchr@plt>
test   %rax,%rax
je     1210 <print_random+0x40>
add    %rsp,%rbp
nop
add    $0x1,%rax
add    $0x1,%ebx
mov    %ebp,%edx
sub    %eax,%edx
mov    %rax,%rdi
mov    $0xa,%esi
call   1060 <memchr@plt>
test   %rax,%rax
jne    1240 <print_random+0x70>
jmp    1210 <print_random+0x40>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10c0 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
xor    %eax,%eax
call   10f0 <rand@plt>
cltd
idiv   %ebx
mov    %edx,%ebp
mov    %edx,%eax
shr    $0x1f,%eax
add    %edx,%eax
and    $0xfffffffe,%eax
mov    %edx,%ecx
sub    %eax,%ecx
xor    %r15d,%r15d
cmp    $0x1,%ecx
sete   %r12b
lea    0xd60(%rip),%rsi
mov    %r14,%rdi
call   10e0 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
jne    134e <print_random+0x17e>
mov    %r12b,%r15b
neg    %r15d
add    %r15d,%ebp
add    $0x1,%ebp
mov    %rsp,%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x4001,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
add    $0xffffffff,%ebp
je     12f3 <print_random+0x123>
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %eax,%eax
je     12d0 <print_random+0x100>
jmp    134e <print_random+0x17e>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x2(%rax,%r14,1)
mov    0x2cd6(%rip),%rbp
mov    0x0(%rbp),%edi
lea    0xcef(%rip),%rsi
mov    %r14,%rdx
call   10a0 <fprintf@plt>
mov    %r14,%rdi
mov    $0x4001,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x2(%rax,%r14,1)
mov    0x0(%rbp),%edi
lea    0xcc3(%rip),%rsi
mov    %r14,%rdx
call   10a0 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x4010,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stdout = global i32 0
@.str.1 = [6 x i8] c"%s : \00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @print_random(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca [16385 x i8]
%10 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %5
%11 = load i8*, i8** %2
%12 = call i32 @open(i8* %11, i32 0)
store i32 %12, i32* %4
br label %13
13: ; preds = %37, %1
%14 = load i32, i32* %4
%15 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%16 = call i64 @read(i32 %14, i8* %15, i32 16384)
store i64 %16, i64* %8
%17 = icmp ugt i64 %16, 0
br i1 %17, label %18, label %38
18: ; preds = %13
%19 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
store i8* %19, i8** %10
br label %20
20: ; preds = %32, %18
%21 = load i8*, i8** %10
%22 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%23 = load i64, i64* %8
%24 = getelementptr inbounds i8, i8* %22, i64 %23
%25 = load i8*, i8** %10
%26 = ptrtoint i8* %24 to i64
%27 = ptrtoint i8* %25 to i64
%28 = sub i64 %26, %27
%29 = trunc i64 %28 to i32
%30 = call i8* @memchr(i8* %21, i8 signext 10, i32 %29)
store i8* %30, i8** %10
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %37
32: ; preds = %20
%33 = load i8*, i8** %10
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %10
%35 = load i32, i32* %5
%36 = add nsw i32 %35, 1
store i32 %36, i32* %5
br label %20
37: ; preds = %20
br label %13
38: ; preds = %13
%39 = load i32, i32* %4
%40 = call i32 @close(i32 %39)
%41 = call i64 @time(i32* null)
%42 = trunc i64 %41 to i32
%43 = call i32 @srand(i32 %42)
%44 = call i32 (...) @rand()
%45 = load i32, i32* %5
%46 = srem i32 %44, %45
store i32 %46, i32* %7
%47 = load i32, i32* %7
%48 = srem i32 %47, 2
%49 = icmp eq i32 %48, 1
br i1 %49, label %50, label %53
50: ; preds = %38
%51 = load i32, i32* %7
%52 = sub nsw i32 %51, 1
store i32 %52, i32* %7
br label %53
53: ; preds = %50, %38
%54 = load i8*, i8** %2
%55 = call i32* @fopen(i8* %54, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %55, i32** %3
store i32 0, i32* %6
br label %56
56: ; preds = %89, %53
%57 = load i32*, i32** %3
%58 = call i32 @feof(i32* %57)
%59 = icmp ne i32 %58, 0
%60 = xor i1 %59, true
br i1 %60, label %61, label %92
61: ; preds = %56
%62 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%63 = load i32*, i32** %3
%64 = call i32 @fgets(i8* %62, i32 16385, i32* %63)
%65 = load i32, i32* %6
%66 = load i32, i32* %7
%67 = icmp eq i32 %65, %66
br i1 %67, label %68, label %88
68: ; preds = %61
%69 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%70 = call i32 @strlen(i8* %69)
%71 = sub nsw i32 %70, 2
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 %72
store i8 0, i8* %73
%74 = load i32, i32* @stdout
%75 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%76 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %75)
%77 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%78 = load i32*, i32** %3
%79 = call i32 @fgets(i8* %77, i32 16385, i32* %78)
%80 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%81 = call i32 @strlen(i8* %80)
%82 = sub nsw i32 %81, 2
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 %83
store i8 0, i8* %84
%85 = load i32, i32* @stdout
%86 = getelementptr inbounds [16385 x i8], [16385 x i8]* %9, i64 0, i64 0
%87 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %86)
br label %92
88: ; preds = %61
br label %89
89: ; preds = %88
%90 = load i32, i32* %6
%91 = add nsw i32 %90, 1
store i32 %91, i32* %6
br label %56
92: ; preds = %68, %56
%93 = load i32*, i32** %3
%94 = call i32 @fclose(i32* %93)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stdout = global i32 0
@.str.1 = [6 x i8] c"%s : \00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @print_random(i8* nocapture %0) {
%2 = alloca [16385 x i8]
%3 = getelementptr inbounds [16385 x i8], [16385 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @open(i8* %0, i32 0)
%5 = call i64 @read(i32 %4, i8* %3, i32 16384)
%6 = icmp eq i64 %5, 0
br i1 %6, label %29, label %11
7: ; preds = %19, %11
%8 = phi i32 [ %13, %11 ], [ %23, %19 ]
%9 = call i64 @read(i32 %4, i8* %3, i32 16384)
%10 = icmp eq i64 %9, 0
br i1 %10, label %29, label %11
11: ; preds = %1, %7
%12 = phi i64 [ %9, %7 ], [ %5, %1 ]
%13 = phi i32 [ %8, %7 ], [ 0, %1 ]
%14 = getelementptr inbounds [16385 x i8], [16385 x i8]* %2, i64 0, i64 %12
%15 = ptrtoint i8* %14 to i64
%16 = trunc i64 %12 to i32
%17 = call i8* @memchr(i8* %3, i8 signext 10, i32 %16)
%18 = icmp eq i8* %17, null
br i1 %18, label %7, label %19
19: ; preds = %11, %19
%20 = phi i8* [ %27, %19 ], [ %17, %11 ]
%21 = phi i32 [ %23, %19 ], [ %13, %11 ]
%22 = getelementptr inbounds i8, i8* %20, i64 1
%23 = add nsw i32 %21, 1
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %15, %24
%26 = trunc i64 %25 to i32
%27 = call i8* @memchr(i8* %22, i8 signext 10, i32 %26)
%28 = icmp eq i8* %27, null
br i1 %28, label %7, label %19
29: ; preds = %7, %1
%30 = phi i32 [ 0, %1 ], [ %8, %7 ]
%31 = call i32 @close(i32 %4)
%32 = call i64 @time(i32* null)
%33 = trunc i64 %32 to i32
%34 = call i32 @srand(i32 %33)
%35 = call i32 (...) @rand()
%36 = srem i32 %35, %30
%37 = srem i32 %36, 2
%38 = icmp eq i32 %37, 1
%39 = sext i1 %38 to i32
%40 = add nsw i32 %36, %39
%41 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%42 = call i32 @feof(i32* %41)
%43 = icmp eq i32 %42, 0
br i1 %43, label %48, label %66
44: ; preds = %48
%45 = add nuw nsw i32 %49, 1
%46 = call i32 @feof(i32* %41)
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %66
48: ; preds = %29, %44
%49 = phi i32 [ %45, %44 ], [ 0, %29 ]
%50 = call i32 @fgets(i8* %3, i32 16385, i32* %41)
%51 = icmp eq i32 %49, %40
br i1 %51, label %52, label %44
52: ; preds = %48
%53 = call i32 @strlen(i8* %3)
%54 = add nsw i32 %53, -2
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [16385 x i8], [16385 x i8]* %2, i64 0, i64 %55
store i8 0, i8* %56
%57 = load i32, i32* @stdout
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%59 = call i32 @fgets(i8* %3, i32 16385, i32* %41)
%60 = call i32 @strlen(i8* %3)
%61 = add nsw i32 %60, -2
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [16385 x i8], [16385 x i8]* %2, i64 0, i64 %62
store i8 0, i8* %63
%64 = load i32, i32* @stdout
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %66
66: ; preds = %44, %29, %52
%67 = call i32 @fclose(i32* %41)
ret void
}