#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 */
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 *strchr(char *, char);
char *readline(const char *prompt) {
  char *tmp, *buf = 0;
  size_t len = 0;
  printf("%s", prompt ? prompt : "");
  fflush(stdout);
  if (getline(&buf, &len, stdin) == -1)
    return 0;
  tmp = strchr(buf, '\n');
  if (tmp)
    *tmp = '\0';
  else
    return 0;
  return buf;
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1174 <readline+0x34>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    1184 <readline+0x44>
lea    0xe87(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    1184 <readline+0x44>
mov    -0x30(%rbp),%rsi
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
jne    11ce <readline+0x8e>
movq   $0x0,-0x8(%rbp)
jmp    120c <readline+0xcc>
mov    -0x20(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f7 <readline+0xb7>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    1204 <readline+0xc4>
movq   $0x0,-0x8(%rbp)
jmp    120c <readline+0xcc>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
test   %rdi,%rdi
lea    0xea2(%rip),%rsi
cmovne %rdi,%rsi
lea    0xe95(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     11bc <readline+0x7c>
mov    0x8(%rsp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     11bc <readline+0x7c>
movb   $0x0,(%rax)
mov    0x8(%rsp),%rax
add    $0x18,%rsp
ret
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [1 x i8] zeroinitializer
@stdout = global i32 0
@stdin = global i32 0
define i8* @readline(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i8* null, i8** %5
store i64 0, i64* %6
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load i8*, i8** %3
br label %12
11: ; preds = %1
br label %12
12: ; preds = %11, %9
%13 = phi i8* [ %10, %9 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %11 ]
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @stdout
%16 = call i32 @fflush(i32 %15)
%17 = load i32, i32* @stdin
%18 = call i32 @getline(i8** %5, i64* %6, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %12
store i8* null, i8** %2
br label %31
21: ; preds = %12
%22 = load i8*, i8** %5
%23 = call i8* @strchr(i8* %22, i8 signext 10)
store i8* %23, i8** %4
%24 = load i8*, i8** %4
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = load i8*, i8** %4
store i8 0, i8* %27
br label %29
28: ; preds = %21
store i8* null, i8** %2
br label %31
29: ; preds = %26
%30 = load i8*, i8** %5
store i8* %30, i8** %2
br label %31
31: ; preds = %29, %28, %20
%32 = load i8*, i8** %2
ret i8* %32
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [1 x i8] zeroinitializer
@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 = icmp eq i8* %0, null
%7 = select i1 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %0
%8 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @stdout
%10 = tail call i32 @fflush(i32 %9)
%11 = load i32, i32* @stdin
%12 = call i32 @getline(i8** %2, i64* %3, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %20, label %14
14: ; preds = %1
%15 = load i8*, i8** %2
%16 = call i8* @strchr(i8* dereferenceable(1) %15, i8 signext 10)
%17 = icmp eq i8* %16, null
br i1 %17, label %20, label %18
18: ; preds = %14
store i8 0, i8* %16
%19 = load i8*, i8** %2
br label %20
20: ; preds = %14, %1, %18
%21 = phi i8* [ %19, %18 ], [ null, %1 ], [ null, %14 ]
ret i8* %21
}