#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*/ exit(int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
int validString(char *, int);
void promptUserValue(char *responseVar, char *prompt, bool checkCommand) {
  printf("%s\n> ", prompt);
  fgets(responseVar, 100, stdin);
  bool isValid;
  if (checkCommand) {
    isValid = validString(responseVar, true);
  } else {
    isValid = validString(responseVar, false);
  }
  if (!isValid) {
    printf("I'm sorry, but that's not a valid input :(\n");
    exit(1);
  } else {
    int length = strlen(responseVar);
    if (length > 0) {
      if (responseVar[length - 1] == '\n') {
        responseVar[length - 1] = '\0';
      }
    }
  }
}


x86 assembly (clang, -O0):
<promptUserValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1060 <fgets@plt>
cmpl   $0x0,-0x14(%rbp)
je     11ac <promptUserValue+0x5c>
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
call   1030 <validString@plt>
mov    %eax,-0x18(%rbp)
jmp    11ba <promptUserValue+0x6a>
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1030 <validString@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    11dc <promptUserValue+0x8c>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1222 <promptUserValue+0xd2>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    121d <promptUserValue+0xcd>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1222 <promptUserValue+0xd2>
jmp    1227 <promptUserValue+0xd7>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<promptUserValue>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rdi,%rbx
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1070 <fgets@plt>
xor    %esi,%esi
test   %ebp,%ebp
setne  %sil
mov    %rbx,%rdi
call   1030 <validString@plt>
test   %eax,%eax
je     11c0 <promptUserValue+0x60>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
jle    11b9 <promptUserValue+0x59>
add    $0xffffffff,%eax
cmpb   $0xa,(%rbx,%rax,1)
jne    11b9 <promptUserValue+0x59>
movb   $0x0,(%rbx,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe3f(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%s\0A> \00"
@stdin = global i32 0
@.str.1 = [44 x i8] c"I'm sorry, but that's not a valid input :(\0A\00"
define void @promptUserValue(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %5
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %4
%12 = load i32, i32* @stdin
%13 = call i32 @fgets(i8* %11, i32 100, i32 %12)
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = load i8*, i8** %4
%18 = call i32 @validString(i8* %17, i32 1)
store i32 %18, i32* %7
br label %22
19: ; preds = %3
%20 = load i8*, i8** %4
%21 = call i32 @validString(i8* %20, i32 0)
store i32 %21, i32* %7
br label %22
22: ; preds = %19, %16
%23 = load i32, i32* %7
%24 = icmp ne i32 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %22
%29 = load i8*, i8** %4
%30 = call i32 @strlen(i8* %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %49
33: ; preds = %28
%34 = load i8*, i8** %4
%35 = load i32, i32* %8
%36 = sub nsw i32 %35, 1
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 10
br i1 %41, label %42, label %48
42: ; preds = %33
%43 = load i8*, i8** %4
%44 = load i32, i32* %8
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %43, i64 %46
store i8 0, i8* %47
br label %48
48: ; preds = %42, %33
br label %49
49: ; preds = %48, %28
br label %50
50: ; preds = %49
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s\0A> \00"
@stdin = global i32 0
@str = [43 x i8] c"I'm sorry, but that's not a valid input :(\00"
define void @promptUserValue(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1)
%5 = load i32, i32* @stdin
%6 = tail call i32 @fgets(i8* %0, i32 100, i32 %5)
%7 = icmp ne i32 %2, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @validString(i8* %0, i32 %8)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %3
%15 = tail call i32 @strlen(i8* %0)
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %14
%18 = add nsw i32 %15, -1
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
%22 = icmp eq i8 %21, 10
br i1 %22, label %23, label %24
23: ; preds = %17
store i8 0, i8* %20
br label %24
24: ; preds = %17, %23, %14
ret void
}