#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__ check_argc(int, int, int, char *);
scalar_t__ check_cmd(int, char *, char **);
unsigned long extract_val(char *);
int get_demo();
int /*<<< orphan*/ print_unknown_arg(char *);
int /*<<< orphan*/ print_unknown_cmd(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ set_demo(unsigned long);
scalar_t__ strcmp(char *, char *);
int my_cmd_demo(int argc, char **argv) {
  char *usage[] = {"set   load demo (1 | 2 | 3)",
                   "get   print current demo configuration", 0};
  if (check_cmd(argc, "demo", usage))
    return -1;
  if (strcmp("get", argv[0]) == 0) {
    if (check_argc(argc, 1, 1, ""))
      return -1;
    printf("demo configuration %d\n", get_demo());
  } else if (strcmp("set", argv[0]) == 0) {
    if (check_argc(argc, 2, 2, "demo set ID"))
      return -1;
    unsigned long val = extract_val(argv[1]);
    if ((val < 1) || (val > 3)) {
      print_unknown_arg(argv[1]);
      return -1;
    }
    set_demo(val);
    printf("selecting demo %d\n", get_demo());
  } else {
    print_unknown_cmd(argv[0]);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<my_cmd_demo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2c5a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2c57(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c54(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rdx
lea    0xe75(%rip),%rsi
call   1070 <check_cmd@plt>
cmp    $0x0,%rax
je     11e9 <my_cmd_demo+0x59>
movl   $0xffffffff,-0x4(%rbp)
jmp    131c <my_cmd_demo+0x18c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe51(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    124c <my_cmd_demo+0xbc>
mov    -0x8(%rbp),%edi
mov    $0x1,%edx
lea    0xe4d(%rip),%rcx
mov    %edx,%esi
call   1030 <check_argc@plt>
cmp    $0x0,%rax
je     1232 <my_cmd_demo+0xa2>
movl   $0xffffffff,-0x4(%rbp)
jmp    131c <my_cmd_demo+0x18c>
mov    $0x0,%al
call   10b0 <get_demo@plt>
mov    %eax,%esi
lea    0xe0a(%rip),%rdi
call   1040 <printf@plt>
jmp    1315 <my_cmd_demo+0x185>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe09(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12f8 <my_cmd_demo+0x168>
mov    -0x8(%rbp),%edi
mov    $0x2,%edx
lea    0xdef(%rip),%rcx
mov    %edx,%esi
call   1030 <check_argc@plt>
cmp    $0x0,%rax
je     1295 <my_cmd_demo+0x105>
movl   $0xffffffff,-0x4(%rbp)
jmp    131c <my_cmd_demo+0x18c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <extract_val@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x1,-0x38(%rbp)
jb     12bc <my_cmd_demo+0x12c>
cmpq   $0x3,-0x38(%rbp)
jbe    12d5 <my_cmd_demo+0x145>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <print_unknown_arg@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    131c <my_cmd_demo+0x18c>
mov    -0x38(%rbp),%rdi
call   1050 <set_demo@plt>
mov    $0x0,%al
call   10b0 <get_demo@plt>
mov    %eax,%esi
lea    0xd85(%rip),%rdi
call   1040 <printf@plt>
jmp    1310 <my_cmd_demo+0x180>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <print_unknown_cmd@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    131c <my_cmd_demo+0x18c>
jmp    1315 <my_cmd_demo+0x185>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_cmd_demo>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2c6c(%rip),%rax
mov    %rax,0x10(%rsp)
movaps 0x2c50(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xe88(%rip),%rsi
mov    %rsp,%rdx
call   1070 <check_cmd@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
je     11da <my_cmd_demo+0x4a>
mov    %r14d,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xe64(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     120c <my_cmd_demo+0x7c>
mov    (%rbx),%rsi
lea    0xe6b(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     123c <my_cmd_demo+0xac>
mov    (%rbx),%rdi
call   1090 <print_unknown_cmd@plt>
jmp    11ce <my_cmd_demo+0x3e>
lea    0xe4f(%rip),%rcx
mov    %ebp,%edi
mov    $0x1,%esi
mov    $0x1,%edx
call   1030 <check_argc@plt>
test   %rax,%rax
jne    11ce <my_cmd_demo+0x3e>
xor    %r14d,%r14d
xor    %eax,%eax
call   10b0 <get_demo@plt>
lea    0xe12(%rip),%rdi
jmp    1297 <my_cmd_demo+0x107>
lea    0xe24(%rip),%rcx
mov    %ebp,%edi
mov    $0x2,%esi
mov    $0x2,%edx
call   1030 <check_argc@plt>
test   %rax,%rax
jne    11ce <my_cmd_demo+0x3e>
mov    0x8(%rbx),%rdi
call   10a0 <extract_val@plt>
lea    -0x4(%rax),%rcx
cmp    $0xfffffffffffffffc,%rcx
ja     127e <my_cmd_demo+0xee>
mov    0x8(%rbx),%rdi
call   1080 <print_unknown_arg@plt>
jmp    11ce <my_cmd_demo+0x3e>
mov    %rax,%rdi
call   1050 <set_demo@plt>
xor    %r14d,%r14d
xor    %eax,%eax
call   10b0 <get_demo@plt>
lea    0xddc(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
jmp    11ce <my_cmd_demo+0x3e>

LLVM IR (-O0):
@.str = [28 x i8] c"set load demo (1 | 2 | 3)\00"
@.str.1 = [39 x i8] c"get print current demo configuration\00"
@__const.my_cmd_demo.usage = [3 x i8*] [i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [5 x i8] c"demo\00"
@.str.3 = [4 x i8] c"get\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [23 x i8] c"demo configuration %d\0A\00"
@.str.6 = [4 x i8] c"set\00"
@.str.7 = [12 x i8] c"demo set ID\00"
@.str.8 = [19 x i8] c"selecting demo %d\0A\00"
define i32 @my_cmd_demo(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x i8*]
%7 = alloca i64
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = bitcast [3 x i8*]* %6 to i8*
%9 = load i32, i32* %4
%10 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
%11 = call i64 @check_cmd(i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 -1, i32* %3
br label %66
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %14
%21 = load i32, i32* %4
%22 = call i64 @check_argc(i32 %21, i32 1, i32 1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 -1, i32* %3
br label %66
25: ; preds = %20
%26 = call i32 (...) @get_demo()
%27 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %26)
br label %65
28: ; preds = %14
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %59
34: ; preds = %28
%35 = load i32, i32* %4
%36 = call i64 @check_argc(i32 %35, i32 2, i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
store i32 -1, i32* %3
br label %66
39: ; preds = %34
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i64 @extract_val(i8* %42)
store i64 %43, i64* %7
%44 = load i64, i64* %7
%45 = icmp ult i64 %44, 1
br i1 %45, label %49, label %46
46: ; preds = %39
%47 = load i64, i64* %7
%48 = icmp ugt i64 %47, 3
br i1 %48, label %49, label %54
49: ; preds = %46, %39
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = call i32 @print_unknown_arg(i8* %52)
store i32 -1, i32* %3
br label %66
54: ; preds = %46
%55 = load i64, i64* %7
%56 = call i32 @set_demo(i64 %55)
%57 = call i32 (...) @get_demo()
%58 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 %57)
br label %64
59: ; preds = %28
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 0
%62 = load i8*, i8** %61
%63 = call i32 @print_unknown_cmd(i8* %62)
store i32 -1, i32* %3
br label %66
64: ; preds = %54
br label %65
65: ; preds = %64, %25
store i32 0, i32* %3
br label %66
66: ; preds = %65, %59, %49, %38, %24, %13
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
@.str = [28 x i8] c"set load demo (1 | 2 | 3)\00"
@.str.1 = [39 x i8] c"get print current demo configuration\00"
@__const.my_cmd_demo.usage = [3 x i8*] [i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [5 x i8] c"demo\00"
@.str.3 = [4 x i8] c"get\00"
@.str.4 = [1 x i8] zeroinitializer
@.str.5 = [23 x i8] c"demo configuration %d\0A\00"
@.str.6 = [4 x i8] c"set\00"
@.str.7 = [12 x i8] c"demo set ID\00"
@.str.8 = [19 x i8] c"selecting demo %d\0A\00"
define i32 @my_cmd_demo(i32 %0, i8** nocapture %1) {
%3 = alloca [3 x i8*]
%4 = bitcast [3 x i8*]* %3 to i8*
%5 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%6 = call i64 @check_cmd(i32 %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %41
8: ; preds = %2
%9 = load i8*, i8** %1
%10 = call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %8
%13 = call i64 @check_argc(i32 %0, i32 1, i32 1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %41
15: ; preds = %12
%16 = call i32 (...) @get_demo()
%17 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %16)
br label %41
18: ; preds = %8
%19 = load i8*, i8** %1
%20 = call i64 @strcmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %38
22: ; preds = %18
%23 = call i64 @check_argc(i32 %0, i32 2, i32 2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %41
25: ; preds = %22
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @extract_val(i8* %27)
%29 = add i64 %28, -4
%30 = icmp ult i64 %29, -3
br i1 %30, label %31, label %34
31: ; preds = %25
%32 = load i8*, i8** %26
%33 = call i32 @print_unknown_arg(i8* %32)
br label %41
34: ; preds = %25
%35 = call i32 @set_demo(i64 %28)
%36 = call i32 (...) @get_demo()
%37 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i32 %36)
br label %41
38: ; preds = %18
%39 = load i8*, i8** %1
%40 = call i32 @print_unknown_cmd(i8* %39)
br label %41
41: ; preds = %15, %34, %31, %22, %12, %2, %38
%42 = phi i32 [ -1, %38 ], [ -1, %2 ], [ -1, %12 ], [ -1, %22 ], [ -1, %31 ], [ 0, %34 ], [ 0, %15 ]
ret i32 %42
}