#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__ feof(int /*<<< orphan*/ *);
char *fgets(char *, size_t const, int /*<<< orphan*/ *);
scalar_t__ strlen(char *);
int super_chop(char *, int const);
int fgetl(FILE *fd, const size_t sz, char *buf) {
  if (feof(fd))
    return -1;
  char *s = fgets(buf, sz - 1, fd);
  if (s == NULL)
    return -1;
  const int len = (const int)strlen(s);
  return super_chop(s, len);
}


x86 assembly (clang, -O0):
<fgetl>:
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   1050 <feof@plt>
cmp    $0x0,%rax
je     1173 <fgetl+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <fgetl+0x7e>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
sub    $0x1,%rsi
mov    -0x10(%rbp),%rdx
call   1040 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a3 <fgetl+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <fgetl+0x7e>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1060 <super_chop@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetl>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1050 <feof@plt>
test   %rax,%rax
je     1163 <fgetl+0x23>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
add    $0xffffffffffffffff,%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1158 <fgetl+0x18>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %eax,%esi
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <super_chop@plt>

LLVM IR (-O0):
define i32 @fgetl(i32* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
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 = sub i64 %16, 1
%18 = load i32*, i32** %5
%19 = call i8* @fgets(i8* %15, i64 %17, i32* %18)
store i8* %19, i8** %8
%20 = load i8*, i8** %8
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %14
store i32 -1, i32* %4
br label %30
23: ; preds = %14
%24 = load i8*, i8** %8
%25 = call i64 @strlen(i8* %24)
%26 = trunc i64 %25 to i32
store i32 %26, i32* %9
%27 = load i8*, i8** %8
%28 = load i32, i32* %9
%29 = call i32 @super_chop(i8* %27, i32 %28)
store i32 %29, i32* %4
br label %30
30: ; preds = %23, %22, %13
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
define i32 @fgetl(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 %14
6: ; preds = %3
%7 = add i64 %1, -1
%8 = tail call i8* @fgets(i8* %2, i64 %7, i32* %0)
%9 = icmp eq i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %6
%11 = tail call i64 @strlen(i8* %8)
%12 = trunc i64 %11 to i32
%13 = tail call i32 @super_chop(i8* %8, i32 %12)
br label %14
14: ; preds = %10, %6, %3
%15 = phi i32 [ -1, %3 ], [ %13, %10 ], [ -1, %6 ]
ret i32 %15
}