#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_device(int, void *);
int open_device(int *, char *, void **);
int parse_command(int, char **, char **, int *, int *, int *);
int /*<<< orphan*/ printf(char *);
int read_gpio(int, int *, char *, void *, int);
int /*<<< orphan*/ write_gpio(int, char *, void *, int);
int main(int argc, char *argv[]) {
  int file_descriptor;
  int r_w = 0;
  int r_or_w_value = 0;
  int ret_parse;
  char *uio_dev;
  int cha;
  void *virt_addr;
  if ((ret_parse =
           parse_command(argc, argv, &uio_dev, &cha, &r_w, &r_or_w_value)) == 1)
    return 0;
  else if (ret_parse == -1)
    return -1;
  if (open_device(&file_descriptor, uio_dev, &virt_addr) == -1) {
    printf("nodriver aborted!\n");
    return -1;
  }
  if (r_w == 0) {
    if (read_gpio(file_descriptor, &r_or_w_value, uio_dev, virt_addr, cha) ==
        -1) {
      printf("Error on read\n");
      return -1;
    }
  } else
    write_gpio(r_or_w_value, uio_dev, virt_addr, cha);
  close_device(file_descriptor, virt_addr);
  return 0;
}


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   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
lea    -0x18(%rbp),%r8
lea    -0x1c(%rbp),%r9
call   1080 <parse_command@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x1,%eax
jne    11b8 <main+0x58>
movl   $0x0,-0x4(%rbp)
jmp    1273 <main+0x113>
cmpl   $0xffffffff,-0x20(%rbp)
jne    11ce <main+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1273 <main+0x113>
jmp    11d3 <main+0x73>
mov    -0x28(%rbp),%rsi
lea    -0x14(%rbp),%rdi
lea    -0x38(%rbp),%rdx
call   1060 <open_device@plt>
cmp    $0xffffffff,%eax
jne    1205 <main+0xa5>
lea    0xe0c(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1273 <main+0x113>
cmpl   $0x0,-0x18(%rbp)
jne    124d <main+0xed>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
lea    -0x1c(%rbp),%rsi
call   1050 <read_gpio@plt>
cmp    $0xffffffff,%eax
jne    1248 <main+0xe8>
lea    0xddc(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1273 <main+0x113>
jmp    1260 <main+0x100>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1030 <write_gpio@plt>
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rsi
call   1070 <close_device@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movl   $0x0,0x8(%rsp)
movl   $0x0,(%rsp)
lea    0x18(%rsp),%rdx
lea    0x4(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %rsp,%r9
call   1080 <parse_command@plt>
xor    %ebx,%ebx
cmp    $0x1,%eax
je     121b <main+0xbb>
cmp    $0xffffffff,%eax
jne    11a2 <main+0x42>
mov    $0xffffffff,%ebx
jmp    121b <main+0xbb>
mov    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%rdx
call   1060 <open_device@plt>
cmp    $0xffffffff,%eax
je     11da <main+0x7a>
cmpl   $0x0,0x8(%rsp)
je     11ed <main+0x8d>
mov    (%rsp),%edi
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%rdx
mov    0x4(%rsp),%ecx
call   1030 <write_gpio@plt>
jmp    120d <main+0xad>
lea    0xe2d(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
jmp    121b <main+0xbb>
mov    0xc(%rsp),%edi
mov    0x18(%rsp),%rdx
mov    0x10(%rsp),%rcx
mov    0x4(%rsp),%r8d
mov    %rsp,%rsi
call   1050 <read_gpio@plt>
cmp    $0xffffffff,%eax
je     1223 <main+0xc3>
mov    0xc(%rsp),%edi
mov    0x10(%rsp),%rsi
call   1070 <close_device@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xdd6(%rip),%rdi
jmp    11e1 <main+0x81>

LLVM IR (-O0):
@.str = [19 x i8] c"nodriver aborted!\0A\00"
@.str.1 = [15 x i8] c"Error on read\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 i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @parse_command(i32 %13, i8** %14, i8** %10, i32* %11, i32* %7, i32* %8)
store i32 %15, i32* %9
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %18
17: ; preds = %2
store i32 0, i32* %3
br label %52
18: ; preds = %2
%19 = load i32, i32* %9
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 -1, i32* %3
br label %52
22: ; preds = %18
br label %23
23: ; preds = %22
%24 = load i8*, i8** %10
%25 = call i32 @open_device(i32* %6, i8* %24, i8** %12)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %52
29: ; preds = %23
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = load i32, i32* %6
%34 = load i8*, i8** %10
%35 = load i8*, i8** %12
%36 = load i32, i32* %11
%37 = call i32 @read_gpio(i32 %33, i32* %8, i8* %34, i8* %35, i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %32
%40 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %52
41: ; preds = %32
br label %48
42: ; preds = %29
%43 = load i32, i32* %8
%44 = load i8*, i8** %10
%45 = load i8*, i8** %12
%46 = load i32, i32* %11
%47 = call i32 @write_gpio(i32 %43, i8* %44, i8* %45, i32 %46)
br label %48
48: ; preds = %42, %41
%49 = load i32, i32* %6
%50 = load i8*, i8** %12
%51 = call i32 @close_device(i32 %49, i8* %50)
store i32 0, i32* %3
br label %52
52: ; preds = %48, %39, %27, %21, %17
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
@str = [14 x i8] c"Error on read\00"
@str.2 = [18 x i8] c"nodriver aborted!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%11 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%12 = bitcast i8** %6 to i8*
%13 = bitcast i32* %7 to i8*
%14 = bitcast i8** %8 to i8*
%15 = call i32 @parse_command(i32 %0, i8** %1, i8** %6, i32* %7, i32* %4, i32* %5)
switch i32 %15, label %17 [
i32 1, label %45
i32 -1, label %16
]
16: ; preds = %2
br label %45
17: ; preds = %2
%18 = load i8*, i8** %6
%19 = call i32 @open_device(i32* %3, i8* %18, i8** %8)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0))
br label %45
23: ; preds = %17
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %23
%27 = load i32, i32* %3
%28 = load i8*, i8** %6
%29 = load i8*, i8** %8
%30 = load i32, i32* %7
%31 = call i32 @read_gpio(i32 %27, i32* %5, i8* %28, i8* %29, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %41
33: ; preds = %26
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %45
35: ; preds = %23
%36 = load i32, i32* %5
%37 = load i8*, i8** %6
%38 = load i8*, i8** %8
%39 = load i32, i32* %7
%40 = call i32 @write_gpio(i32 %36, i8* %37, i8* %38, i32 %39)
br label %41
41: ; preds = %26, %35
%42 = load i32, i32* %3
%43 = load i8*, i8** %8
%44 = call i32 @close_device(i32 %42, i8* %43)
br label %45
45: ; preds = %2, %41, %33, %21, %16
%46 = phi i32 [ -1, %16 ], [ -1, %21 ], [ -1, %33 ], [ 0, %41 ], [ 0, %2 ]
ret i32 %46
}