#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*/ fflush(int /*<<< orphan*/);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *readline(const char *prompt) {
  char *line = NULL;
  size_t n = 0;
  ssize_t bytes_read;
  printf("%s", prompt);
  fflush(stdout);
  bytes_read = getline(&line, &n, stdin);
  if (bytes_read > 0)
    line[bytes_read - 1] = '\0';
  return line;
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    0x2e77(%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)
jle    119e <readline+0x6e>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
sub    $0x18,%rsp
mov    %rdi,%rsi
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1050 <getline@plt>
test   %eax,%eax
jle    118b <readline+0x5b>
mov    0x8(%rsp),%rcx
add    $0xffffffff,%eax
movb   $0x0,(%rcx,%rax,1)
mov    0x8(%rsp),%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@stdout = global i32 0
@stdin = global i32 0
define i8* @readline(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i8* %0, i8** %2
store i8* null, i8** %3
store i64 0, i64* %4
%6 = load i8*, i8** %2
%7 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @stdout
%9 = call i32 @fflush(i32 %8)
%10 = load i32, i32* @stdin
%11 = call i32 @getline(i8** %3, i64* %4, i32 %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = load i32, i32* %5
%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
br label %20
20: ; preds = %14, %1
%21 = load i8*, i8** %3
ret i8* %21
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@stdout = global i32 0
@stdin = global i32 0
define i8* @readline(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%6 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = load i32, i32* @stdout
%8 = tail call i32 @fflush(i32 %7)
%9 = load i32, i32* @stdin
%10 = call i32 @getline(i8** %2, i64* %3, i32 %9)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = add nsw i32 %10, -1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
store i8 0, i8* %16
br label %17
17: ; preds = %12, %1
%18 = load i8*, i8** %2
ret i8* %18
}