#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 *fh_in, size_t size, char *buffer) {
  static size_t len;
  static char *buffptr;
  if (feof(fh_in))
    return -1;
  buffptr = fgets(buffer, size, fh_in);
  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    $0x20,%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    11dc <fgetline+0x9c>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <fgets@plt>
mov    %rax,0x2ec5(%rip)
cmpq   $0x0,0x2ebd(%rip)
jne    11a5 <fgetline+0x65>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dc <fgetline+0x9c>
mov    0x2ea4(%rip),%rdi
call   1030 <strlen@plt>
mov    %rax,0x2e90(%rip)
mov    0x2e91(%rip),%rdi
mov    0x2e82(%rip),%rsi
call   1040 <chop@plt>
mov    %rax,0x2e76(%rip)
mov    0x2e6f(%rip),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%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    1194 <fgetline+0x54>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1050 <fgets@plt>
mov    %rax,0x2ed2(%rip)
test   %rax,%rax
je     1194 <fgetline+0x54>
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):
@fgetline.len = internal global i64 0
@fgetline.buffptr = internal global i8* null
define i32 @fgetline(i32* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
store i32* %0, i32** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
%8 = load i32*, i32** %5
%9 = call i64 @feof(i32* %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 -1, i32* %4
br label %28
12: ; preds = %3
%13 = load i8*, i8** %7
%14 = load i64, i64* %6
%15 = load i32*, i32** %5
%16 = call i8* @fgets(i8* %13, i64 %14, i32* %15)
store i8* %16, i8** @fgetline.buffptr
%17 = load i8*, i8** @fgetline.buffptr
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 -1, i32* %4
br label %28
20: ; preds = %12
%21 = load i8*, i8** @fgetline.buffptr
%22 = call i64 @strlen(i8* %21)
store i64 %22, i64* @fgetline.len
%23 = load i8*, i8** @fgetline.buffptr
%24 = load i64, i64* @fgetline.len
%25 = call i64 @chop(i8* %23, i64 %24)
store i64 %25, i64* @fgetline.len
%26 = load i64, i64* @fgetline.len
%27 = trunc i64 %26 to i32
store i32 %27, i32* %4
br label %28
28: ; preds = %20, %19, %11
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
@fgetline.buffptr = internal unnamed_addr global i8* null
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)
store i8* %7, i8** @fgetline.buffptr
%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
}