#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 EXIT_FAILURE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int main_add(int, char **);
int main_sort(int, char **);
int main_sortk(int, char **);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  if (argc < 2) {
    goto usage;
  } else if (strcmp(argv[1], "add") == 0) {
    return main_add(argc - 1, argv + 1);
  } else if (strcmp(argv[1], "sort") == 0) {
    return main_sort(argc - 1, argv + 1);
  } else if (strcmp(argv[1], "sortk") == 0) {
    return main_sortk(argc - 1, argv + 1);
  } else {
    goto usage;
  }
usage:
  fprintf(stderr, "Usage: clh2of-simple-mod (add|sort) ...\n");
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1175 <main+0x25>
jmp    1225 <main+0xd5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7c(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ae <main+0x5e>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1030 <main_add@plt>
mov    %eax,-0x4(%rbp)
jmp    1246 <main+0xf6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe47(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11e7 <main+0x97>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1060 <main_sort@plt>
mov    %eax,-0x4(%rbp)
jmp    1246 <main+0xf6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe13(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1220 <main+0xd0>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1070 <main_sortk@plt>
mov    %eax,-0x4(%rbp)
jmp    1246 <main+0xf6>
jmp    1225 <main+0xd5>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     119e <main+0x4e>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
add    $0x8,%rbx
lea    0xe94(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11c3 <main+0x73>
mov    (%rbx),%rdi
lea    0xe84(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11d6 <main+0x86>
mov    (%rbx),%rdi
lea    0xe75(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11e9 <main+0x99>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
add    $0xffffffff,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <main_add@plt>
add    $0xffffffff,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1060 <main_sort@plt>
add    $0xffffffff,%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1070 <main_sortk@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"add\00"
@.str.1 = [5 x i8] c"sort\00"
@.str.2 = [6 x i8] c"sortk\00"
@stderr = global i32 0
@.str.3 = [41 x i8] c"Usage: clh2of-simple-mod (add|sort) ...\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 2
br i1 %7, label %8, label %9
8: ; preds = %2
br label %46
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %9
%16 = load i32, i32* %4
%17 = sub nsw i32 %16, 1
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = call i32 @main_add(i32 %17, i8** %19)
store i32 %20, i32* %3
br label %50
21: ; preds = %9
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %21
%28 = load i32, i32* %4
%29 = sub nsw i32 %28, 1
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = call i32 @main_sort(i32 %29, i8** %31)
store i32 %32, i32* %3
br label %50
33: ; preds = %21
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %33
%40 = load i32, i32* %4
%41 = sub nsw i32 %40, 1
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 1
%44 = call i32 @main_sortk(i32 %41, i8** %43)
store i32 %44, i32* %3
br label %50
45: ; preds = %33
br label %46
46: ; preds = %45, %8
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
store i32 %49, i32* %3
br label %50
50: ; preds = %46, %39, %27, %15
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@.str = [4 x i8] c"add\00"
@.str.1 = [5 x i8] c"sort\00"
@.str.2 = [6 x i8] c"sortk\00"
@stderr = global i32 0
@.str.3 = [41 x i8] c"Usage: clh2of-simple-mod (add|sort) ...\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %26, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %4
%10 = add nsw i32 %0, -1
%11 = tail call i32 @main_add(i32 %10, i8** %5)
br label %30
12: ; preds = %4
%13 = load i8*, i8** %5
%14 = tail call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = add nsw i32 %0, -1
%18 = tail call i32 @main_sort(i32 %17, i8** %5)
br label %30
19: ; preds = %12
%20 = load i8*, i8** %5
%21 = tail call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = add nsw i32 %0, -1
%25 = tail call i32 @main_sortk(i32 %24, i8** %5)
br label %30
26: ; preds = %19, %2
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
br label %30
30: ; preds = %26, %23, %16, %9
%31 = phi i32 [ %29, %26 ], [ %11, %9 ], [ %18, %16 ], [ %25, %23 ]
ret i32 %31
}