#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, int /*<<< orphan*/ *);
size_t strlen(char *);
size_t super_chop(char *, size_t);
int fgetl(FILE *stream, size_t sz, char *buf) {
  if (feof(stream))
    return -1;
  char *s = fgets(buf, sz, stream);
  if (s == NULL)
    return -1;
  size_t len = strlen(s);
  len = super_chop(s, len);
  return 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    11c4 <fgetl+0x84>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1040 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119f <fgetl+0x5f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c4 <fgetl+0x84>
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1060 <super_chop@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fgetl>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <feof@plt>
mov    $0xffffffff,%r15d
test   %rax,%rax
jne    118d <fgetl+0x4d>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     118d <fgetl+0x4d>
mov    %rax,%r14
mov    %rax,%rdi
call   1030 <strlen@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <super_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 @fgetl(i32* %0, i64 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
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** %8
%19 = load i8*, i8** %8
%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** %8
%24 = call i64 @strlen(i8* %23)
store i64 %24, i64* %9
%25 = load i8*, i8** %8
%26 = load i64, i64* %9
%27 = call i64 @super_chop(i8* %25, i64 %26)
store i64 %27, i64* %9
%28 = load i64, i64* %9
%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 @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 %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 @super_chop(i8* %7, i64 %10)
%12 = trunc i64 %11 to i32
br label %13
13: ; preds = %9, %6, %3
%14 = phi i32 [ -1, %3 ], [ %12, %9 ], [ -1, %6 ]
ret i32 %14
}