#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 */
char EOF;
char *calloc(int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *rdz_read_line(char *fname, int lnumber) {
  char *l = calloc(1024, sizeof(char));
  char *ll = l;
  FILE *in = fopen(fname, "r");
  if (in == NULL) {
    fprintf(stderr, "cannot find source file %s\n", fname);
    exit(1);
  }
  while (1) {
    if (lnumber < 1)
      break;
    char c = fgetc(in);
    if (c == EOF)
      break;
    if (c == '\n') {
      lnumber--;
      continue;
    }
    if (lnumber == 1)
      *(ll++) = c;
  }
  fclose(in);
  return l;
}


x86 assembly (clang, -O0):
<rdz_read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x400,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11cc <rdz_read_line+0x6c>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe45(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11d1 <rdz_read_line+0x71>
cmpl   $0x1,-0xc(%rbp)
jge    11e0 <rdz_read_line+0x80>
jmp    1245 <rdz_read_line+0xe5>
mov    -0x28(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x29(%rbp)
movsbl -0x29(%rbp),%eax
mov    0x2df1(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1207 <rdz_read_line+0xa7>
jmp    1245 <rdz_read_line+0xe5>
movsbl -0x29(%rbp),%eax
cmp    $0xa,%eax
jne    1222 <rdz_read_line+0xc2>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11d1 <rdz_read_line+0x71>
cmpl   $0x1,-0xc(%rbp)
jne    1240 <rdz_read_line+0xe0>
mov    -0x29(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    11d1 <rdz_read_line+0x71>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rdz_read_line>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r15
mov    $0x400,%edi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r14
lea    0xe7a(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11f0 <rdz_read_line+0x90>
mov    %rax,%rbx
test   %ebp,%ebp
jle    11dc <rdz_read_line+0x7c>
mov    0x2e47(%rip),%r15
mov    %r14,%r12
jmp    11b7 <rdz_read_line+0x57>
cs nopw 0x0(%rax,%rax,1)
add    $0xffffffff,%ebp
test   %ebp,%ebp
jle    11dc <rdz_read_line+0x7c>
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%al
je     11dc <rdz_read_line+0x7c>
cmp    $0xa,%al
je     11b0 <rdz_read_line+0x50>
cmp    $0x1,%ebp
jne    11b3 <rdz_read_line+0x53>
mov    %al,(%r12)
add    $0x1,%r12
mov    $0x1,%ebp
jmp    11b3 <rdz_read_line+0x53>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe02(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"cannot find source file %s\0A\00"
@EOF = global i8 0
define i8* @rdz_read_line(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = call i8* @calloc(i32 1024, i32 1)
store i8* %9, i8** %5
%10 = load i8*, i8** %5
store i8* %10, i8** %6
%11 = load i8*, i8** %3
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %3
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %2
br label %21
21: ; preds = %20, %38, %48
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 1
br i1 %23, label %24, label %25
24: ; preds = %21
br label %49
25: ; preds = %21
%26 = load i32*, i32** %7
%27 = call signext i8 @fgetc(i32* %26)
store i8 %27, i8* %8
%28 = load i8, i8* %8
%29 = sext i8 %28 to i32
%30 = load i8, i8* @EOF
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %29, %31
br i1 %32, label %33, label %34
33: ; preds = %25
br label %49
34: ; preds = %25
%35 = load i8, i8* %8
%36 = sext i8 %35 to i32
%37 = icmp eq i32 %36, 10
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = load i32, i32* %4
%40 = add nsw i32 %39, -1
store i32 %40, i32* %4
br label %21
41: ; preds = %34
%42 = load i32, i32* %4
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = load i8, i8* %8
%46 = load i8*, i8** %6
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %6
store i8 %45, i8* %46
br label %48
48: ; preds = %44, %41
br label %21
49: ; preds = %33, %24
%50 = load i32*, i32** %7
%51 = call i32 @fclose(i32* %50)
%52 = load i8*, i8** %5
ret i8* %52
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [28 x i8] c"cannot find source file %s\0A\00"
@EOF = global i8 0
define noalias i8* @rdz_read_line(i8* %0, i32 %1) {
%3 = tail call dereferenceable_or_null(1024) i8* @calloc(i32 1024, i32 1)
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = icmp slt i32 %1, 1
br i1 %7, label %30, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %6, %26
%13 = phi i32 [ %28, %26 ], [ %1, %6 ]
%14 = phi i8* [ %27, %26 ], [ %3, %6 ]
%15 = tail call signext i8 @fgetc(i32* %4)
%16 = load i8, i8* @EOF
%17 = icmp eq i8 %15, %16
br i1 %17, label %30, label %18
18: ; preds = %12
%19 = icmp eq i8 %15, 10
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = add nsw i32 %13, -1
br label %26
22: ; preds = %18
%23 = icmp eq i32 %13, 1
br i1 %23, label %24, label %26
24: ; preds = %22
%25 = getelementptr inbounds i8, i8* %14, i64 1
store i8 %15, i8* %14
br label %26
26: ; preds = %22, %24, %20
%27 = phi i8* [ %14, %20 ], [ %25, %24 ], [ %14, %22 ]
%28 = phi i32 [ %21, %20 ], [ 1, %24 ], [ %13, %22 ]
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %12
30: ; preds = %26, %12, %6
%31 = tail call i32 @fclose(i32* %4)
ret i8* %3
}