#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 */
size_t chop(char *, size_t);
scalar_t__ feof(int /*<<< orphan*/ *);
char *fgets(char *, size_t, int /*<<< orphan*/ *);
size_t strlen(char *);
int fgetline(FILE *inputstream, size_t size, char *buffer) {
  size_t len;
  char *buffptr;
  if (feof(inputstream))
    return -1;
  buffptr = fgets(buffer, size, inputstream);
  if (buffptr == NULL)
    return -1;
  len = strlen(buffptr);
  len = chop(buffptr, len);
  return len;
}


x86 assembly (clang, -O0):
<fgetline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%rax
je     1173 <fgetline+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <fgetline+0x84>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    119f <fgetline+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <fgetline+0x84>
mov    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <chop@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetline>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <feof@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
jne    118d <fgetline+0x4d>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     118d <fgetline+0x4d>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <chop@plt>
mov    %rax,%r15
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @fgetline(i32* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
store i32* %0, i32** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%10 = load i32*, i32** %5
%11 = call i64 @feof(i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %30
14: ; preds = %3
%15 = load i8*, i8** %7
%16 = load i64, i64* %6
%17 = load i32*, i32** %5
%18 = call i8* @fgets(i8* %15, i64 %16, i32* %17)
store i8* %18, i8** %9
%19 = load i8*, i8** %9
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %22
21: ; preds = %14
store i32 -1, i32* %4
br label %30
22: ; preds = %14
%23 = load i8*, i8** %9
%24 = call i64 @strlen(i8* %23)
store i64 %24, i64* %8
%25 = load i8*, i8** %9
%26 = load i64, i64* %8
%27 = call i64 @chop(i8* %25, i64 %26)
store i64 %27, i64* %8
%28 = load i64, i64* %8
%29 = trunc i64 %28 to i32
store i32 %29, i32* %4
br label %30
30: ; preds = %22, %21, %13
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @fgetline(i32* nocapture %0, i64 %1, i8* %2) {
%4 = tail call i64 @feof(i32* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = tail call i8* @fgets(i8* %2, i64 %1, i32* %0)
%8 = icmp eq i8* %7, null
br i1 %8, label %13, label %9
9: ; preds = %6
%10 = tail call i64 @strlen(i8* %7)
%11 = tail call i64 @chop(i8* %7, i64 %10)
%12 = trunc i64 %11 to i32
br label %13
13: ; preds = %6, %3, %9
%14 = phi i32 [ %12, %9 ], [ -1, %3 ], [ -1, %6 ]
ret i32 %14
}