#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*/ free(char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
char *inputPrompt(char *message) {
  printf("%s", message);
  char *response = NULL;
  size_t length;
  if (getline(&response, &length, stdin) != -1) {
    response[strlen(response) - 1] = 0;
    return response;
  } else {
    free(response);
    return NULL;
  }
}


x86 assembly (clang, -O0):
<inputPrompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea9(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,-0x18(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1060 <getline@plt>
cmp    $0xffffffff,%eax
je     11b1 <inputPrompt+0x71>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11c2 <inputPrompt+0x82>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inputPrompt>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rsi
lea    0xeb1(%rip),%rdi
call   1050 <printf@plt>
movq   $0x0,(%rsp)
mov    0x2e85(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1060 <getline@plt>
mov    (%rsp),%rbx
cmp    $0xffffffff,%eax
je     1190 <inputPrompt+0x50>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    (%rsp),%rax
jmp    119a <inputPrompt+0x5a>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
define i8* @inputPrompt(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %6)
store i8* null, i8** %4
%8 = load i32, i32* @stdin
%9 = call i32 @getline(i8** %4, i64* %5, i32 %8)
%10 = icmp ne i32 %9, -1
br i1 %10, label %11, label %19
11: ; preds = %1
%12 = load i8*, i8** %4
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = sub nsw i32 %14, 1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %12, i64 %16
store i8 0, i8* %17
%18 = load i8*, i8** %4
store i8* %18, i8** %2
br label %22
19: ; preds = %1
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
store i8* null, i8** %2
br label %22
22: ; preds = %19, %11
%23 = load i8*, i8** %2
ret i8* %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
define i8* @inputPrompt(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 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*
%7 = load i32, i32* @stdin
%8 = call i32 @getline(i8** %2, i64* %3, i32 %7)
%9 = icmp eq i32 %8, -1
%10 = load i8*, i8** %2
br i1 %9, label %17, label %11
11: ; preds = %1
%12 = call i32 @strlen(i8* %10)
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %10, i64 %14
store i8 0, i8* %15
%16 = load i8*, i8** %2
br label %19
17: ; preds = %1
%18 = call i32 @free(i8* %10)
br label %19
19: ; preds = %17, %11
%20 = phi i8* [ %16, %11 ], [ null, %17 ]
ret i8* %20
}