#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 /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ *strstr(char *, char *);
int /*<<< orphan*/ usage();
int vreboot_connect(char const *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int ret = -1;
  int i;
  const char *sockpath = "/dev/reboot";
  for (i = 1; i < argc; i++) {
    const char *arg = argv[i];
    const char *opt = argv[i + 1];
    if (strcmp(arg, "--socket") == 0) {
      sockpath = opt;
      i++;
    } else if (strcmp(arg, "--help") == 0) {
      break;
    } else {
      fprintf(stderr, "Invalid option %s\n", arg);
      break;
    }
  }
  if (argc != i) {
    usage();
  } else {
    int fd = vreboot_connect(sockpath, true);
    if (fd != -1) {
      if (strstr(argv[0], "halt") != NULL) {
        write(fd, "halt\n", 5);
      } else {
        write(fd, "reboot\n", 7);
      }
      close(fd);
      ret = 0;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
lea    0xe6c(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1250 <main+0xe0>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1200 <main+0x90>
mov    -0x30(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    123d <main+0xcd>
mov    -0x28(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    121f <main+0xaf>
jmp    1250 <main+0xe0>
mov    0x2dba(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xde9(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1250 <main+0xe0>
jmp    1242 <main+0xd2>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119f <main+0x2f>
mov    -0x8(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1268 <main+0xf8>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    12e1 <main+0x171>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1070 <vreboot_connect@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
je     12dc <main+0x16c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xd9e(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
je     12b9 <main+0x149>
mov    -0x34(%rbp),%edi
lea    0xd8a(%rip),%rsi
mov    $0x5,%edx
call   1030 <write@plt>
jmp    12cd <main+0x15d>
mov    -0x34(%rbp),%edi
lea    0xd77(%rip),%rsi
mov    $0x7,%edx
call   1030 <write@plt>
mov    -0x34(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x14(%rbp)
jmp    12e1 <main+0x171>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
mov    %edi,%r14d
cmp    $0x2,%edi
jl     11bb <main+0x4b>
mov    0x8(%r15),%rbp
mov    0x10(%r15),%r13
lea    0xe74(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
mov    %r14d,0xc(%rsp)
je     1210 <main+0xa0>
lea    0xe4f(%rip),%rcx
mov    $0x1,%ebx
jmp    1265 <main+0xf5>
mov    $0x1,%ebx
lea    0xe39(%rip),%rdi
cmp    %r14d,%ebx
jne    12a5 <main+0x135>
mov    $0x1,%esi
call   1070 <vreboot_connect@plt>
cmp    $0xffffffff,%eax
je     12ac <main+0x13c>
mov    %eax,%ebx
mov    (%r15),%rdi
lea    0xe40(%rip),%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     12b3 <main+0x143>
lea    0xe30(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
jmp    12c1 <main+0x151>
mov    %r14d,%eax
mov    %rax,0x10(%rsp)
mov    $0x3,%r12d
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    0x10(%rsp),%r12
jae    12de <main+0x16e>
mov    (%r15,%r12,8),%rbp
mov    0x8(%r15,%r12,8),%r14
mov    %rbp,%rdi
lea    0xdbe(%rip),%rsi
call   1050 <strcmp@plt>
add    $0x2,%r12
add    $0x2,%ebx
mov    %r13,%rcx
mov    %r14,%r13
test   %rax,%rax
je     1230 <main+0xc0>
mov    %rcx,%r12
lea    0xda6(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1294 <main+0x124>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
mov    %rbp,%rdx
call   1060 <fprintf@plt>
mov    0xc(%rsp),%r14d
mov    %r12,%rdi
cmp    %r14d,%ebx
je     11d0 <main+0x60>
xor    %eax,%eax
call   1080 <usage@plt>
mov    $0xffffffff,%eax
jmp    12cf <main+0x15f>
lea    0xd80(%rip),%rsi
mov    %ebx,%edi
mov    $0x7,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
mov    %r12d,%ebx
mov    0xc(%rsp),%r14d
cmp    %r14d,%ebx
je     11d0 <main+0x60>
jmp    12a5 <main+0x135>

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

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/reboot\00"
@.str.1 = [9 x i8] c"--socket\00"
@.str.2 = [7 x i8] c"--help\00"
@stderr = global i32 0
@.str.3 = [19 x i8] c"Invalid option %s\0A\00"
@.str.4 = [5 x i8] c"halt\00"
@.str.5 = [6 x i8] c"halt\0A\00"
@.str.6 = [8 x i8] c"reboot\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %38
4: ; preds = %2
%5 = zext i32 %0 to i64
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i64 @strcmp(i8* %7, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %31, label %22
12: ; preds = %31
%13 = getelementptr inbounds i8*, i8** %1, i64 %34
%14 = load i8*, i8** %13
%15 = add nuw nsw i64 %33, 3
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = load i8*, i8** %16
%18 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %31, label %20
20: ; preds = %12
%21 = trunc i64 %34 to i32
br label %22
22: ; preds = %20, %4
%23 = phi i32 [ %21, %20 ], [ 1, %4 ]
%24 = phi i8* [ %32, %20 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %4 ]
%25 = phi i8* [ %14, %20 ], [ %7, %4 ]
%26 = tail call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %38, label %28
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %38
31: ; preds = %4, %12
%32 = phi i8* [ %17, %12 ], [ %9, %4 ]
%33 = phi i64 [ %34, %12 ], [ 1, %4 ]
%34 = add nuw nsw i64 %33, 2
%35 = icmp ult i64 %34, %5
br i1 %35, label %12, label %36
36: ; preds = %31
%37 = trunc i64 %34 to i32
br label %38
38: ; preds = %36, %2, %22, %28
%39 = phi i8* [ %24, %22 ], [ %24, %28 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), %2 ], [ %32, %36 ]
%40 = phi i32 [ %23, %22 ], [ %23, %28 ], [ 1, %2 ], [ %37, %36 ]
%41 = icmp eq i32 %40, %0
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = tail call i32 (...) @usage()
br label %57
44: ; preds = %38
%45 = tail call i32 @vreboot_connect(i8* %39, i32 1)
%46 = icmp eq i32 %45, -1
br i1 %46, label %57, label %47
47: ; preds = %44
%48 = load i8*, i8** %1
%49 = tail call i32* @strstr(i8* dereferenceable(1) %48, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%50 = icmp eq i32* %49, null
br i1 %50, label %53, label %51
51: ; preds = %47
%52 = tail call i32 @write(i32 %45, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 5)
br label %55
53: ; preds = %47
%54 = tail call i32 @write(i32 %45, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i32 7)
br label %55
55: ; preds = %53, %51
%56 = tail call i32 @close(i32 %45)
br label %57
57: ; preds = %44, %55, %42
%58 = phi i32 [ -1, %42 ], [ 0, %55 ], [ -1, %44 ]
ret i32 %58
}