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

/* Variables and functions */
int getline(char **, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
char *dash_read_line(void) {
  char *line = NULL;
  ssize_t bufsize = 0;
  int chars = getline(&line, &bufsize, stdin);
  if ((line)[chars - 1] == '\n') {
    (line)[chars - 1] = '\0';
    --chars;
  }
  return line;
}


x86 assembly (clang, -O0):
<dash_read_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2eba(%rip),%rax
mov    (%rax),%edx
lea    -0x8(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1030 <getline@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1174 <dash_read_line+0x64>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dash_read_line>:
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movl   $0x0,0x14(%rsp)
mov    0x2ebc(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x14(%rsp),%rsi
call   1030 <getline@plt>
mov    %eax,%ecx
mov    0x8(%rsp),%rax
movslq %ecx,%rcx
cmpb   $0xa,-0x1(%rcx,%rax,1)
jne    1158 <dash_read_line+0x48>
movb   $0x0,-0x1(%rax,%rcx,1)
mov    0x8(%rsp),%rax
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
@stdin = global i32 0
define i8* @dash_read_line() {
%1 = alloca i8*
%2 = alloca i32
%3 = bitcast i8** %1 to i8*
store i8* null, i8** %1
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = load i32, i32* @stdin
%6 = call i32 @getline(i8** %1, i32* %2, i32 %5)
%7 = load i8*, i8** %1
%8 = add nsw i32 %6, -1
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 10
br i1 %12, label %13, label %15
13: ; preds = %0
store i8 0, i8* %10
%14 = load i8*, i8** %1
br label %15
15: ; preds = %13, %0
%16 = phi i8* [ %14, %13 ], [ %7, %0 ]
ret i8* %16
}