#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 */
scalar_t__ checkUserCommandIsValid(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
void *malloc(int);
int /*<<< orphan*/ printInvalidCommandMessage();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
char **tokeniseUserCommand(char *);
char **getUserCommand(void) {
  printf("(JVG)");
  char *buff = malloc(300);
  fgets(buff, 300, stdin);
  char *ptr = malloc(2);
  if ((ptr = strchr(buff, '\n')) != NULL)
    *ptr = '\0';
  char **tokens = malloc(sizeof(char) * 300);
  tokens = tokeniseUserCommand(buff);
  if (checkUserCommandIsValid(tokens[0]))
    return tokens;
  printInvalidCommandMessage();
  return getUserCommand();
}


x86 assembly (clang, -O0):
<getUserCommand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe71(%rip),%rdi
call   1070 <printf@plt>
mov    $0x12c,%edi
call   1090 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
mov    $0x12c,%esi
call   1080 <fgets@plt>
mov    $0x2,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ea <getUserCommand+0x6a>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x12c,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <tokeniseUserCommand@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <checkUserCommandIsValid@plt>
cmp    $0x0,%rax
je     1228 <getUserCommand+0xa8>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1238 <getUserCommand+0xb8>
mov    $0x0,%al
call   1040 <printInvalidCommandMessage@plt>
call   1050 <getUserCommand@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getUserCommand>:
push   %r15
push   %r14
push   %rbx
lea    0xe84(%rip),%r14
mov    0x2e65(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1060 <printf@plt>
mov    $0x12c,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    (%r15),%edx
mov    %rax,%rdi
mov    $0x12c,%esi
call   1070 <fgets@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     11ca <getUserCommand+0x5a>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1090 <tokeniseUserCommand@plt>
mov    %rax,%rbx
mov    (%rax),%rdi
call   1030 <checkUserCommandIsValid@plt>
test   %rax,%rax
jne    11eb <getUserCommand+0x7b>
xor    %eax,%eax
call   1040 <printInvalidCommandMessage@plt>
jmp    1190 <getUserCommand+0x20>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [6 x i8] c"(JVG)\00"
@stdin = global i32 0
define i8** @getUserCommand() {
%1 = alloca i8**
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8**
%5 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = call i8* @malloc(i32 300)
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %7, i32 300, i32 %8)
%10 = call i8* @malloc(i32 2)
store i8* %10, i8** %3
%11 = load i8*, i8** %2
%12 = call i8* @strchr(i8* %11, i8 signext 10)
store i8* %12, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = load i8*, i8** %3
store i8 0, i8* %15
br label %16
16: ; preds = %14, %0
%17 = call i8* @malloc(i32 300)
%18 = bitcast i8* %17 to i8**
store i8** %18, i8*** %4
%19 = load i8*, i8** %2
%20 = call i8** @tokeniseUserCommand(i8* %19)
store i8** %20, i8*** %4
%21 = load i8**, i8*** %4
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i64 @checkUserCommandIsValid(i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %16
%27 = load i8**, i8*** %4
store i8** %27, i8*** %1
br label %31
28: ; preds = %16
%29 = call i32 (...) @printInvalidCommandMessage()
%30 = call i8** @getUserCommand()
store i8** %30, i8*** %1
br label %31
31: ; preds = %28, %26
%32 = load i8**, i8*** %1
ret i8** %32
}

LLVM IR (-O2):
@.str = [6 x i8] c"(JVG)\00"
@stdin = global i32 0
define i8** @getUserCommand() {
br label %1
1: ; preds = %14, %0
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = tail call dereferenceable_or_null(300) i8* @malloc(i32 300)
%4 = load i32, i32* @stdin
%5 = tail call i32 @fgets(i8* %3, i32 300, i32 %4)
%6 = tail call i8* @strchr(i8* dereferenceable(1) %3, i8 signext 10)
%7 = icmp eq i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i8 0, i8* %6
br label %9
9: ; preds = %8, %1
%10 = tail call i8** @tokeniseUserCommand(i8* %3)
%11 = load i8*, i8** %10
%12 = tail call i64 @checkUserCommandIsValid(i8* %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 (...) @printInvalidCommandMessage()
br label %1
16: ; preds = %9
ret i8** %10
}