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

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strerror(int /*<<< orphan*/);
char *input(char *prompt) {
  printf("%s ", prompt);
  char *buffer = NULL;
  size_t n = 0;
  ssize_t buffer_length = getline(&buffer, &n, stdin);
  if (buffer_length < 0) {
    fprintf(stderr, "%s: %s\n", "getline", strerror(errno));
  } else if (buffer[buffer_length - 1] == '\n') {
    buffer[buffer_length - 1] = '\0';
  }
  return buffer;
}


x86 assembly (clang, -O0):
<input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    11c7 <input+0x87>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rcx
lea    0xe4e(%rip),%rsi
lea    0xe4f(%rip),%rdx
call   1040 <fprintf@plt>
jmp    11f7 <input+0xb7>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11f2 <input+0xb2>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11f7 <input+0xb7>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rsi
lea    0xeb1(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,(%rsp)
movq   $0x0,0x8(%rsp)
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1050 <getline@plt>
test   %eax,%eax
js     1193 <input+0x53>
mov    (%rsp),%rcx
cltq
cmpb   $0xa,-0x1(%rax,%rcx,1)
jne    11c2 <input+0x82>
movb   $0x0,-0x1(%rcx,%rax,1)
jmp    11c2 <input+0x82>
mov    0x2e3e(%rip),%rax
mov    (%rax),%ebx
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe53(%rip),%rsi
lea    0xe54(%rip),%rdx
mov    %ebx,%edi
mov    %rax,%rcx
call   1040 <fprintf@plt>
mov    (%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@.str.2 = [8 x i8] c"getline\00"
@errno = global i32 0
define i8* @input(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %6)
store i8* null, i8** %3
store i64 0, i64* %4
%8 = load i32, i32* @stdin
%9 = call i32 @getline(i8** %3, i64* %4, i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %15)
br label %33
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %32
26: ; preds = %17
%27 = load i8*, i8** %3
%28 = load i32, i32* %5
%29 = sub nsw i32 %28, 1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %27, i64 %30
store i8 0, i8* %31
br label %32
32: ; preds = %26, %17
br label %33
33: ; preds = %32, %12
%34 = load i8*, i8** %3
ret i8* %34
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s \00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@.str.2 = [8 x i8] c"getline\00"
@errno = global i32 0
define i8* @input(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%6 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%7 = load i32, i32* @stdin
%8 = call i32 @getline(i8** %2, i64* %3, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %23
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = add nsw i32 %8, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 10
br i1 %21, label %22, label %23
22: ; preds = %15
store i8 0, i8* %19
br label %23
23: ; preds = %15, %22, %10
%24 = load i8*, i8** %2
ret i8* %24
}