#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, char *);
int /*<<< orphan*/ stdin;
scalar_t__ strcasecmp(char *, char *);
int /*<<< orphan*/ wscSystemStop();
void *WscDeviceCommandLoop(void *args) {
  int stoploop = 0;
  char cmdline[100];
  char cmd[100];
  while (!stoploop) {
    sprintf(cmdline, " ");
    sprintf(cmd, " ");
    printf("\n>> ");
    fgets(cmdline, 100, stdin);
    sscanf(cmdline, "%s", cmd);
    if (strcasecmp(cmd, "exit") == 0) {
      printf("Shutting down...\n");
      wscSystemStop();
    } else {
      printf("\n   Unknown command: %s\n\n", cmd);
      printf("   Valid Commands:\n");
      printf("     Exit\n\n");
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<WscDeviceCommandLoop>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    118c <WscDeviceCommandLoop+0x2c>
jmp    1258 <WscDeviceCommandLoop+0xf8>
lea    -0x70(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1080 <sprintf@plt>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x70(%rbp),%rdi
mov    0x2e20(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1050 <fgets@plt>
lea    -0x70(%rbp),%rdi
lea    -0xe0(%rbp),%rdx
lea    0xe1f(%rip),%rsi
call   1070 <sscanf@plt>
lea    -0xe0(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1030 <strcasecmp@plt>
cmp    $0x0,%rax
jne    1222 <WscDeviceCommandLoop+0xc2>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <wscSystemStop@plt>
jmp    1253 <WscDeviceCommandLoop+0xf3>
lea    -0xe0(%rbp),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1176 <WscDeviceCommandLoop+0x16>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WscDeviceCommandLoop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
lea    0xe88(%rip),%r14
mov    0x2e69(%rip),%rbp
lea    0x70(%rsp),%r12
lea    0xe7a(%rip),%r15
mov    %rsp,%rbx
lea    0xe73(%rip),%r13
jmp    11c9 <WscDeviceCommandLoop+0x69>
nopw   0x0(%rax,%rax,1)
lea    0xe66(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe6f(%rip),%rdi
call   1040 <puts@plt>
lea    0xe76(%rip),%rdi
call   1040 <puts@plt>
movw   $0x20,0x70(%rsp)
movw   $0x20,(%rsp)
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x0(%rbp),%edx
mov    %r12,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <sscanf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1030 <strcasecmp@plt>
test   %rax,%rax
jne    11a0 <WscDeviceCommandLoop+0x40>
lea    0xe30(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1070 <wscSystemStop@plt>
jmp    11c9 <WscDeviceCommandLoop+0x69>

LLVM IR (-O0):
@.str = [2 x i8] c" \00"
@.str.1 = [5 x i8] c"\0A>> \00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [5 x i8] c"exit\00"
@.str.4 = [18 x i8] c"Shutting down...\0A\00"
@.str.5 = [26 x i8] c"\0A Unknown command: %s\0A\0A\00"
@.str.6 = [20 x i8] c" Valid Commands:\0A\00"
@.str.7 = [12 x i8] c" Exit\0A\0A\00"
define i8* @WscDeviceCommandLoop(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
store i8* %0, i8** %2
store i32 0, i32* %3
br label %6
6: ; preds = %33, %1
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %34
10: ; preds = %6
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%12 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%14 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%17 = load i32, i32* @stdin
%18 = call i32 @fgets(i8* %16, i32 100, i32 %17)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%21 = call i32 @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%23 = call i64 @strcasecmp(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %10
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%27 = call i32 (...) @wscSystemStop()
br label %33
28: ; preds = %10
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0))
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
br label %33
33: ; preds = %28, %25
br label %6
34: ; preds = %6
ret i8* null
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"\0A>> \00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [5 x i8] c"exit\00"
@.str.5 = [26 x i8] c"\0A Unknown command: %s\0A\0A\00"
@str = [19 x i8] c" Valid Commands:\00"
@str.8 = [11 x i8] c" Exit\0A\00"
@str.9 = [17 x i8] c"Shutting down...\00"
define noalias i8* @WscDeviceCommandLoop(i8* nocapture readnone %0) {
%2 = alloca [100 x i8]
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = bitcast [100 x i8]* %2 to i16*
%7 = bitcast [100 x i8]* %3 to i16*
br label %8
8: ; preds = %22, %1
store i16 32, i16* %6
store i16 32, i16* %7
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i32 @fgets(i8* %4, i32 100, i32 %10)
%12 = call i32 @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%13 = call i64 @strcasecmp(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.9, i64 0, i64 0))
%17 = call i32 (...) @wscSystemStop()
br label %22
18: ; preds = %8
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.8, i64 0, i64 0))
br label %22
22: ; preds = %18, %15
br label %8
}