#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 */
char EOF;
char getc(int /*<<< orphan*/);
scalar_t__ isspace(char);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int getCmd() {
  char ch;
  printf(" Enter the command and ? for help ");
  ch = getc(stdin);
  while (isspace(ch))
    ch = getc(stdin);
  if (ch == EOF)
    return -1;
  return ch;
}


x86 assembly (clang, -O0):
<getCmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xec1(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
call   1050 <getc@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%edi
call   1040 <isspace@plt>
cmp    $0x0,%rax
je     117e <getCmd+0x4e>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1050 <getc@plt>
mov    %al,-0x5(%rbp)
jmp    1155 <getCmd+0x25>
movsbl -0x5(%rbp),%eax
mov    0x2e57(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11a0 <getCmd+0x70>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <getCmd+0x77>
movsbl -0x5(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCmd>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rdi
call   1030 <printf@plt>
mov    0x2ea1(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    (%r14),%edi
call   1050 <getc@plt>
mov    %eax,%ebx
movsbl %al,%edi
call   1040 <isspace@plt>
test   %rax,%rax
jne    1150 <getCmd+0x20>
mov    0x2e72(%rip),%rax
cmp    (%rax),%bl
movzbl %bl,%eax
mov    $0xff,%ecx
cmovne %eax,%ecx
movsbl %cl,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [35 x i8] c" Enter the command and ? for help \00"
@stdin = global i32 0
@EOF = global i8 0
define i32 @getCmd() {
%1 = alloca i32
%2 = alloca i8
%3 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @stdin
%5 = call signext i8 @getc(i32 %4)
store i8 %5, i8* %2
br label %6
6: ; preds = %10, %0
%7 = load i8, i8* %2
%8 = call i64 @isspace(i8 signext %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* @stdin
%12 = call signext i8 @getc(i32 %11)
store i8 %12, i8* %2
br label %6
13: ; preds = %6
%14 = load i8, i8* %2
%15 = sext i8 %14 to i32
%16 = load i8, i8* @EOF
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %15, %17
br i1 %18, label %19, label %20
19: ; preds = %13
store i32 -1, i32* %1
br label %23
20: ; preds = %13
%21 = load i8, i8* %2
%22 = sext i8 %21 to i32
store i32 %22, i32* %1
br label %23
23: ; preds = %20, %19
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [35 x i8] c" Enter the command and ? for help \00"
@stdin = global i32 0
@EOF = global i8 0
define i32 @getCmd() {
%1 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%2 = load i32, i32* @stdin
%3 = tail call signext i8 @getc(i32 %2)
%4 = tail call i64 @isspace(i8 signext %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %0, %6
%7 = load i32, i32* @stdin
%8 = tail call signext i8 @getc(i32 %7)
%9 = tail call i64 @isspace(i8 signext %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %6
11: ; preds = %6, %0
%12 = phi i8 [ %3, %0 ], [ %8, %6 ]
%13 = load i8, i8* @EOF
%14 = icmp eq i8 %12, %13
%15 = select i1 %14, i8 -1, i8 %12
%16 = sext i8 %15 to i32
ret i32 %16
}