#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 EXIT_SUCCESS;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ USBDEVFS_CONNECT;
int /*<<< orphan*/ USBDEVFS_DISCONNECT;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_usage(int, char **);
int /*<<< orphan*/ printf(char *, char *, char *, char *, ...);
int send_usb_cmd(int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  if (argc != 3) {
    print_usage(argc, argv);
    return EXIT_FAILURE;
  } else {
    enum Command { CMD_CONNECT, CMD_DISCONNECT, CMD_RECONNECT } cmd;
    if (strcmp(argv[1], "connect") == 0) {
      cmd = CMD_CONNECT;
    } else if (strcmp(argv[1], "disconnect") == 0) {
      cmd = CMD_DISCONNECT;
    } else if (strcmp(argv[1], "reconnect") == 0) {
      cmd = CMD_RECONNECT;
    } else {
      print_usage(argc, argv);
      return EXIT_FAILURE;
    }
    int fd = open(argv[2], O_RDWR);
    if (fd < 0) {
      perror(argv[1]);
      return EXIT_FAILURE;
    } else {
      int ret = 0;
      switch (cmd) {
      case CMD_CONNECT:
        ret = send_usb_cmd(fd, USBDEVFS_CONNECT);
        break;
      case CMD_DISCONNECT:
        ret = send_usb_cmd(fd, USBDEVFS_DISCONNECT);
        break;
      case CMD_RECONNECT:
        ret = send_usb_cmd(fd, USBDEVFS_DISCONNECT);
        if (ret < 0)
          goto error_handling;
        sleep(1);
        ret = send_usb_cmd(fd, USBDEVFS_CONNECT);
        break;
      default:
        assert(!"Never reached");
      }
    error_handling:
      if (ret < 0) {
        printf("%s: Could not issue usb %s on %s: %s\n", argv[0], argv[1],
               argv[2], strerror(errno));
        close(fd);
        return EXIT_FAILURE;
      } else {
        printf("%s: %s of %s successful\n", argv[0], argv[1], argv[2]);
        close(fd);
        return EXIT_SUCCESS;
      }
    }
  }
}


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)
cmpl   $0x3,-0x8(%rbp)
je     11dd <main+0x3d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10a0 <print_usage@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    142d <main+0x28d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe21(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1207 <main+0x67>
movl   $0x0,-0x14(%rbp)
jmp    1282 <main+0xe2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdea(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1231 <main+0x91>
movl   $0x1,-0x14(%rbp)
jmp    127d <main+0xdd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdcb(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    125b <main+0xbb>
movl   $0x2,-0x14(%rbp)
jmp    1278 <main+0xd8>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10a0 <print_usage@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    142d <main+0x28d>
jmp    127d <main+0xdd>
jmp    1282 <main+0xe2>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    12c3 <main+0x123>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <perror@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    142d <main+0x28d>
movl   $0x0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
test   %eax,%eax
je     12ff <main+0x15f>
jmp    12dd <main+0x13d>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
je     1318 <main+0x178>
jmp    12ee <main+0x14e>
mov    -0x20(%rbp),%eax
sub    $0x2,%eax
je     1331 <main+0x191>
jmp    1377 <main+0x1d7>
mov    -0x18(%rbp),%edi
mov    0x2cd7(%rip),%rax
mov    (%rax),%esi
call   1070 <send_usb_cmd@plt>
mov    %eax,-0x1c(%rbp)
jmp    137e <main+0x1de>
mov    -0x18(%rbp),%edi
mov    0x2cb6(%rip),%rax
mov    (%rax),%esi
call   1070 <send_usb_cmd@plt>
mov    %eax,-0x1c(%rbp)
jmp    137e <main+0x1de>
mov    -0x18(%rbp),%edi
mov    0x2c9d(%rip),%rax
mov    (%rax),%esi
call   1070 <send_usb_cmd@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1354 <main+0x1b4>
jmp    1383 <main+0x1e3>
mov    $0x1,%edi
call   10c0 <sleep@plt>
mov    -0x18(%rbp),%edi
mov    0x2c78(%rip),%rax
mov    (%rax),%esi
call   1070 <send_usb_cmd@plt>
mov    %eax,-0x1c(%rbp)
jmp    137e <main+0x1de>
xor    %edi,%edi
call   1060 <assert@plt>
jmp    1383 <main+0x1e3>
cmpl   $0x0,-0x1c(%rbp)
jge    13f4 <main+0x254>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2c11(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    %rax,%r8
lea    0xc4f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    0x2bd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    142d <main+0x28d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rcx
lea    0xc37(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    0x2b90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    11f4 <main+0x54>
mov    0x8(%rbx),%rdi
lea    0xe52(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1208 <main+0x68>
mov    0x8(%rbx),%rdi
lea    0xe30(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     120c <main+0x6c>
mov    0x8(%rbx),%rdi
lea    0xe26(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1213 <main+0x73>
mov    $0x3,%edi
mov    %rbx,%rsi
call   10a0 <print_usage@plt>
mov    0x2dbd(%rip),%rax
jmp    12f4 <main+0x154>
xor    %ebp,%ebp
jmp    1218 <main+0x78>
mov    $0x1,%ebp
jmp    1218 <main+0x78>
mov    $0x2,%ebp
mov    0x10(%rbx),%rdi
mov    0x2dc5(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     12ff <main+0x15f>
mov    %eax,%r12d
mov    0x2da4(%rip),%r14
test   %ebp,%ebp
je     1272 <main+0xd2>
cmp    $0x2,%ebp
je     1253 <main+0xb3>
cmp    $0x1,%ebp
jne    12c5 <main+0x125>
mov    0x2d87(%rip),%r14
jmp    1272 <main+0xd2>
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
call   1070 <send_usb_cmd@plt>
test   %eax,%eax
js     1281 <main+0xe1>
mov    $0x1,%edi
call   10c0 <sleep@plt>
mov    (%r14),%esi
mov    %r12d,%edi
call   1070 <send_usb_cmd@plt>
test   %eax,%eax
jns    12cc <main+0x12c>
mov    (%rbx),%r14
mov    0x8(%rbx),%r15
mov    0x10(%rbx),%rbx
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd74(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12d,%edi
call   1040 <close@plt>
mov    0x2cfd(%rip),%rax
jmp    12f4 <main+0x154>
xor    %edi,%edi
call   1060 <assert@plt>
mov    (%rbx),%rsi
mov    0x8(%rbx),%rdx
mov    0x10(%rbx),%rcx
lea    0xd5d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r12d,%edi
call   1040 <close@plt>
mov    0x2cc4(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rdi
call   1090 <perror@plt>
mov    0x2cb1(%rip),%rax
jmp    12f4 <main+0x154>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@.str = [8 x i8] c"connect\00"
@.str.1 = [11 x i8] c"disconnect\00"
@.str.2 = [10 x i8] c"reconnect\00"
@O_RDWR = global i32 0
@USBDEVFS_CONNECT = global i32 0
@USBDEVFS_DISCONNECT = global i32 0
@.str.3 = [14 x i8] c"Never reached\00"
@.str.4 = [38 x i8] c"%s: Could not issue usb %s on %s: %s\0A\00"
@errno = global i32 0
@.str.5 = [25 x i8] c"%s: %s of %s successful\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @print_usage(i32 %12, i8** %13)
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %3
br label %116
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 0, i32* %6
br label %44
23: ; preds = %16
%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 ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %23
store i32 1, i32* %6
br label %43
30: ; preds = %23
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %30
store i32 2, i32* %6
br label %42
37: ; preds = %30
%38 = load i32, i32* %4
%39 = load i8**, i8*** %5
%40 = call i32 @print_usage(i32 %38, i8** %39)
%41 = load i32, i32* @EXIT_FAILURE
store i32 %41, i32* %3
br label %116
42: ; preds = %36
br label %43
43: ; preds = %42, %29
br label %44
44: ; preds = %43, %22
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 2
%47 = load i8*, i8** %46
%48 = load i32, i32* @O_RDWR
%49 = call i32 @open(i8* %47, i32 %48)
store i32 %49, i32* %7
%50 = load i32, i32* %7
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %58
52: ; preds = %44
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
%56 = call i32 @perror(i8* %55)
%57 = load i32, i32* @EXIT_FAILURE
store i32 %57, i32* %3
br label %116
58: ; preds = %44
store i32 0, i32* %8
%59 = load i32, i32* %6
switch i32 %59, label %80 [
i32 0, label %60
i32 1, label %64
i32 2, label %68
]
60: ; preds = %58
%61 = load i32, i32* %7
%62 = load i32, i32* @USBDEVFS_CONNECT
%63 = call i32 @send_usb_cmd(i32 %61, i32 %62)
store i32 %63, i32* %8
br label %82
64: ; preds = %58
%65 = load i32, i32* %7
%66 = load i32, i32* @USBDEVFS_DISCONNECT
%67 = call i32 @send_usb_cmd(i32 %65, i32 %66)
store i32 %67, i32* %8
br label %82
68: ; preds = %58
%69 = load i32, i32* %7
%70 = load i32, i32* @USBDEVFS_DISCONNECT
%71 = call i32 @send_usb_cmd(i32 %69, i32 %70)
store i32 %71, i32* %8
%72 = load i32, i32* %8
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %75
74: ; preds = %68
br label %83
75: ; preds = %68
%76 = call i32 @sleep(i32 1)
%77 = load i32, i32* %7
%78 = load i32, i32* @USBDEVFS_CONNECT
%79 = call i32 @send_usb_cmd(i32 %77, i32 %78)
store i32 %79, i32* %8
br label %82
80: ; preds = %58
%81 = call i32 @assert(i32 0)
br label %82
82: ; preds = %80, %75, %64, %60
br label %83
83: ; preds = %82, %74
%84 = load i32, i32* %8
%85 = icmp slt i32 %84, 0
br i1 %85, label %86, label %102
86: ; preds = %83
%87 = load i8**, i8*** %5
%88 = getelementptr inbounds i8*, i8** %87, i64 0
%89 = load i8*, i8** %88
%90 = load i8**, i8*** %5
%91 = getelementptr inbounds i8*, i8** %90, i64 1
%92 = load i8*, i8** %91
%93 = load i8**, i8*** %5
%94 = getelementptr inbounds i8*, i8** %93, i64 2
%95 = load i8*, i8** %94
%96 = load i32, i32* @errno
%97 = call i8* @strerror(i32 %96)
%98 = call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %89, i8* %92, i8* %95, i8* %97)
%99 = load i32, i32* %7
%100 = call i32 @close(i32 %99)
%101 = load i32, i32* @EXIT_FAILURE
store i32 %101, i32* %3
br label %116
102: ; preds = %83
%103 = load i8**, i8*** %5
%104 = getelementptr inbounds i8*, i8** %103, i64 0
%105 = load i8*, i8** %104
%106 = load i8**, i8*** %5
%107 = getelementptr inbounds i8*, i8** %106, i64 1
%108 = load i8*, i8** %107
%109 = load i8**, i8*** %5
%110 = getelementptr inbounds i8*, i8** %109, i64 2
%111 = load i8*, i8** %110
%112 = call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %105, i8* %108, i8* %111)
%113 = load i32, i32* %7
%114 = call i32 @close(i32 %113)
%115 = load i32, i32* @EXIT_SUCCESS
store i32 %115, i32* %3
br label %116
116: ; preds = %102, %86, %52, %37, %11
%117 = load i32, i32* %3
ret i32 %117
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@.str = [8 x i8] c"connect\00"
@.str.1 = [11 x i8] c"disconnect\00"
@.str.2 = [10 x i8] c"reconnect\00"
@O_RDWR = global i32 0
@USBDEVFS_CONNECT = global i32 0
@USBDEVFS_DISCONNECT = global i32 0
@.str.4 = [38 x i8] c"%s: Could not issue usb %s on %s: %s\0A\00"
@errno = global i32 0
@.str.5 = [25 x i8] c"%s: %s of %s successful\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @print_usage(i32 %0, i8** %1)
br label %60
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %21, label %11
11: ; preds = %6
%12 = load i8*, i8** %7
%13 = tail call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %11
%16 = load i8*, i8** %7
%17 = tail call i64 @strcmp(i8* %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32 @print_usage(i32 3, i8** %1)
br label %60
21: ; preds = %15, %11, %6
%22 = phi i32 [ 0, %6 ], [ 1, %11 ], [ 2, %15 ]
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDWR
%26 = tail call i32 @open(i8* %24, i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = load i8*, i8** %7
%30 = tail call i32 @perror(i8* %29)
br label %60
31: ; preds = %21
switch i32 %22, label %39 [
i32 0, label %41
i32 1, label %32
i32 2, label %33
]
32: ; preds = %31
br label %41
33: ; preds = %31
%34 = load i32, i32* @USBDEVFS_DISCONNECT
%35 = tail call i32 @send_usb_cmd(i32 %26, i32 %34)
%36 = icmp slt i32 %35, 0
br i1 %36, label %46, label %37
37: ; preds = %33
%38 = tail call i32 @sleep(i32 1)
br label %41
39: ; preds = %31
%40 = tail call i32 @assert(i32 0)
br label %54
41: ; preds = %31, %32, %37
%42 = phi i32* [ @USBDEVFS_DISCONNECT, %32 ], [ @USBDEVFS_CONNECT, %37 ], [ @USBDEVFS_CONNECT, %31 ]
%43 = load i32, i32* %42
%44 = tail call i32 @send_usb_cmd(i32 %26, i32 %43)
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %54
46: ; preds = %33, %41
%47 = load i8*, i8** %1
%48 = load i8*, i8** %7
%49 = load i8*, i8** %23
%50 = load i32, i32* @errno
%51 = tail call i8* @strerror(i32 %50)
%52 = tail call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* %47, i8* %48, i8* %49, i8* %51)
%53 = tail call i32 @close(i32 %26)
br label %60
54: ; preds = %39, %41
%55 = load i8*, i8** %1
%56 = load i8*, i8** %7
%57 = load i8*, i8** %23
%58 = tail call i32 (i8*, i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %55, i8* %56, i8* %57)
%59 = tail call i32 @close(i32 %26)
br label %60
60: ; preds = %19, %46, %54, %28, %4
%61 = phi i32* [ @EXIT_FAILURE, %4 ], [ @EXIT_FAILURE, %19 ], [ @EXIT_FAILURE, %28 ], [ @EXIT_FAILURE, %46 ], [ @EXIT_SUCCESS, %54 ]
%62 = load i32, i32* %61
ret i32 %62
}