#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 */
scalar_t__ EAGAIN;
scalar_t__ errno;
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
void fgetfirstline(char *line, int size, FILE *fp) {
  if (fp == NULL)
    return;
  rewind(fp);
  while (fgets(line, size, fp) != NULL || errno == EAGAIN)
    ;
}


x86 assembly (clang, -O0):
<fgetfirstline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1143 <fgetfirstline+0x23>
jmp    119d <fgetfirstline+0x7d>
mov    -0x18(%rbp),%rdi
call   1030 <rewind@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1040 <fgets@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
jne    1188 <fgetfirstline+0x68>
mov    0x2e6b(%rip),%rax
mov    (%rax),%rax
mov    0x2e51(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1198 <fgetfirstline+0x78>
jmp    119d <fgetfirstline+0x7d>
jmp    114c <fgetfirstline+0x2c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetfirstline>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %rdx,%rdx
je     116c <fgetfirstline+0x4c>
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    %rdx,%rdi
call   1030 <rewind@plt>
mov    0x2e9b(%rip),%r15
mov    0x2e84(%rip),%r12
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1150 <fgetfirstline+0x30>
mov    (%r12),%rax
cmp    %rax,(%r15)
je     1150 <fgetfirstline+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EAGAIN = global i64 0
define void @fgetfirstline(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%7 = load i32*, i32** %6
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %3
br label %26
10: ; preds = %3
%11 = load i32*, i32** %6
%12 = call i32 @rewind(i32* %11)
br label %13
13: ; preds = %25, %10
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = load i32*, i32** %6
%17 = call i32* @fgets(i8* %14, i32 %15, i32* %16)
%18 = icmp ne i32* %17, null
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = load i64, i64* @errno
%21 = load i64, i64* @EAGAIN
%22 = icmp eq i64 %20, %21
br label %23
23: ; preds = %19, %13
%24 = phi i1 [ true, %13 ], [ %22, %19 ]
br i1 %24, label %25, label %26
25: ; preds = %23
br label %13
26: ; preds = %9, %23
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@EAGAIN = global i64 0
define void @fgetfirstline(i8* %0, i32 %1, i32* %2) {
%4 = icmp eq i32* %2, null
br i1 %4, label %14, label %5
5: ; preds = %3
%6 = tail call i32 @rewind(i32* %2)
br label %7
7: ; preds = %7, %5
%8 = tail call i32* @fgets(i8* %0, i32 %1, i32* %2)
%9 = icmp ne i32* %8, null
%10 = load i64, i64* @errno
%11 = load i64, i64* @EAGAIN
%12 = icmp eq i64 %10, %11
%13 = select i1 %9, i1 true, i1 %12
br i1 %13, label %7, label %14
14: ; preds = %7, %3
ret void
}