#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int file_goto_first_line(const char *fpath, char *line, int line_size) {
  FILE *fp;
  int status = -1;
  memset(line, 0, line_size);
  fp = fopen(fpath, "r");
  if (fp) {
    if (!feof(fp)) {
      status = (NULL != fgets(line, line_size, fp)) ? 0 : -1;
    }
    fclose(fp);
  }
  return status;
}


x86 assembly (clang, -O0):
<file_goto_first_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0xffffffff,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d9 <file_goto_first_line+0x89>
mov    -0x20(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
jne    11d0 <file_goto_first_line+0x80>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    %rsi,%rdx
cmovne %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_goto_first_line>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
mov    %rsi,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     11b0 <file_goto_first_line+0x60>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <feof@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
jne    11a6 <file_goto_first_line+0x56>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbp,%rdx
call   1050 <fgets@plt>
cmp    $0x1,%rax
sbb    %ebx,%ebx
mov    %rbp,%rdi
call   1030 <fclose@plt>
jmp    11b5 <file_goto_first_line+0x65>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @file_goto_first_line(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 -1, i32* %8
%9 = load i8*, i8** %5
%10 = load i32, i32* %6
%11 = call i32 @memset(i8* %9, i32 0, i32 %10)
%12 = load i8*, i8** %4
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %7
%14 = load i32*, i32** %7
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %31
16: ; preds = %3
%17 = load i32*, i32** %7
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %28, label %20
20: ; preds = %16
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = load i32*, i32** %7
%24 = call i32* @fgets(i8* %21, i32 %22, i32* %23)
%25 = icmp ne i32* null, %24
%26 = zext i1 %25 to i64
%27 = select i1 %25, i32 0, i32 -1
store i32 %27, i32* %8
br label %28
28: ; preds = %20, %16
%29 = load i32*, i32** %7
%30 = call i32 @fclose(i32* %29)
br label %31
31: ; preds = %28, %3
%32 = load i32, i32* %8
ret i32 %32
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @file_goto_first_line(i8* nocapture %0, i8* %1, i32 %2) {
%4 = tail call i32 @memset(i8* %1, i32 0, i32 %2)
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %17, label %7
7: ; preds = %3
%8 = tail call i32 @feof(i32* %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call i32* @fgets(i8* %1, i32 %2, i32* %5)
%12 = icmp eq i32* %11, null
%13 = sext i1 %12 to i32
br label %14
14: ; preds = %10, %7
%15 = phi i32 [ -1, %7 ], [ %13, %10 ]
%16 = tail call i32 @fclose(i32* %5)
br label %17
17: ; preds = %14, %3
%18 = phi i32 [ %15, %14 ], [ -1, %3 ]
ret i32 %18
}