#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*/ abort();
int /*<<< orphan*/ fgets(char *, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ isspace(char);
int /*<<< orphan*/ stderr;
size_t strlen(char *);
int getl(char *buf, size_t size, FILE *f) {
  if (!fgets(buf, size, f))
    return -1;
  size_t len = strlen(buf);
  if (len + 1 == size) {
    fprintf(stderr, "input line is too long, increase buffer size!\n");
    abort();
  }
  while (len > 0 && isspace(buf[len - 1]))
    --len;
  buf[len] = 0;
  return len;
}


x86 assembly (clang, -O0):
<getl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <fgets@plt>
cmp    $0x0,%eax
jne    118a <getl+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    122d <getl+0xdd>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
cmp    -0x18(%rbp),%rax
jne    11c5 <getl+0x75>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    11ca <getl+0x7a>
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x29(%rbp)
jbe    11f9 <getl+0xa9>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1209 <getl+0xb9>
jmp    121a <getl+0xca>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
jmp    11ca <getl+0x7a>
mov    -0x10(%rbp),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getl>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
call   1060 <fgets@plt>
test   %eax,%eax
je     11a0 <getl+0x50>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
add    $0x1,%rax
cmp    %r15,%rax
je     11af <getl+0x5f>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%r15
sub    $0x1,%rbx
jb     1199 <getl+0x49>
movsbl -0x1(%r14,%r15,1),%edi
call   1050 <isspace@plt>
test   %rax,%rax
jne    1180 <getl+0x30>
movb   $0x0,(%r14,%r15,1)
jmp    11a6 <getl+0x56>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [47 x i8] c"input line is too long, increase buffer size!\0A\00"
define i32 @getl(i8* %0, i64 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32*
%8 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32* %2, i32** %7
%9 = load i8*, i8** %5
%10 = load i64, i64* %6
%11 = load i32*, i32** %7
%12 = call i32 @fgets(i8* %9, i64 %10, i32* %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %3
store i32 -1, i32* %4
br label %49
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = call i64 @strlen(i8* %16)
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = add i64 %18, 1
%20 = load i64, i64* %6
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%25 = call i32 (...) @abort()
unreachable
26: ; preds = %15
br label %27
27: ; preds = %40, %26
%28 = load i64, i64* %8
%29 = icmp ugt i64 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load i8*, i8** %5
%32 = load i64, i64* %8
%33 = sub i64 %32, 1
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %34
%36 = call i64 @isspace(i8 signext %35)
%37 = icmp ne i64 %36, 0
br label %38
38: ; preds = %30, %27
%39 = phi i1 [ false, %27 ], [ %37, %30 ]
br i1 %39, label %40, label %43
40: ; preds = %38
%41 = load i64, i64* %8
%42 = add i64 %41, -1
store i64 %42, i64* %8
br label %27
43: ; preds = %38
%44 = load i8*, i8** %5
%45 = load i64, i64* %8
%46 = getelementptr inbounds i8, i8* %44, i64 %45
store i8 0, i8* %46
%47 = load i64, i64* %8
%48 = trunc i64 %47 to i32
store i32 %48, i32* %4
br label %49
49: ; preds = %43, %14
%50 = load i32, i32* %4
ret i32 %50
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [47 x i8] c"input line is too long, increase buffer size!\0A\00"
define i32 @getl(i8* %0, i64 %1, i32* nocapture %2) {
%4 = tail call i32 @fgets(i8* %0, i64 %1, i32* %2)
%5 = icmp eq i32 %4, 0
br i1 %5, label %26, label %6
6: ; preds = %3
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = add i64 %7, 1
%9 = icmp eq i64 %8, %1
br i1 %9, label %10, label %14
10: ; preds = %6
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 (...) @abort()
unreachable
14: ; preds = %6, %17
%15 = phi i64 [ %18, %17 ], [ %7, %6 ]
%16 = icmp eq i64 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %14
%18 = add i64 %15, -1
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = tail call i64 @isspace(i8 signext %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %14
23: ; preds = %14, %17
%24 = getelementptr inbounds i8, i8* %0, i64 %15
store i8 0, i8* %24
%25 = trunc i64 %15 to i32
br label %26
26: ; preds = %3, %23
%27 = phi i32 [ %25, %23 ], [ -1, %3 ]
ret i32 %27
}