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

/* Variables and functions */
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ regcomp(int /*<<< orphan*/ *, char *, int /*<<< orphan*/);
scalar_t__ regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                   int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int validInput(char input[]) {
  regex_t regex;
  regcomp(&regex, "^ *\n$", 0);
  if (regexec(&regex, input, 0, NULL, 0) == 0) {
    regfree(&regex);
  } else if (strlen(input) == 99) {
    printf("Command dumped. Max 100 characters.\n");
    do {
      fgets(input, 100, stdin);
    } while (strlen(input) == 0);
  } else {
    regfree(&regex);
    input[strlen(input) - 1] = '\0';
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<validInput>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
lea    0xe89(%rip),%rsi
xor    %edx,%edx
call   1060 <regcomp@plt>
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1080 <regexec@plt>
cmp    $0x0,%rax
jne    11ad <validInput+0x4d>
lea    -0x14(%rbp),%rdi
call   1030 <regfree@plt>
jmp    1234 <validInput+0xd4>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x63,%eax
jne    11f9 <validInput+0x99>
lea    0xe40(%rip),%rdi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1070 <fgets@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
je     11cb <validInput+0x6b>
jmp    122f <validInput+0xcf>
lea    -0x14(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
jmp    123b <validInput+0xdb>
jmp    1234 <validInput+0xd4>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validInput>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe92(%rip),%rsi
lea    0x4(%rsp),%r14
mov    %r14,%rdi
xor    %edx,%edx
call   1060 <regcomp@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1080 <regexec@plt>
test   %rax,%rax
je     11e3 <validInput+0x83>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cmp    $0x63,%eax
jne    11f4 <validInput+0x94>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e34(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     11c0 <validInput+0x60>
mov    $0xffffffff,%eax
jmp    120f <validInput+0xaf>
lea    0x4(%rsp),%rdi
call   1040 <regfree@plt>
mov    $0xffffffff,%eax
jmp    120f <validInput+0xaf>
lea    0x4(%rsp),%rdi
call   1040 <regfree@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [6 x i8] c"^ *\0A$\00"
@.str.1 = [37 x i8] c"Command dumped. Max 100 characters.\0A\00"
@stdin = global i32 0
define i32 @validInput(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i32 @regcomp(i32* %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 0)
%6 = load i8*, i8** %3
%7 = call i64 @regexec(i32* %4, i8* %6, i32 0, i32* null, i32 0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @regfree(i32* %4)
br label %35
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = icmp eq i32 %13, 99
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %21, %15
%18 = load i8*, i8** %3
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %18, i32 100, i32 %19)
br label %21
21: ; preds = %17
%22 = load i8*, i8** %3
%23 = call i32 @strlen(i8* %22)
%24 = icmp eq i32 %23, 0
br i1 %24, label %17, label %25
25: ; preds = %21
br label %34
26: ; preds = %11
%27 = call i32 @regfree(i32* %4)
%28 = load i8*, i8** %3
%29 = load i8*, i8** %3
%30 = call i32 @strlen(i8* %29)
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %28, i64 %32
store i8 0, i8* %33
store i32 0, i32* %2
br label %36
34: ; preds = %25
br label %35
35: ; preds = %34, %9
store i32 -1, i32* %2
br label %36
36: ; preds = %35, %26
%37 = load i32, i32* %2
ret i32 %37
}

LLVM IR (-O2):
@.str = [6 x i8] c"^ *\0A$\00"
@stdin = global i32 0
@str = [36 x i8] c"Command dumped. Max 100 characters.\00"
define i32 @validInput(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @regcomp(i32* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 0)
%5 = call i64 @regexec(i32* %2, i8* %0, i32 0, i32* null, i32 0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @regfree(i32* %2)
br label %25
9: ; preds = %1
%10 = call i32 @strlen(i8* %0)
%11 = icmp eq i32 %10, 99
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %14
14: ; preds = %14, %12
%15 = load i32, i32* @stdin
%16 = call i32 @fgets(i8* %0, i32 100, i32 %15)
%17 = call i32 @strlen(i8* %0)
%18 = icmp eq i32 %17, 0
br i1 %18, label %14, label %25
19: ; preds = %9
%20 = call i32 @regfree(i32* %2)
%21 = call i32 @strlen(i8* %0)
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %14, %7, %19
%26 = phi i32 [ 0, %19 ], [ -1, %7 ], [ -1, %14 ]
ret i32 %26
}