#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 argument {
  int dummy;
};

/* Variables and functions */
struct argument *find_argument(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int ndsctl_do(char const *, struct argument const *, char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  const struct argument *arg;
  const char *socket;
  int i = 1;
  socket = strdup("/tmp/ndsctl.sock");
  if (argc <= i) {
    usage();
    return 0;
  }
  if (strcmp(argv[1], "-h") == 0) {
    usage();
    return 1;
  }
  if (strcmp(argv[1], "-s") == 0) {
    if (argc >= 2) {
      socket = strdup(argv[2]);
      i = 3;
    } else {
      usage();
      return 1;
    }
  }
  if (argc > (i + 2)) {
    usage();
    return 1;
  }
  arg = find_argument(argv[i]);
  if (arg == NULL) {
    fprintf(stderr, "Unknown command: %s\n", argv[i]);
    return 1;
  }
  return ndsctl_do(socket, arg, argv[i + 1]);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
lea    0xe7c(%rip),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     11ac <main+0x4c>
mov    $0x0,%al
call   1070 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    12cc <main+0x16c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe56(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11dd <main+0x7d>
mov    $0x0,%al
call   1070 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cc <main+0x16c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe28(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    123a <main+0xda>
cmpl   $0x2,-0x8(%rbp)
jl     1222 <main+0xc2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x20(%rbp)
movl   $0x3,-0x24(%rbp)
jmp    1235 <main+0xd5>
mov    $0x0,%al
call   1070 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cc <main+0x16c>
jmp    123a <main+0xda>
mov    -0x8(%rbp),%eax
mov    -0x24(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
jle    125e <main+0xfe>
mov    $0x0,%al
call   1070 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cc <main+0x16c>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <find_argument@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12ab <main+0x14b>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd7d(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12cc <main+0x16c>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
call   1060 <ndsctl_do@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe90(%rip),%rdi
call   1080 <strdup@plt>
cmp    $0x1,%ebp
jg     1185 <main+0x25>
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <usage@plt>
jmp    11dd <main+0x7d>
mov    %rax,%r14
mov    0x8(%rbx),%rdi
lea    0xe7e(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11d1 <main+0x71>
mov    0x8(%rbx),%rdi
lea    0xe6c(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     11b9 <main+0x59>
mov    $0x1,%eax
jmp    11ca <main+0x6a>
mov    0x10(%rbx),%rdi
call   1080 <strdup@plt>
mov    %rax,%r14
mov    $0x3,%eax
lea    0x2(%rax),%ecx
cmp    %ebp,%ecx
jae    11e4 <main+0x84>
xor    %eax,%eax
call   1070 <usage@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %eax,%ebp
mov    (%rbx,%rbp,8),%rdi
call   1030 <find_argument@plt>
test   %rax,%rax
je     1208 <main+0xa8>
mov    0x8(%rbx,%rbp,8),%rdx
mov    %r14,%rdi
mov    %rax,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <ndsctl_do@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    (%rbx,%rbp,8),%rdx
lea    0xdfb(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11d8 <main+0x78>

LLVM IR (-O0):
%struct.argument = type { i32 }
@.str = [17 x i8] c"/tmp/ndsctl.sock\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [3 x i8] c"-s\00"
@stderr = global i32 0
@.str.3 = [21 x i8] c"Unknown command: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.argument*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %8
%9 = call i8* @strdup(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %7
%10 = load i32, i32* %4
%11 = load i32, i32* %8
%12 = icmp sle i32 %10, %11
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (...) @usage()
store i32 0, i32* %3
br label %74
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 (...) @usage()
store i32 1, i32* %3
br label %74
23: ; preds = %15
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %40
29: ; preds = %23
%30 = load i32, i32* %4
%31 = icmp sge i32 %30, 2
br i1 %31, label %32, label %37
32: ; preds = %29
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i8* @strdup(i8* %35)
store i8* %36, i8** %7
store i32 3, i32* %8
br label %39
37: ; preds = %29
%38 = call i32 (...) @usage()
store i32 1, i32* %3
br label %74
39: ; preds = %32
br label %40
40: ; preds = %39, %23
%41 = load i32, i32* %4
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 2
%44 = icmp sgt i32 %41, %43
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = call i32 (...) @usage()
store i32 1, i32* %3
br label %74
47: ; preds = %40
%48 = load i8**, i8*** %5
%49 = load i32, i32* %8
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %48, i64 %50
%52 = load i8*, i8** %51
%53 = call %struct.argument* @find_argument(i8* %52)
store %struct.argument* %53, %struct.argument** %6
%54 = load %struct.argument*, %struct.argument** %6
%55 = icmp eq %struct.argument* %54, null
br i1 %55, label %56, label %64
56: ; preds = %47
%57 = load i32, i32* @stderr
%58 = load i8**, i8*** %5
%59 = load i32, i32* %8
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %58, i64 %60
%62 = load i8*, i8** %61
%63 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %62)
store i32 1, i32* %3
br label %74
64: ; preds = %47
%65 = load i8*, i8** %7
%66 = load %struct.argument*, %struct.argument** %6
%67 = load i8**, i8*** %5
%68 = load i32, i32* %8
%69 = add nsw i32 %68, 1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %67, i64 %70
%72 = load i8*, i8** %71
%73 = call i32 @ndsctl_do(i8* %65, %struct.argument* %66, i8* %72)
store i32 %73, i32* %3
br label %74
74: ; preds = %64, %56, %45, %37, %21, %13
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
%struct.argument = type { i32 }
@.str = [17 x i8] c"/tmp/ndsctl.sock\00"
@.str.1 = [3 x i8] c"-h\00"
@.str.2 = [3 x i8] c"-s\00"
@stderr = global i32 0
@.str.3 = [21 x i8] c"Unknown command: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call dereferenceable_or_null(17) i8* @strdup(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (...) @usage()
br label %45
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 (...) @usage()
br label %45
14: ; preds = %7
%15 = load i8*, i8** %8
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %14
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i8* @strdup(i8* %20)
br label %22
22: ; preds = %18, %14
%23 = phi i8* [ %21, %18 ], [ %3, %14 ]
%24 = phi i32 [ 3, %18 ], [ 1, %14 ]
%25 = add nuw nsw i32 %24, 2
%26 = icmp ult i32 %25, %0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = tail call i32 (...) @usage()
br label %45
29: ; preds = %22
%30 = zext i32 %24 to i64
%31 = getelementptr inbounds i8*, i8** %1, i64 %30
%32 = load i8*, i8** %31
%33 = tail call %struct.argument* @find_argument(i8* %32)
%34 = icmp eq %struct.argument* %33, null
br i1 %34, label %35, label %39
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %31
%38 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* %37)
br label %45
39: ; preds = %29
%40 = add nuw nsw i32 %24, 1
%41 = zext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %1, i64 %41
%43 = load i8*, i8** %42
%44 = tail call i32 @ndsctl_do(i8* %23, %struct.argument* %33, i8* %43)
br label %45
45: ; preds = %39, %35, %27, %12, %5
%46 = phi i32 [ 0, %5 ], [ 1, %12 ], [ 1, %27 ], [ 1, %35 ], [ %44, %39 ]
ret i32 %46
}