#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 /*<<< orphan*/ read_gpio(int *, 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)
    read_gpio(&r_or_w_value, virt_addr, cha);
  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    124a <main+0xea>
cmpl   $0xffffffff,-0x20(%rbp)
jne    11ce <main+0x6e>
movl   $0xffffffff,-0x4(%rbp)
jmp    124a <main+0xea>
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    124a <main+0xea>
cmpl   $0x0,-0x18(%rbp)
jne    1224 <main+0xc4>
mov    -0x38(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    -0x1c(%rbp),%rdi
call   1050 <read_gpio@plt>
jmp    1237 <main+0xd7>
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    $0x30,%rsp
movl   $0x0,0x14(%rsp)
movl   $0x0,0xc(%rsp)
lea    0x28(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0x14(%rsp),%r8
lea    0xc(%rsp),%r9
call   1080 <parse_command@plt>
xor    %ebx,%ebx
cmp    $0x1,%eax
je     120e <main+0xae>
cmp    $0xffffffff,%eax
jne    11a1 <main+0x41>
mov    $0xffffffff,%ebx
jmp    120e <main+0xae>
mov    0x28(%rsp),%rsi
lea    0x24(%rsp),%rdi
lea    0x18(%rsp),%rdx
call   1060 <open_device@plt>
cmp    $0xffffffff,%eax
je     11da <main+0x7a>
cmpl   $0x0,0x14(%rsp)
je     11ed <main+0x8d>
mov    0xc(%rsp),%edi
mov    0x28(%rsp),%rsi
mov    0x18(%rsp),%rdx
mov    0x10(%rsp),%ecx
call   1030 <write_gpio@plt>
jmp    1200 <main+0xa0>
lea    0xe1f(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
jmp    120e <main+0xae>
mov    0x18(%rsp),%rsi
mov    0x10(%rsp),%edx
lea    0xc(%rsp),%rdi
call   1050 <read_gpio@plt>
mov    0x24(%rsp),%edi
mov    0x18(%rsp),%rsi
call   1070 <close_device@plt>
mov    %ebx,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"nodriver aborted!\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 %46
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 %46
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 %46
29: ; preds = %23
%30 = load i32, i32* %7
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i8*, i8** %12
%34 = load i32, i32* %11
%35 = call i32 @read_gpio(i32* %8, i8* %33, i32 %34)
br label %42
36: ; preds = %29
%37 = load i32, i32* %8
%38 = load i8*, i8** %10
%39 = load i8*, i8** %12
%40 = load i32, i32* %11
%41 = call i32 @write_gpio(i32 %37, i8* %38, i8* %39, i32 %40)
br label %42
42: ; preds = %36, %32
%43 = load i32, i32* %6
%44 = load i8*, i8** %12
%45 = call i32 @close_device(i32 %43, i8* %44)
store i32 0, i32* %3
br label %46
46: ; preds = %42, %27, %21, %17
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@str = [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 %40
i32 -1, label %16
]
16: ; preds = %2
br label %40
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, i64 0, i64 0))
br label %40
23: ; preds = %17
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = load i8*, i8** %8
%28 = load i32, i32* %7
%29 = call i32 @read_gpio(i32* %5, i8* %27, i32 %28)
br label %36
30: ; preds = %23
%31 = load i32, i32* %5
%32 = load i8*, i8** %6
%33 = load i8*, i8** %8
%34 = load i32, i32* %7
%35 = call i32 @write_gpio(i32 %31, i8* %32, i8* %33, i32 %34)
br label %36
36: ; preds = %30, %26
%37 = load i32, i32* %3
%38 = load i8*, i8** %8
%39 = call i32 @close_device(i32 %37, i8* %38)
br label %40
40: ; preds = %2, %36, %21, %16
%41 = phi i32 [ -1, %16 ], [ -1, %21 ], [ 0, %36 ], [ 0, %2 ]
ret i32 %41
}