#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*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int line(FILE *f, char *buf, int eofok) {
  char *p;
  if (fgets(buf, 1000, f) == 0) {
    if (eofok)
      return 0;
    fprintf(stderr, "unexpected EOF\n");
    exit(1);
  }
  p = buf + strlen(buf);
  p--;
  if (p >= buf && *p == '\n')
    *p = '\0';
  return 1;
}


x86 assembly (clang, -O0):
<line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x3e8,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    11a4 <line+0x64>
cmpl   $0x0,-0x1c(%rbp)
je     1185 <line+0x45>
movl   $0x0,-0x4(%rbp)
jmp    11fd <line+0xbd>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
lea    0xe6b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     11f6 <line+0xb6>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
jne    11f6 <line+0xb6>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<line>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%rdx
mov    %rsi,%rdi
mov    $0x3e8,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     1183 <line+0x43>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rcx
add    $0xffffffffffffffff,%rcx
mov    $0x1,%eax
cmp    %rbx,%rcx
jb     1189 <line+0x49>
cmpb   $0xa,(%rcx)
jne    1189 <line+0x49>
movb   $0x0,(%rcx)
jmp    1189 <line+0x49>
xor    %eax,%eax
test   %ebp,%ebp
je     1190 <line+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [16 x i8] c"unexpected EOF\0A\00"
define i32 @line(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i32* %0, i32** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %6
%10 = load i32*, i32** %5
%11 = call i64 @fgets(i8* %9, i32 1000, i32* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %3
%14 = load i32, i32* %7
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 0, i32* %4
br label %40
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %3
%22 = load i8*, i8** %6
%23 = load i8*, i8** %6
%24 = call i32 @strlen(i8* %23)
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = getelementptr inbounds i8, i8* %27, i32 -1
store i8* %28, i8** %8
%29 = load i8*, i8** %8
%30 = load i8*, i8** %6
%31 = icmp uge i8* %29, %30
br i1 %31, label %32, label %39
32: ; preds = %21
%33 = load i8*, i8** %8
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 10
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = load i8*, i8** %8
store i8 0, i8* %38
br label %39
39: ; preds = %37, %32, %21
store i32 1, i32* %4
br label %40
40: ; preds = %39, %16
%41 = load i32, i32* %4
ret i32 %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [16 x i8] c"unexpected EOF\0A\00"
define i32 @line(i32* nocapture %0, i8* %1, i32 %2) {
%4 = tail call i64 @fgets(i8* %1, i32 1000, i32* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = icmp eq i32 %2, 0
br i1 %7, label %8, label %22
8: ; preds = %6
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %3
%13 = tail call i32 @strlen(i8* %1)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = getelementptr inbounds i8, i8* %15, i64 -1
%17 = icmp ult i8* %16, %1
br i1 %17, label %22, label %18
18: ; preds = %12
%19 = load i8, i8* %16
%20 = icmp eq i8 %19, 10
br i1 %20, label %21, label %22
21: ; preds = %18
store i8 0, i8* %16
br label %22
22: ; preds = %12, %18, %21, %6
%23 = phi i32 [ 0, %6 ], [ 1, %21 ], [ 1, %18 ], [ 1, %12 ]
ret i32 %23
}