#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
char *read_line(int /*<<< orphan*/ *);
int /*<<< orphan*/ smb___free(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int test_read_line(void) {
  FILE *f = fopen("res/file.txt", "r");
  int i = 0;
  char *lines[] = {"This is the first line of my file.",
                   "This is the second line of my file.", ""};
  char *line;
  while (!feof(f)) {
    line = read_line(f);
    do {
      if (strcmp((lines[i]), (line)) != 0) {
        fprintf(stderr, "Assertion failed: \"%s\" != \"%s\"\n", lines[i], line);
        return 65;
      }
    } while (0);
    smb___free(line);
    i++;
  }
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<test_read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xe81(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2c63(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c60(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c5d(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d5 <test_read_line+0x65>
jmp    1248 <test_read_line+0xd8>
mov    -0x10(%rbp),%rdi
call   1080 <read_line@plt>
mov    %rax,-0x38(%rbp)
movslq -0x14(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     122c <test_read_line+0xbc>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
movslq -0x14(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdx
mov    -0x38(%rbp),%rcx
lea    0xe3b(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x41,-0x4(%rbp)
jmp    1258 <test_read_line+0xe8>
jmp    1231 <test_read_line+0xc1>
mov    -0x38(%rbp),%rdi
call   1030 <smb___free@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b7 <test_read_line+0x47>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_read_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe81(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    11e6 <test_read_line+0x76>
lea    0x2c5f(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1080 <read_line@plt>
mov    %rax,%r12
mov    (%rbx),%r15
mov    %r15,%rdi
mov    %rax,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11f2 <test_read_line+0x82>
mov    %r12,%rdi
call   1030 <smb___free@plt>
mov    %r14,%rdi
call   1070 <feof@plt>
add    $0x8,%rbx
test   %eax,%eax
je     11b0 <test_read_line+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1212 <test_read_line+0xa2>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1060 <fprintf@plt>
mov    $0x41,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"res/file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [35 x i8] c"This is the first line of my file.\00"
@.str.3 = [36 x i8] c"This is the second line of my file.\00"
@.str.4 = [1 x i8] zeroinitializer
@__const.test_read_line.lines = [3 x i8*] [i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i32 0, i32 0)]
@stderr = global i32 0
@.str.5 = [32 x i8] c"Assertion failed: \22%s\22 != \22%s\22\0A\00"
define i32 @test_read_line() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
%4 = alloca [3 x i8*]
%5 = alloca i8*
%6 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %2
store i32 0, i32* %3
%7 = bitcast [3 x i8*]* %4 to i8*
br label %8
8: ; preds = %33, %0
%9 = load i32*, i32** %2
%10 = call i32 @feof(i32* %9)
%11 = icmp ne i32 %10, 0
%12 = xor i1 %11, true
br i1 %12, label %13, label %38
13: ; preds = %8
%14 = load i32*, i32** %2
%15 = call i8* @read_line(i32* %14)
store i8* %15, i8** %5
br label %16
16: ; preds = %13
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 %18
%20 = load i8*, i8** %19
%21 = load i8*, i8** %5
%22 = call i64 @strcmp(i8* %20, i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 %27
%29 = load i8*, i8** %28
%30 = load i8*, i8** %5
%31 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %29, i8* %30)
store i32 65, i32* %1
br label %41
32: ; preds = %16
br label %33
33: ; preds = %32
%34 = load i8*, i8** %5
%35 = call i32 @smb___free(i8* %34)
%36 = load i32, i32* %3
%37 = add nsw i32 %36, 1
store i32 %37, i32* %3
br label %8
38: ; preds = %8
%39 = load i32*, i32** %2
%40 = call i32 @fclose(i32* %39)
store i32 0, i32* %1
br label %41
41: ; preds = %38, %24
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str = [13 x i8] c"res/file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [35 x i8] c"This is the first line of my file.\00"
@.str.3 = [36 x i8] c"This is the second line of my file.\00"
@.str.4 = [1 x i8] zeroinitializer
@__const.test_read_line.lines = [3 x i8*] [i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i32 0, i32 0)]
@stderr = global i32 0
@.str.5 = [32 x i8] c"Assertion failed: \22%s\22 != \22%s\22\0A\00"
define i32 @test_read_line() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i32 @feof(i32* %1)
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %19
4: ; preds = %0, %14
%5 = phi i64 [ %16, %14 ], [ 0, %0 ]
%6 = tail call i8* @read_line(i32* %1)
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* @__const.test_read_line.lines, i64 0, i64 %5
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* %6)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i8* %8, i8* %6)
br label %21
14: ; preds = %4
%15 = tail call i32 @smb___free(i8* %6)
%16 = add nuw i64 %5, 1
%17 = tail call i32 @feof(i32* %1)
%18 = icmp eq i32 %17, 0
br i1 %18, label %4, label %19
19: ; preds = %14, %0
%20 = tail call i32 @fclose(i32* %1)
br label %21
21: ; preds = %19, %11
%22 = phi i32 [ 65, %11 ], [ 0, %19 ]
ret i32 %22
}