#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*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *open_file_follow_system_path(char *, char *);
char *l_findline(char *buf, int len, char *fname, long line) {
  FILE *f;
  long i;
  if ((*fname == 0) || (line < 1))
    return NULL;
  if ((f = open_file_follow_system_path(fname, "rt")) == NULL)
    return NULL;
  for (i = 0; i != line; i++)
    if (fgets(buf, len, f) == NULL) {
      fclose(f);
      return NULL;
    }
  fclose(f);
  return buf;
}


x86 assembly (clang, -O0):
<l_findline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1162 <l_findline+0x32>
cmpq   $0x1,-0x28(%rbp)
jge    116f <l_findline+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    1207 <l_findline+0xd7>
mov    -0x20(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1050 <open_file_follow_system_path@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    119a <l_findline+0x6a>
movq   $0x0,-0x8(%rbp)
jmp    1207 <l_findline+0xd7>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11f6 <l_findline+0xc6>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x30(%rbp),%rdx
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    11e0 <l_findline+0xb0>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    1207 <l_findline+0xd7>
jmp    11e5 <l_findline+0xb5>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    11a2 <l_findline+0x72>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<l_findline>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
test   %rcx,%rcx
jle    119d <l_findline+0x6d>
cmpb   $0x0,(%rdx)
je     119d <l_findline+0x6d>
mov    %rcx,%rbx
mov    %esi,%r15d
mov    %rdi,%r14
lea    0xead(%rip),%rsi
mov    %rdx,%rdi
call   1050 <open_file_follow_system_path@plt>
test   %rax,%rax
je     118b <l_findline+0x5b>
mov    %rax,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r15d,%esi
mov    %rbp,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     118f <l_findline+0x5f>
add    $0xffffffffffffffff,%rbx
jne    1170 <l_findline+0x40>
jmp    1192 <l_findline+0x62>
xor    %eax,%eax
jmp    119d <l_findline+0x6d>
xor    %r14d,%r14d
mov    %rbp,%rdi
call   1030 <fclose@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rt\00"
define i8* @l_findline(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
%7 = icmp slt i64 %3, 1
%8 = or i1 %7, %6
br i1 %8, label %22, label %9
9: ; preds = %4
%10 = tail call i32* @open_file_follow_system_path(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %22, label %14
12: ; preds = %14
%13 = icmp eq i64 %18, %3
br i1 %13, label %19, label %14
14: ; preds = %9, %12
%15 = phi i64 [ %18, %12 ], [ 0, %9 ]
%16 = tail call i32* @fgets(i8* %0, i32 %1, i32* %10)
%17 = icmp eq i32* %16, null
%18 = add nuw nsw i64 %15, 1
br i1 %17, label %19, label %12
19: ; preds = %12, %14
%20 = phi i8* [ null, %14 ], [ %0, %12 ]
%21 = tail call i32 @fclose(i32* %10)
br label %22
22: ; preds = %19, %9, %4
%23 = phi i8* [ null, %4 ], [ null, %9 ], [ %20, %19 ]
ret i8* %23
}