#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*/ ENOBUFS;
int /*<<< orphan*/ assert(char const *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fgetz(char *, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *, char const *);
int /*<<< orphan*/ stdin;
size_t strlcpy(char *, char const *, size_t);
int prompts(const char *prompt, const char *def, char *s, size_t size) {
  assert(prompt);
  assert(def);
  assert(s);
  printf("%s [%s]: ", prompt, def);
  if (!fgetz(s, size, stdin)) {
    return (-1);
  }
  if (!*s && strlcpy(s, def, size) >= size) {
    errno = ENOBUFS;
    return (-1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<prompts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x20(%rbp),%rdi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe7e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
call   1030 <fgetz@plt>
cmp    $0x0,%eax
jne    11b2 <prompts+0x72>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <prompts+0xbf>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11f8 <prompts+0xb8>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1060 <strlcpy@plt>
cmp    -0x28(%rbp),%rax
jb     11f8 <prompts+0xb8>
mov    0x2e17(%rip),%rax
mov    (%rax),%ecx
mov    0x2de6(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11ff <prompts+0xbf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prompts>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%rbp
call   1050 <assert@plt>
mov    %r15,%rdi
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1050 <assert@plt>
lea    0xe91(%rip),%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1040 <printf@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <fgetz@plt>
mov    $0xffffffff,%ebp
test   %eax,%eax
je     11c8 <prompts+0x88>
xor    %ebp,%ebp
cmpb   $0x0,(%rbx)
jne    11c8 <prompts+0x88>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1060 <strlcpy@plt>
cmp    %r14,%rax
jb     11c8 <prompts+0x88>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    0x2e0f(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [10 x i8] c"%s [%s]: \00"
@stdin = global i32 0
@ENOBUFS = global i32 0
@errno = global i32 0
define i32 @prompts(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = tail call i32 @assert(i8* %0)
%6 = tail call i32 @assert(i8* %1)
%7 = tail call i32 @assert(i8* %2)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%9 = load i32, i32* @stdin
%10 = tail call i32 @fgetz(i8* %2, i64 %3, i32 %9)
%11 = icmp eq i32 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %4
%13 = load i8, i8* %2
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = tail call i64 @strlcpy(i8* %2, i8* %1, i64 %3)
%17 = icmp ult i64 %16, %3
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = load i32, i32* @ENOBUFS
store i32 %19, i32* @errno
br label %20
20: ; preds = %12, %15, %4, %18
%21 = phi i32 [ -1, %18 ], [ -1, %4 ], [ 0, %15 ], [ 0, %12 ]
ret i32 %21
}