#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 */
char *calloc(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strncpy(char *, char *, int);
int stdin_prompt(char *msg, char **buffer) {
  char *line = NULL;
  size_t len = 0;
  ssize_t read;
  fprintf(stdout, "%s: ", msg);
  read = getline(&line, &len, stdin);
  if (read < 2) {
    return -1;
  }
  *buffer = calloc(1, read + 1);
  strncpy(*buffer, line, read - 1);
  return 0;
}


x86 assembly (clang, -O0):
<stdin_prompt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe8c(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <getline@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x2,-0x2c(%rbp)
jge    11a8 <stdin_prompt+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <stdin_prompt+0x9f>
mov    -0x2c(%rbp),%esi
add    $0x1,%esi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x2c(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdin_prompt>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rdx
movq   $0x0,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1060 <getline@plt>
mov    %eax,%ebx
mov    $0xffffffff,%eax
cmp    $0x2,%ebx
jl     11bc <stdin_prompt+0x7c>
lea    0x1(%rbx),%esi
mov    $0x1,%edi
call   1040 <calloc@plt>
mov    %rax,(%r14)
mov    0x8(%rsp),%rsi
add    $0xffffffff,%ebx
mov    %rax,%rdi
mov    %ebx,%edx
call   1030 <strncpy@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

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

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