#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*/ flag;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_1;
};

/* Variables and functions */
int /*<<< orphan*/ SMBCloseDevice();
char *SMBGetErrorString(int);
int SMBOpenDeviceVIDPID(int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getopt_long(int, char **, char *, struct option *, int *);
unsigned char *malloc(int);
int /*<<< orphan*/ *optarg;
int /*<<< orphan*/ printHeader();
int /*<<< orphan*/ printUsage();
int /*<<< orphan*/ printf(char *, ...);
#define required_argument 128
char *strtok(int /*<<< orphan*/ *, char *);
int strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  int status;
  int i, c;
  char *tmp;
  int vid = 0;
  int pid = 0;
  unsigned char *tempStr = malloc(256);
  unsigned int tempWord;
  static struct option long_options[] = {{"device", required_argument, 0, 'd'},
                                         {0, 0, 0, 0}};
  while (1) {
    int option_index = 0;
    c = getopt_long(argc, argv, "d:", long_options, &option_index);
    if (c == -1)
      break;
    switch (c) {
    case 0:
      if (long_options[option_index].flag != 0)
        break;
    case 'd':
      tmp = strtok(optarg, ":");
      vid = strtoul(tmp, NULL, 16);
      tmp = strtok(NULL, ":");
      if (tmp != NULL)
        pid = strtoul(tmp, NULL, 16);
      break;
    }
  }
  if ((vid == 0) | (pid == 0)) {
    printUsage();
    exit(0);
  }
  printHeader();
  printf("Initializing device: %04X:%04X\n", vid, pid);
  SMBOpenDeviceVIDPID(vid, pid);
  SMBCloseDevice();
  if ((status = SMBOpenDeviceVIDPID(0x04B4, 0x8613)) > 0) {
    printf("Success. SMBusb Firmware Version: %d.%d.%d\n", status & 0xFF,
           (status >> 8) & 0xFF, (status >> 16) & 0xFF);
  } else {
    printf("Error: %s\n", SMBGetErrorString(status));
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    $0x100,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe10(%rip),%rdx
lea    0x2e82(%rip),%rcx
lea    -0x40(%rbp),%r8
call   1030 <getopt_long@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1219 <main+0x69>
jmp    12d0 <main+0x120>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x44(%rbp)
test   %eax,%eax
je     123d <main+0x8d>
jmp    122c <main+0x7c>
mov    -0x44(%rbp),%eax
sub    $0x64,%eax
je     1263 <main+0xb3>
jmp    12cb <main+0x11b>
movslq -0x40(%rbp),%rcx
lea    0x2e38(%rip),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
cmpl   $0x0,0xc(%rax)
je     125e <main+0xae>
jmp    12cb <main+0x11b>
jmp    1263 <main+0xb3>
mov    0x2d8e(%rip),%rax
mov    (%rax),%rdi
lea    0xd94(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x2c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd6b(%rip),%rsi
call   1090 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12c6 <main+0x116>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   10a0 <strtoul@plt>
mov    %eax,-0x30(%rbp)
jmp    12cb <main+0x11b>
jmp    11e2 <main+0x32>
cmpl   $0x0,-0x2c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x0,-0x30(%rbp)
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
or     %ecx,%eax
cmp    $0x0,%eax
je     1302 <main+0x152>
mov    $0x0,%al
call   1070 <printUsage@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1080 <printHeader@plt>
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
lea    0xcf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1050 <SMBOpenDeviceVIDPID@plt>
mov    $0x0,%al
call   10d0 <SMBCloseDevice@plt>
mov    $0x4b4,%edi
mov    $0x8613,%esi
call   1050 <SMBOpenDeviceVIDPID@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    137e <main+0x1ce>
mov    -0x14(%rbp),%esi
and    $0xff,%esi
mov    -0x14(%rbp),%edx
sar    $0x8,%edx
and    $0xff,%edx
mov    -0x14(%rbp),%ecx
sar    $0x10,%ecx
and    $0xff,%ecx
lea    0xcb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    139e <main+0x1ee>
mov    -0x14(%rbp),%edi
call   10c0 <SMBGetErrorString@plt>
mov    %rax,%rsi
lea    0xcc6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x50,%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,%r14
mov    %edi,%r12d
xor    %eax,%eax
mov    %rax,0x10(%rsp)
lea    0xe45(%rip),%rbx
lea    0x2eb7(%rip),%r13
lea    0xc(%rsp),%rbp
movl   $0x0,0x8(%rsp)
jmp    11e9 <main+0x49>
nopl   0x0(%rax,%rax,1)
cmp    $0xffffffff,%eax
je     1275 <main+0xd5>
movl   $0x0,0xc(%rsp)
mov    %r12d,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1030 <getopt_long@plt>
test   %eax,%eax
je     1210 <main+0x70>
cmp    $0x64,%eax
jne    11e0 <main+0x40>
jmp    1221 <main+0x81>
movslq 0xc(%rsp),%rax
lea    (%rax,%rax,2),%rax
cmpl   $0x0,0xc(%r13,%rax,8)
jne    11e9 <main+0x49>
mov    0x2dd0(%rip),%rax
mov    (%rax),%rdi
lea    0xdd6(%rip),%r15
mov    %r15,%rsi
call   1080 <strtok@plt>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <strtoul@plt>
mov    %eax,0x8(%rsp)
xor    %edi,%edi
mov    %r15,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     11e9 <main+0x49>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1090 <strtoul@plt>
mov    %rax,0x10(%rsp)
jmp    11e9 <main+0x49>
mov    0x10(%rsp),%rbx
test   %ebx,%ebx
mov    0x8(%rsp),%r12d
je     12f1 <main+0x151>
test   %r12d,%r12d
je     12f1 <main+0x151>
xor    %eax,%eax
call   1070 <printHeader@plt>
lea    0xd74(%rip),%rdi
mov    %r12d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r12d,%edi
mov    %ebx,%esi
call   1050 <SMBOpenDeviceVIDPID@plt>
xor    %eax,%eax
call   10c0 <SMBCloseDevice@plt>
mov    $0x4b4,%edi
mov    $0x8613,%esi
call   1050 <SMBOpenDeviceVIDPID@plt>
test   %eax,%eax
jle    12ff <main+0x15f>
movzbl %al,%esi
movzbl %ah,%edx
shr    $0x10,%eax
movzbl %al,%ecx
lea    0xd51(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1060 <printUsage@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    %eax,%edi
call   10b0 <SMBGetErrorString@plt>
lea    0xd49(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32, i32, i32 }
@main.long_options = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8 -128, i32 0, i32 100, i32 0 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"device\00"
@.str.1 = [3 x i8] c"d:\00"
@optarg = global i32* null
@.str.2 = [2 x i8] c":\00"
@.str.3 = [32 x i8] c"Initializing device: %04X:%04X\0A\00"
@.str.4 = [44 x i8] c"Success. SMBusb Firmware Version: %d.%d.%d\0A\00"
@.str.5 = [11 x i8] c"Error: %s\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 i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
store i32 0, i32* %11
%15 = call i8* @malloc(i32 256)
store i8* %15, i8** %12
br label %16
16: ; preds = %2, %46
store i32 0, i32* %14
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt_long(i32 %17, i8** %18, 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]* @main.long_options, i64 0, i64 0), i32* %14)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %23
22: ; preds = %16
br label %47
23: ; preds = %16
%24 = load i32, i32* %8
switch i32 %24, label %46 [
i32 0, label %25
i32 100, label %34
]
25: ; preds = %23
%26 = load i32, i32* %14
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [2 x %struct.option], [2 x %struct.option]* @main.long_options, i64 0, i64 %27
%29 = getelementptr inbounds %struct.option, %struct.option* %28, i32 0, i32 2
%30 = load i32, i32* %29
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %25
br label %46
33: ; preds = %25
br label %34
34: ; preds = %23, %33
%35 = load i32*, i32** @optarg
%36 = call i8* @strtok(i32* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %36, i8** %9
%37 = load i8*, i8** %9
%38 = call i32 @strtoul(i8* %37, i32* null, i32 16)
store i32 %38, i32* %10
%39 = call i8* @strtok(i32* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %39, i8** %9
%40 = load i8*, i8** %9
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %45
42: ; preds = %34
%43 = load i8*, i8** %9
%44 = call i32 @strtoul(i8* %43, i32* null, i32 16)
store i32 %44, i32* %11
br label %45
45: ; preds = %42, %34
br label %46
46: ; preds = %23, %45, %32
br label %16
47: ; preds = %22
%48 = load i32, i32* %10
%49 = icmp eq i32 %48, 0
%50 = zext i1 %49 to i32
%51 = load i32, i32* %11
%52 = icmp eq i32 %51, 0
%53 = zext i1 %52 to i32
%54 = or i32 %50, %53
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %47
%57 = call i32 (...) @printUsage()
%58 = call i32 @exit(i32 0)
unreachable
59: ; preds = %47
%60 = call i32 (...) @printHeader()
%61 = load i32, i32* %10
%62 = load i32, i32* %11
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %61, i32 %62)
%64 = load i32, i32* %10
%65 = load i32, i32* %11
%66 = call i32 @SMBOpenDeviceVIDPID(i32 %64, i32 %65)
%67 = call i32 (...) @SMBCloseDevice()
%68 = call i32 @SMBOpenDeviceVIDPID(i32 1204, i32 34323)
store i32 %68, i32* %6
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %80
70: ; preds = %59
%71 = load i32, i32* %6
%72 = and i32 %71, 255
%73 = load i32, i32* %6
%74 = ashr i32 %73, 8
%75 = and i32 %74, 255
%76 = load i32, i32* %6
%77 = ashr i32 %76, 16
%78 = and i32 %77, 255
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %72, i32 %75, i32 %78)
br label %85
80: ; preds = %59
%81 = load i32, i32* %6
%82 = call i8* @SMBGetErrorString(i32 %81)
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %82)
%84 = call i32 @exit(i32 0)
unreachable
85: ; preds = %70
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32, i32, i32 }
@main.long_options = internal global [2 x %struct.option] [%struct.option { i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8 -128, i32 0, i32 100, i32 0 }, %struct.option zeroinitializer]
@.str = [7 x i8] c"device\00"
@.str.1 = [3 x i8] c"d:\00"
@optarg = global i32* null
@.str.2 = [2 x i8] c":\00"
@.str.3 = [32 x i8] c"Initializing device: %04X:%04X\0A\00"
@.str.4 = [44 x i8] c"Success. SMBusb Firmware Version: %d.%d.%d\0A\00"
@.str.5 = [11 x i8] c"Error: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
br label %5
5: ; preds = %23, %2
%6 = phi i32 [ 0, %2 ], [ %24, %23 ]
%7 = phi i32 [ 0, %2 ], [ %25, %23 ]
store i32 0, i32* %3
%8 = call i32 @getopt_long(i32 %0, i8** %1, 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]* @main.long_options, i64 0, i64 0), i32* %3)
switch i32 %8, label %23 [
i32 -1, label %26
i32 0, label %9
i32 100, label %15
]
9: ; preds = %5
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds [2 x %struct.option], [2 x %struct.option]* @main.long_options, i64 0, i64 %11, i32 2
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %5, %9
%16 = load i32*, i32** @optarg
%17 = call i8* @strtok(i32* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @strtoul(i8* nocapture %17, i32* null, i32 16)
%19 = call i8* @strtok(i32* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%20 = icmp eq i8* %19, null
br i1 %20, label %23, label %21
21: ; preds = %15
%22 = call i32 @strtoul(i8* nocapture %19, i32* null, i32 16)
br label %23
23: ; preds = %9, %21, %15, %5
%24 = phi i32 [ %22, %21 ], [ %6, %15 ], [ %6, %9 ], [ %6, %5 ]
%25 = phi i32 [ %18, %21 ], [ %18, %15 ], [ %7, %9 ], [ %7, %5 ]
br label %5
26: ; preds = %5
%27 = icmp eq i32 %7, 0
%28 = icmp eq i32 %6, 0
%29 = or i1 %28, %27
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = call i32 (...) @printUsage()
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %26
%34 = call i32 (...) @printHeader()
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i32 %7, i32 %6)
%36 = call i32 @SMBOpenDeviceVIDPID(i32 %7, i32 %6)
%37 = call i32 (...) @SMBCloseDevice()
%38 = call i32 @SMBOpenDeviceVIDPID(i32 1204, i32 34323)
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %47
40: ; preds = %33
%41 = and i32 %38, 255
%42 = lshr i32 %38, 8
%43 = and i32 %42, 255
%44 = lshr i32 %38, 16
%45 = and i32 %44, 255
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0), i32 %41, i32 %43, i32 %45)
ret i32 0
47: ; preds = %33
%48 = call i8* @SMBGetErrorString(i32 %38)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %48)
%50 = call i32 @exit(i32 0)
unreachable
}