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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
bool ace_tu_fs_does_file_contain_line_at(int expected_line_number,
                                         char *filepath,
                                         char *str_without_linebreak) {
  FILE *file;
  char *line = NULL;
  int line_number = 0;
  ssize_t line_length;
  size_t buffer_length = 0;
  bool does_line_number_match;
  bool result = false;
  file = fopen(filepath, "r");
  while ((line_length = getline(&line, &buffer_length, file)) != -1) {
    line_number++;
    line[strlen(line) - 1] = '\0';
    does_line_number_match =
        (line_number == expected_line_number) || (expected_line_number <= 0);
    if (does_line_number_match && (strcmp(line, str_without_linebreak) == 0)) {
      result = true;
      break;
    }
  }
  fclose(file);
  if (line)
    free(line);
  return result;
}


x86 assembly (clang, -O0):
<ace_tu_fs_does_file_contain_line_at>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe64(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdx
lea    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1080 <getline@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
je     1244 <ace_tu_fs_does_file_contain_line_at+0xe4>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x2c(%rbp),%ecx
mov    $0x1,%al
cmp    -0x4(%rbp),%ecx
mov    %al,-0x41(%rbp)
je     1207 <ace_tu_fs_does_file_contain_line_at+0xa7>
cmpl   $0x0,-0x4(%rbp)
setle  %al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
je     123f <ace_tu_fs_does_file_contain_line_at+0xdf>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    123f <ace_tu_fs_does_file_contain_line_at+0xdf>
movl   $0x1,-0x40(%rbp)
jmp    1244 <ace_tu_fs_does_file_contain_line_at+0xe4>
jmp    11a5 <ace_tu_fs_does_file_contain_line_at+0x45>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x28(%rbp)
je     1261 <ace_tu_fs_does_file_contain_line_at+0x101>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x40(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ace_tu_fs_does_file_contain_line_at>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,%rax
mov    %edi,%ebp
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe70(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
mov    %rax,%rdx
call   1080 <getline@plt>
xor    %r14d,%r14d
cmp    $0xffffffff,%eax
je     1226 <ace_tu_fs_does_file_contain_line_at+0xc6>
lea    -0x1(%rbp),%r15d
mov    %rsp,%r12
lea    0x8(%rsp),%r13
jmp    11f6 <ace_tu_fs_does_file_contain_line_at+0x96>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rdi
mov    0x10(%rsp),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1220 <ace_tu_fs_does_file_contain_line_at+0xc0>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1080 <getline@plt>
cmp    $0xffffffff,%eax
je     121b <ace_tu_fs_does_file_contain_line_at+0xbb>
mov    (%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
sub    $0x1,%r15d
setb   %cl
cltq
movb   $0x0,-0x1(%rax,%r14,1)
test   %ebp,%ebp
jle    11d0 <ace_tu_fs_does_file_contain_line_at+0x70>
test   %cl,%cl
je     11e3 <ace_tu_fs_does_file_contain_line_at+0x83>
jmp    11d0 <ace_tu_fs_does_file_contain_line_at+0x70>
xor    %r14d,%r14d
jmp    1226 <ace_tu_fs_does_file_contain_line_at+0xc6>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     123c <ace_tu_fs_does_file_contain_line_at+0xdc>
call   1030 <free@plt>
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @ace_tu_fs_does_file_contain_line_at(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i8* null, i8** %8
store i32 0, i32* %9
store i64 0, i64* %11
store i32 0, i32* %13
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %7
br label %16
16: ; preds = %46, %3
%17 = load i32*, i32** %7
%18 = call i32 @getline(i8** %8, i64* %11, i32* %17)
store i32 %18, i32* %10
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %47
20: ; preds = %16
%21 = load i32, i32* %9
%22 = add nsw i32 %21, 1
store i32 %22, i32* %9
%23 = load i8*, i8** %8
%24 = load i8*, i8** %8
%25 = call i32 @strlen(i8* %24)
%26 = sub nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %23, i64 %27
store i8 0, i8* %28
%29 = load i32, i32* %9
%30 = load i32, i32* %4
%31 = icmp eq i32 %29, %30
br i1 %31, label %35, label %32
32: ; preds = %20
%33 = load i32, i32* %4
%34 = icmp sle i32 %33, 0
br label %35
35: ; preds = %32, %20
%36 = phi i1 [ true, %20 ], [ %34, %32 ]
%37 = zext i1 %36 to i32
store i32 %37, i32* %12
%38 = load i32, i32* %12
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %35
%41 = load i8*, i8** %8
%42 = load i8*, i8** %6
%43 = call i64 @strcmp(i8* %41, i8* %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %40
store i32 1, i32* %13
br label %47
46: ; preds = %40, %35
br label %16
47: ; preds = %45, %16
%48 = load i32*, i32** %7
%49 = call i32 @fclose(i32* %48)
%50 = load i8*, i8** %8
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = load i8*, i8** %8
%54 = call i32 @free(i8* %53)
br label %55
55: ; preds = %52, %47
%56 = load i32, i32* %13
ret i32 %56
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @ace_tu_fs_does_file_contain_line_at(i32 %0, i8* nocapture %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%7 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%8 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @getline(i8** %4, i64* %5, i32* %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %30, label %11
11: ; preds = %3
%12 = icmp slt i32 %0, 1
br label %13
13: ; preds = %11, %27
%14 = phi i32 [ 0, %11 ], [ %15, %27 ]
%15 = add nuw nsw i32 %14, 1
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* %16)
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %16, i64 %19
store i8 0, i8* %20
%21 = icmp eq i32 %15, %0
%22 = or i1 %12, %21
br i1 %22, label %23, label %27
23: ; preds = %13
%24 = load i8*, i8** %4
%25 = call i64 @strcmp(i8* %24, i8* %2)
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %23, %13
%28 = call i32 @getline(i8** %4, i64* %5, i32* %8)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %13
30: ; preds = %27, %23, %3
%31 = phi i32 [ 0, %3 ], [ 1, %23 ], [ 0, %27 ]
%32 = call i32 @fclose(i32* %8)
%33 = load i8*, i8** %4
%34 = icmp eq i8* %33, null
br i1 %34, label %37, label %35
35: ; preds = %30
%36 = call i32 @free(i8* %33)
br label %37
37: ; preds = %35, %30
ret i32 %31
}