#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 */
struct ptrarray {
  int dummy;
};
typedef void cmd_entry;

/* Variables and functions */
int cmd_entry_call(void *, int, char const **);
void *cmd_get(struct ptrarray *, char const *);
int /*<<< orphan*/ help(struct ptrarray *, int, char const **);
int /*<<< orphan*/ printf(char *);
int cmd_process(struct ptrarray *tbl, int argc, const char **argv) {
  struct cmd_entry *c;
  c = cmd_get(tbl, argv[0]);
  if (c == ((void *)2))
    help(tbl, argc, argv);
  else if (c == ((void *)1))
    printf("?Ambiguous command\n");
  else if (c == 0)
    printf("?Invalid command\n");
  else
    return cmd_entry_call(c, argc, argv);
  return 0;
}


x86 assembly (clang, -O0):
<cmd_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   1050 <cmd_get@plt>
mov    %rax,-0x28(%rbp)
mov    $0x2,%eax
cmp    %rax,-0x28(%rbp)
jne    118b <cmd_process+0x4b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <help@plt>
jmp    11e9 <cmd_process+0xa9>
mov    $0x1,%eax
cmp    %rax,-0x28(%rbp)
jne    11ab <cmd_process+0x6b>
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
jmp    11e4 <cmd_process+0xa4>
cmpq   $0x0,-0x28(%rbp)
jne    11c7 <cmd_process+0x87>
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
jmp    11df <cmd_process+0x9f>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1030 <cmd_entry_call@plt>
mov    %eax,-0x4(%rbp)
jmp    11f0 <cmd_process+0xb0>
jmp    11e4 <cmd_process+0xa4>
jmp    11e9 <cmd_process+0xa9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_process>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    (%rdx),%rsi
call   1050 <cmd_get@plt>
test   %rax,%rax
je     1176 <cmd_process+0x36>
cmp    $0x1,%rax
je     117f <cmd_process+0x3f>
cmp    $0x2,%rax
jne    1192 <cmd_process+0x52>
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
call   1060 <help@plt>
jmp    118b <cmd_process+0x4b>
lea    0xe83(%rip),%rdi
jmp    1186 <cmd_process+0x46>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %rax,%rdi
mov    %r14d,%esi
mov    %rbx,%rdx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <cmd_entry_call@plt>

LLVM IR (-O0):
%struct.ptrarray = type { i32 }
%struct.cmd_entry = type opaque
@.str = [20 x i8] c"?Ambiguous command\0A\00"
@.str.1 = [18 x i8] c"?Invalid command\0A\00"
define i32 @cmd_process(%struct.ptrarray* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca %struct.ptrarray*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca %struct.cmd_entry*
store %struct.ptrarray* %0, %struct.ptrarray** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%9 = load %struct.ptrarray*, %struct.ptrarray** %5
%10 = load i8**, i8*** %7
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i8* @cmd_get(%struct.ptrarray* %9, i8* %12)
%14 = bitcast i8* %13 to %struct.cmd_entry*
store %struct.cmd_entry* %14, %struct.cmd_entry** %8
%15 = load %struct.cmd_entry*, %struct.cmd_entry** %8
%16 = icmp eq %struct.cmd_entry* %15, inttoptr (i64 2 to %struct.cmd_entry*)
br i1 %16, label %17, label %22
17: ; preds = %3
%18 = load %struct.ptrarray*, %struct.ptrarray** %5
%19 = load i32, i32* %6
%20 = load i8**, i8*** %7
%21 = call i32 @help(%struct.ptrarray* %18, i32 %19, i8** %20)
br label %40
22: ; preds = %3
%23 = load %struct.cmd_entry*, %struct.cmd_entry** %8
%24 = icmp eq %struct.cmd_entry* %23, inttoptr (i64 1 to %struct.cmd_entry*)
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %39
27: ; preds = %22
%28 = load %struct.cmd_entry*, %struct.cmd_entry** %8
%29 = icmp eq %struct.cmd_entry* %28, null
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %38
32: ; preds = %27
%33 = load %struct.cmd_entry*, %struct.cmd_entry** %8
%34 = bitcast %struct.cmd_entry* %33 to i8*
%35 = load i32, i32* %6
%36 = load i8**, i8*** %7
%37 = call i32 @cmd_entry_call(i8* %34, i32 %35, i8** %36)
store i32 %37, i32* %4
br label %41
38: ; preds = %30
br label %39
39: ; preds = %38, %25
br label %40
40: ; preds = %39, %17
store i32 0, i32* %4
br label %41
41: ; preds = %40, %32
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
%struct.ptrarray = type { i32 }
@str = [17 x i8] c"?Invalid command\00"
@str.2 = [19 x i8] c"?Ambiguous command\00"
define i32 @cmd_process(%struct.ptrarray* %0, i32 %1, i8** %2) {
%4 = load i8*, i8** %2
%5 = tail call i8* @cmd_get(%struct.ptrarray* %0, i8* %4)
%6 = ptrtoint i8* %5 to i64
switch i64 %6, label %13 [
i64 2, label %7
i64 1, label %9
i64 0, label %11
]
7: ; preds = %3
%8 = tail call i32 @help(%struct.ptrarray* %0, i32 %1, i8** %2)
br label %15
9: ; preds = %3
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.2, i64 0, i64 0))
br label %15
11: ; preds = %3
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %15
13: ; preds = %3
%14 = tail call i32 @cmd_entry_call(i8* %5, i32 %1, i8** %2)
br label %15
15: ; preds = %7, %11, %9, %13
%16 = phi i32 [ %14, %13 ], [ 0, %9 ], [ 0, %11 ], [ 0, %7 ]
ret i32 %16
}