#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*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sourceFileName(int);
int /*<<< orphan*/ *strchr(char *, char);
char *readSourceLine(int file, int line) {
  int count;
  static char buffer[1000];
  FILE *sourceFile;
  sourceFile = fopen(sourceFileName(file), "r");
  if (sourceFile != NULL) {
    for (count = 0; count < line; count++) {
      if (fgets(buffer, 1000, sourceFile) == 0)
        return NULL;
      while (strchr(buffer, '\n') == NULL)
        if (fgets(buffer, 1000, sourceFile) == 0)
          return buffer;
    }
    fclose(sourceFile);
    return buffer;
  }
  return NULL;
}


x86 assembly (clang, -O0):
<readSourceLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <sourceFileName@plt>
mov    %eax,%edi
lea    0xe91(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1242 <readSourceLine+0xf2>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    1229 <readSourceLine+0xd9>
mov    -0x20(%rbp),%rdx
lea    0x2ebf(%rip),%rdi
mov    $0x3e8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    11c2 <readSourceLine+0x72>
movq   $0x0,-0x8(%rbp)
jmp    124a <readSourceLine+0xfa>
jmp    11c7 <readSourceLine+0x77>
lea    0x2e92(%rip),%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jne    1216 <readSourceLine+0xc6>
mov    -0x20(%rbp),%rdx
lea    0x2e73(%rip),%rdi
mov    $0x3e8,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    1211 <readSourceLine+0xc1>
lea    0x2e58(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    124a <readSourceLine+0xfa>
jmp    11c7 <readSourceLine+0x77>
jmp    121b <readSourceLine+0xcb>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118a <readSourceLine+0x3a>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
lea    0x2e27(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    124a <readSourceLine+0xfa>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readSourceLine>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
call   1030 <sourceFileName@plt>
lea    0xe9a(%rip),%rsi
mov    %eax,%edi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ea <readSourceLine+0x9a>
mov    %rax,%rbp
test   %r14d,%r14d
jle    11d9 <readSourceLine+0x89>
lea    0x2edf(%rip),%rbx
xor    %r15d,%r15d
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %rbp,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11ea <readSourceLine+0x9a>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    11d0 <readSourceLine+0x80>
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %rbp,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
jne    11a0 <readSourceLine+0x50>
jmp    11ec <readSourceLine+0x9c>
nopl   0x0(%rax)
add    $0x1,%r15d
cmp    %r14d,%r15d
jne    1184 <readSourceLine+0x34>
mov    %rbp,%rdi
call   1040 <fclose@plt>
lea    0x2e78(%rip),%rbx
jmp    11ec <readSourceLine+0x9c>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@readSourceLine.buffer = internal global [1000 x i8] zeroinitializer
@.str = [2 x i8] c"r\00"
define i8* @readSourceLine(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* %4
%9 = call i32 @sourceFileName(i32 %8)
%10 = call i32* @fopen(i32 %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = load i32*, i32** %7
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %40
13: ; preds = %2
store i32 0, i32* %6
br label %14
14: ; preds = %34, %13
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %37
18: ; preds = %14
%19 = load i32*, i32** %7
%20 = call i64 @fgets(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @readSourceLine.buffer, i64 0, i64 0), i32 1000, i32* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i8* null, i8** %3
br label %41
23: ; preds = %18
br label %24
24: ; preds = %32, %23
%25 = call i32* @strchr(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @readSourceLine.buffer, i64 0, i64 0), i8 signext 10)
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %33
27: ; preds = %24
%28 = load i32*, i32** %7
%29 = call i64 @fgets(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @readSourceLine.buffer, i64 0, i64 0), i32 1000, i32* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %27
store i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @readSourceLine.buffer, i64 0, i64 0), i8** %3
br label %41
32: ; preds = %27
br label %24
33: ; preds = %24
br label %34
34: ; preds = %33
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %14
37: ; preds = %14
%38 = load i32*, i32** %7
%39 = call i32 @fclose(i32* %38)
store i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @readSourceLine.buffer, i64 0, i64 0), i8** %3
br label %41
40: ; preds = %2
store i8* null, i8** %3
br label %41
41: ; preds = %40, %37, %31, %22
%42 = load i8*, i8** %3
ret i8* %42
}

LLVM IR (-O2):
@readSourceLine.buffer = internal global [1000 x i8] zeroinitializer
@.str = [2 x i8] c"r\00"
define i8* @readSourceLine(i32 %0, i32 %1) {
%3 = tail call i32 @sourceFileName(i32 %0)
%4 = tail call i32* @fopen(i32 %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %23, label %6
6: ; preds = %2
%7 = icmp sgt i32 %1, 0
br i1 %7, label %8, label %21
8: ; preds = %6, %18
%9 = phi i32 [ %19, %18 ], [ 0, %6 ]
%10 = tail call i64 @fgets(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @readSourceLine.buffer, i64 0, i64 0), i32 1000, i32* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %8, %15
%13 = tail call i32* @strchr(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @readSourceLine.buffer, i64 0, i64 0), i8 signext 10)
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i64 @fgets(i8* getelementptr inbounds ([1000 x i8], [1000 x i8]* @readSourceLine.buffer, i64 0, i64 0), i32 1000, i32* %4)
%17 = icmp eq i64 %16, 0
br i1 %17, label %23, label %12
18: ; preds = %12
%19 = add nuw nsw i32 %9, 1
%20 = icmp eq i32 %19, %1
br i1 %20, label %21, label %8
21: ; preds = %18, %6
%22 = tail call i32 @fclose(i32* %4)
br label %23
23: ; preds = %8, %15, %2, %21
%24 = phi i8* [ getelementptr inbounds ([1000 x i8], [1000 x i8]* @readSourceLine.buffer, i64 0, i64 0), %21 ], [ null, %2 ], [ getelementptr inbounds ([1000 x i8], [1000 x i8]* @readSourceLine.buffer, i64 0, i64 0), %15 ], [ null, %8 ]
ret i8* %24
}