#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*/ TrimWhitespace(char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
int PromptForString(const char *prompt, char str[], int len) {
  printf("%s", prompt);
  fflush(stdout);
  if (fgets(str, len, stdin) == NULL) {
    return -1;
  }
  TrimWhitespace(str);
  return strlen(str);
}


x86 assembly (clang, -O0):
<PromptForString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe92(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
call   1060 <fgets@plt>
cmp    $0x0,%rax
jne    11ac <PromptForString+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c1 <PromptForString+0x71>
mov    -0x18(%rbp),%rdi
call   1030 <TrimWhitespace@plt>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PromptForString>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%rsi
lea    0xe9e(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     11a3 <PromptForString+0x53>
mov    %rbx,%rdi
call   1030 <TrimWhitespace@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <strlen@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@stdout = global i32 0
@stdin = global i32 0
define i32 @PromptForString(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = load i32, i32* @stdout
%6 = tail call i32 @fflush(i32 %5)
%7 = load i32, i32* @stdin
%8 = tail call i32* @fgets(i8* %1, i32 %2, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %3
%11 = tail call i32 @TrimWhitespace(i8* %1)
%12 = tail call i32 @strlen(i8* %1)
br label %13
13: ; preds = %3, %10
%14 = phi i32 [ %12, %10 ], [ -1, %3 ]
ret i32 %14
}