#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 */

/* Variables and functions */
scalar_t__ BUFSIZ;
char *fgets(char *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int strlen(char *);
char *fline(char *f) {
  int n;
  char *r;
  r = fgets(f, BUFSIZ - 1, stdin);
  if (r != NULL) {
    n = strlen(f);
    if (n > 0)
      f[n - 1] = '\0';
  }
  return r;
}


x86 assembly (clang, -O0):
<fline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%rsi
sub    $0x1,%rsi
mov    0x2ea3(%rip),%rax
mov    (%rax),%edx
call   1040 <fgets@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1187 <fline+0x67>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1182 <fline+0x62>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1187 <fline+0x67>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fline>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eaa(%rip),%rax
mov    (%rax),%rsi
add    $0xffffffffffffffff,%rsi
mov    0x2eac(%rip),%rax
mov    (%rax),%edx
call   1040 <fgets@plt>
mov    %rax,%rbx
test   %rax,%rax
je     115f <fline+0x3f>
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    115f <fline+0x3f>
add    $0xffffffff,%eax
movb   $0x0,(%r14,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@BUFSIZ = global i64 0
@stdin = global i32 0
define i8* @fline(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i64, i64* @BUFSIZ
%7 = sub nsw i64 %6, 1
%8 = load i32, i32* @stdin
%9 = call i8* @fgets(i8* %5, i64 %7, i32 %8)
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %24
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %12
%18 = load i8*, i8** %2
%19 = load i32, i32* %3
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
store i8 0, i8* %22
br label %23
23: ; preds = %17, %12
br label %24
24: ; preds = %23, %1
%25 = load i8*, i8** %4
ret i8* %25
}

LLVM IR (-O2):
@BUFSIZ = global i64 0
@stdin = global i32 0
define i8* @fline(i8* %0) {
%2 = load i64, i64* @BUFSIZ
%3 = add nsw i64 %2, -1
%4 = load i32, i32* @stdin
%5 = tail call i8* @fgets(i8* %0, i64 %3, i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = add nsw i32 %8, -1
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 0, i8* %13
br label %14
14: ; preds = %7, %10, %1
ret i8* %5
}