#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 getchar();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *strdup(char *);
char *read_prompt(char *prompt) {
  int c;
  char ret[4096] = {0};
  char tmp[2] = {0};
  printf("%s", prompt);
  while ((c = getchar()) != '\n') {
    tmp[0] = c;
    strcat(ret, tmp);
  }
  return strdup(ret);
}


x86 assembly (clang, -O0):
<read_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x1010(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
lea    -0x1012(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xa,%eax
je     11c9 <read_prompt+0x79>
mov    -0xc(%rbp),%eax
mov    %al,-0x1012(%rbp)
lea    -0x1010(%rbp),%rdi
lea    -0x1012(%rbp),%rsi
call   1060 <strcat@plt>
jmp    1195 <read_prompt+0x45>
lea    -0x1010(%rbp),%rdi
call   1070 <strdup@plt>
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_prompt>:
push   %r14
push   %rbx
sub    $0x1018,%rsp
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
mov    $0x1000,%edx
xor    %esi,%esi
call   1040 <memset@plt>
movw   $0x0,0xe(%rsp)
lea    0xe84(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
je     11bb <read_prompt+0x6b>
lea    0x10(%rsp),%r14
lea    0xe(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %al,0xe(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
jne    11a0 <read_prompt+0x50>
lea    0x10(%rsp),%rdi
call   1070 <strdup@plt>
add    $0x1018,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
define i8* @read_prompt(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [4096 x i8]
%5 = alloca [2 x i8]
store i8* %0, i8** %2
%6 = bitcast [4096 x i8]* %4 to i8*
%7 = bitcast [2 x i8]* %5 to i8*
%8 = load i8*, i8** %2
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %13, %1
%11 = call i32 (...) @getchar()
store i32 %11, i32* %3
%12 = icmp ne i32 %11, 10
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = load i32, i32* %3
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
store i8 %15, i8* %16
%17 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%19 = call i32 @strcat(i8* %17, i8* %18)
br label %10
20: ; preds = %10
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%22 = call i8* @strdup(i8* %21)
ret i8* %22
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
define noalias i8* @read_prompt(i8* %0) {
%2 = alloca [4096 x i8]
%3 = alloca i16
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%5 = bitcast i16* %3 to i8*
store i16 0, i16* %3
%6 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32 (...) @getchar()
%8 = icmp eq i32 %7, 10
br i1 %8, label %15, label %9
9: ; preds = %1, %9
%10 = phi i32 [ %13, %9 ], [ %7, %1 ]
%11 = trunc i32 %10 to i8
store i8 %11, i8* %5
%12 = call i32 @strcat(i8* %4, i8* %5)
%13 = call i32 (...) @getchar()
%14 = icmp eq i32 %13, 10
br i1 %14, label %15, label %9
15: ; preds = %9, %1
%16 = call i8* @strdup(i8* %4)
ret i8* %16
}