#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 /*<<< orphan*/ buffer;

/* Variables and functions */
char *clean_string(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int ask_string(char *prompt, char *the_default, char *out) {
  char buffer[1024];
  char *clean;
  out[0] = 0;
  printf("%s", prompt);
  if (!fgets(buffer, sizeof(buffer), stdin))
    return -1;
  clean = clean_string(buffer);
  if (strlen(clean) < 1) {
    strcpy(out, the_default);
    return 0;
  }
  strcpy(out, clean);
  return 0;
}


x86 assembly (clang, -O0):
<ask_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rsi
lea    0xe87(%rip),%rdi
call   1050 <printf@plt>
lea    -0x420(%rbp),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%eax
jne    11ad <ask_string+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <ask_string+0xb5>
lea    -0x420(%rbp),%rdi
call   1060 <clean_string@plt>
mov    %rax,-0x428(%rbp)
mov    -0x428(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x1,%eax
jge    11ee <ask_string+0x9e>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    1205 <ask_string+0xb5>
mov    -0x20(%rbp),%rdi
mov    -0x428(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ask_string>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rsi
movb   $0x0,(%rdx)
lea    0xe91(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x400,%esi
call   1070 <fgets@plt>
test   %eax,%eax
je     11b6 <ask_string+0x66>
mov    %rsp,%rdi
call   1060 <clean_string@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
cmovg  %rbx,%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
xor    %eax,%eax
jmp    11bb <ask_string+0x6b>
mov    $0xffffffff,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@stdin = global i32 0
define i32 @ask_string(i8* %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
store i8 0, i8* %2
%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* @stdin
%8 = call i32 @fgets(i8* %5, i32 1024, i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %3
%11 = call i8* @clean_string(i8* %5)
%12 = call i32 @strlen(i8* %11)
%13 = icmp slt i32 %12, 1
%14 = select i1 %13, i8* %1, i8* %11
%15 = call i32 @strcpy(i8* %2, i8* %14)
br label %16
16: ; preds = %10, %3
%17 = phi i32 [ -1, %3 ], [ 0, %10 ]
ret i32 %17
}