#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 option {
  char *member_0;
  char member_3;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
};

/* Variables and functions */
int EINVAL;
int clickos_domid(char *);
char *clickos_read_script(char *);
int /*<<< orphan*/ clickos_start(int, char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt_long(int, char **, char *, struct option *, int *);
int optind;
int optopt;
int /*<<< orphan*/ stderr;
int cmd_start(int argc, char **argv) {
  char *script, *script_path;
  int opt, domid;
  int option_index = 0;
  static struct option long_options[] = {{"autoattach", 0, 0, 'a'},
                                         {0, 0, 0, 0}};
  if (argv[1] && argv[1][0] != '-') {
    argc--;
    argv++;
  }
  while (1) {
    opt = getopt_long(argc, argv, "ax", long_options, &option_index);
    if (opt == -1)
      break;
    switch (opt) {
    default:
      fprintf(stderr, "option `%c' not supported.\n", optopt);
      break;
    }
  }
  if ((argc - optind + 1) != 2) {
    fprintf(stderr, "wrong number of arguments (expected 2, got %d).\n",
            ((argc - optind) <= 0 ? 0 : (argc - optind)));
    return -EINVAL;
  }
  domid = clickos_domid(argv[optind - 1]);
  script_path = argv[optind];
  fprintf(stderr, "Domain ID for %s: %d\n", argv[optind - 1], domid);
  fprintf(stderr, "Location of click script: %s\n", script_path);
  script = clickos_read_script(script_path);
  clickos_start(domid, "script", script);
  return 0;
}


x86 assembly (clang, -O0):
<cmd_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     119e <cmd_start+0x4e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     119e <cmd_start+0x4e>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    11a3 <cmd_start+0x53>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe5a(%rip),%rdx
lea    0x2e98(%rip),%rcx
lea    -0x2c(%rbp),%r8
call   1030 <getopt_long@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11d3 <cmd_start+0x83>
jmp    11f8 <cmd_start+0xa8>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    0x2e05(%rip),%rax
mov    (%rax),%edx
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    11a3 <cmd_start+0x53>
mov    -0x8(%rbp),%eax
mov    0x2dde(%rip),%rcx
sub    (%rcx),%eax
add    $0x1,%eax
cmp    $0x2,%eax
je     1271 <cmd_start+0x121>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%eax
mov    0x2dba(%rip),%rcx
sub    (%rcx),%eax
cmp    $0x0,%eax
jg     123b <cmd_start+0xeb>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    124a <cmd_start+0xfa>
mov    -0x8(%rbp),%eax
mov    0x2d9b(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%edi
mov    -0x34(%rbp),%edx
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
xor    %eax,%eax
mov    0x2d61(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1319 <cmd_start+0x1c9>
mov    -0x10(%rbp),%rax
mov    0x2d64(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1060 <clickos_domid@plt>
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2d45(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
mov    0x2d23(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x2d26(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x28(%rbp),%ecx
lea    0xd8b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xd86(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1070 <clickos_read_script@plt>
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%edi
mov    -0x18(%rbp),%rdx
lea    0xd82(%rip),%rsi
call   1040 <clickos_start@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_start>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
movl   $0x0,0x4(%rsp)
mov    0x8(%rsi),%rax
test   %rax,%rax
je     1183 <cmd_start+0x33>
lea    0x8(%r14),%rcx
xor    %edx,%edx
cmpb   $0x2d,(%rax)
setne  %dl
cmovne %rcx,%r14
sub    %edx,%ebx
lea    0xe81(%rip),%rdx
lea    0x2ebf(%rip),%rcx
lea    0x4(%rsp),%r8
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <getopt_long@plt>
cmp    $0xffffffff,%eax
je     11f4 <cmd_start+0xa4>
lea    0xe62(%rip),%r15
lea    0xe58(%rip),%r12
lea    0x2e96(%rip),%r13
lea    0x4(%rsp),%rbp
nop
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1030 <getopt_long@plt>
cmp    $0xffffffff,%eax
jne    11c0 <cmd_start+0x70>
mov    0x2de5(%rip),%rbp
movslq 0x0(%rbp),%rax
sub    %eax,%ebx
cmp    $0x1,%ebx
jne    126d <cmd_start+0x11d>
mov    -0x8(%r14,%rax,8),%rdi
call   1060 <clickos_domid@plt>
mov    %eax,%r15d
movslq 0x0(%rbp),%rax
mov    -0x8(%r14,%rax,8),%rdx
mov    (%r14,%rax,8),%rbx
mov    0x2da9(%rip),%r14
mov    (%r14),%edi
lea    0xe2a(%rip),%rsi
xor    %ebp,%ebp
mov    %r15d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r14),%edi
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1070 <clickos_read_script@plt>
lea    0xe2f(%rip),%rsi
mov    %r15d,%edi
mov    %rax,%rdx
call   1040 <clickos_start@plt>
jmp    1296 <cmd_start+0x146>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
xor    %ebp,%ebp
test   %ebx,%ebx
cmovs  %ebp,%ebx
lea    0xda6(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2d34(%rip),%rax
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32, i32 }
@cmd_start.long_options = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8 0, i32 0, i32 97 }, %struct.option zeroinitializer]
@.str = [11 x i8] c"autoattach\00"
@.str.1 = [3 x i8] c"ax\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"option `%c' not supported.\0A\00"
@optopt = global i32 0
@optind = global i32 0
@.str.3 = [49 x i8] c"wrong number of arguments (expected 2, got %d).\0A\00"
@EINVAL = global i32 0
@.str.4 = [22 x i8] c"Domain ID for %s: %d\0A\00"
@.str.5 = [30 x i8] c"Location of click script: %s\0A\00"
@.str.6 = [7 x i8] c"script\00"
define i32 @cmd_start(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %28
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8, i8* %18, i64 0
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp ne i32 %21, 45
br i1 %22, label %23, label %28
23: ; preds = %15
%24 = load i32, i32* %4
%25 = add nsw i32 %24, -1
store i32 %25, i32* %4
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i32 1
store i8** %27, i8*** %5
br label %28
28: ; preds = %23, %15, %2
br label %29
29: ; preds = %28, %42
%30 = load i32, i32* %4
%31 = load i8**, i8*** %5
%32 = call i32 @getopt_long(i32 %30, i8** %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @cmd_start.long_options, i64 0, i64 0), i32* %10)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %36
35: ; preds = %29
br label %43
36: ; preds = %29
%37 = load i32, i32* %8
switch i32 %37, label %38 [
]
38: ; preds = %36
%39 = load i32, i32* @stderr
%40 = load i32, i32* @optopt
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %38
br label %29
43: ; preds = %35
%44 = load i32, i32* %4
%45 = load i32, i32* @optind
%46 = sub nsw i32 %44, %45
%47 = add nsw i32 %46, 1
%48 = icmp ne i32 %47, 2
br i1 %48, label %49, label %65
49: ; preds = %43
%50 = load i32, i32* @stderr
%51 = load i32, i32* %4
%52 = load i32, i32* @optind
%53 = sub nsw i32 %51, %52
%54 = icmp sle i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %49
br label %60
56: ; preds = %49
%57 = load i32, i32* %4
%58 = load i32, i32* @optind
%59 = sub nsw i32 %57, %58
br label %60
60: ; preds = %56, %55
%61 = phi i32 [ 0, %55 ], [ %59, %56 ]
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %61)
%63 = load i32, i32* @EINVAL
%64 = sub nsw i32 0, %63
store i32 %64, i32* %3
br label %95
65: ; preds = %43
%66 = load i8**, i8*** %5
%67 = load i32, i32* @optind
%68 = sub nsw i32 %67, 1
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %66, i64 %69
%71 = load i8*, i8** %70
%72 = call i32 @clickos_domid(i8* %71)
store i32 %72, i32* %9
%73 = load i8**, i8*** %5
%74 = load i32, i32* @optind
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8*, i8** %73, i64 %75
%77 = load i8*, i8** %76
store i8* %77, i8** %7
%78 = load i32, i32* @stderr
%79 = load i8**, i8*** %5
%80 = load i32, i32* @optind
%81 = sub nsw i32 %80, 1
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8*, i8** %79, i64 %82
%84 = load i8*, i8** %83
%85 = load i32, i32* %9
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %84, i32 %85)
%87 = load i32, i32* @stderr
%88 = load i8*, i8** %7
%89 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %88)
%90 = load i8*, i8** %7
%91 = call i8* @clickos_read_script(i8* %90)
store i8* %91, i8** %6
%92 = load i32, i32* %9
%93 = load i8*, i8** %6
%94 = call i32 @clickos_start(i32 %92, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %93)
store i32 0, i32* %3
br label %95
95: ; preds = %65, %60
%96 = load i32, i32* %3
ret i32 %96
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32 }
@cmd_start.long_options = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i8 0, i32 0, i32 97 }, %struct.option zeroinitializer]
@.str = [11 x i8] c"autoattach\00"
@.str.1 = [3 x i8] c"ax\00"
@stderr = global i32 0
@.str.2 = [28 x i8] c"option `%c' not supported.\0A\00"
@optopt = global i32 0
@optind = global i32 0
@.str.3 = [49 x i8] c"wrong number of arguments (expected 2, got %d).\0A\00"
@EINVAL = global i32 0
@.str.4 = [22 x i8] c"Domain ID for %s: %d\0A\00"
@.str.5 = [30 x i8] c"Location of click script: %s\0A\00"
@.str.6 = [7 x i8] c"script\00"
define i32 @cmd_start(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 45
%11 = select i1 %10, i8** %1, i8** %5
%12 = xor i1 %10, true
%13 = sext i1 %12 to i32
%14 = add nsw i32 %13, %0
br label %15
15: ; preds = %8, %2
%16 = phi i8** [ %1, %2 ], [ %11, %8 ]
%17 = phi i32 [ %0, %2 ], [ %14, %8 ]
%18 = call i32 @getopt_long(i32 %17, i8** %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @cmd_start.long_options, i64 0, i64 0), i32* %3)
%19 = icmp eq i32 %18, -1
br i1 %19, label %26, label %20
20: ; preds = %15, %20
%21 = load i32, i32* @stderr
%22 = load i32, i32* @optopt
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = call i32 @getopt_long(i32 %17, i8** %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %struct.option* getelementptr inbounds ([2 x %struct.option], [2 x %struct.option]* @cmd_start.long_options, i64 0, i64 0), i32* %3)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %20
26: ; preds = %20, %15
%27 = load i32, i32* @optind
%28 = sub nsw i32 %17, %27
%29 = icmp eq i32 %28, 1
br i1 %29, label %37, label %30
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = icmp sgt i32 %28, 0
%33 = select i1 %32, i32 %28, i32 0
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.3, i64 0, i64 0), i32 %33)
%35 = load i32, i32* @EINVAL
%36 = sub nsw i32 0, %35
br label %57
37: ; preds = %26
%38 = add nsw i32 %27, -1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %16, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 @clickos_domid(i8* %41)
%43 = load i32, i32* @optind
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %16, i64 %44
%46 = load i8*, i8** %45
%47 = load i32, i32* @stderr
%48 = add nsw i32 %43, -1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %16, i64 %49
%51 = load i8*, i8** %50
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %51, i32 %42)
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i64 0, i64 0), i8* %46)
%55 = call i8* @clickos_read_script(i8* %46)
%56 = call i32 @clickos_start(i32 %42, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %55)
br label %57
57: ; preds = %37, %30
%58 = phi i32 [ %36, %30 ], [ 0, %37 ]
ret i32 %58
}