#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*/ O_RDWR;
int S_IRUSR;
int S_IWUSR;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ ioctl(int, int, int /*<<< orphan*/ *);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int fd;
  fd = open("/dev/mygpio", O_RDWR, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    printf("no this module!\n");
    return -1;
  }
  if (argc < 2) {
    printf("argc error!\n");
    exit(0);
  }
  switch (atoi(argv[1])) {
  case 0:
    ioctl(fd, 0, NULL);
    break;
  case 1:
    ioctl(fd, 1, NULL);
    break;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
mov    0x2e51(%rip),%rax
or     (%rax),%edx
lea    0xe68(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11c2 <main+0x62>
lea    0xe5b(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1242 <main+0xe2>
cmpl   $0x2,-0x8(%rbp)
jge    11df <main+0x7f>
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
test   %eax,%eax
je     120f <main+0xaf>
jmp    11fe <main+0x9e>
mov    -0x18(%rbp),%eax
sub    $0x1,%eax
je     1222 <main+0xc2>
jmp    1233 <main+0xd3>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <ioctl@plt>
jmp    1233 <main+0xd3>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1040 <ioctl@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    0x2e57(%rip),%rax
mov    0x2e60(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe75(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     11c9 <main+0x69>
cmp    $0x1,%ebp
jle    11df <main+0x7f>
mov    %eax,%ebx
mov    0x8(%r14),%rdi
call   1070 <atoi@plt>
test   %eax,%eax
je     11b3 <main+0x53>
cmp    $0x1,%eax
jne    11be <main+0x5e>
mov    $0x1,%eax
mov    %ebx,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    11da <main+0x7a>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe26(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/mygpio\00"
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [17 x i8] c"no this module!\0A\00"
@.str.2 = [13 x i8] c"argc error!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* @O_RDWR
%8 = load i32, i32* @S_IRUSR
%9 = load i32, i32* @S_IWUSR
%10 = or i32 %8, %9
%11 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %36
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 2
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %16
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
switch i32 %26, label %33 [
i32 0, label %27
i32 1, label %30
]
27: ; preds = %22
%28 = load i32, i32* %6
%29 = call i32 @ioctl(i32 %28, i32 0, i32* null)
br label %33
30: ; preds = %22
%31 = load i32, i32* %6
%32 = call i32 @ioctl(i32 %31, i32 1, i32* null)
br label %33
33: ; preds = %22, %30, %27
%34 = load i32, i32* %6
%35 = call i32 @close(i32 %34)
store i32 0, i32* %3
br label %36
36: ; preds = %33, %14
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/mygpio\00"
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@str = [12 x i8] c"argc error!\00"
@str.3 = [16 x i8] c"no this module!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @S_IRUSR
%5 = load i32, i32* @S_IWUSR
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.3, i64 0, i64 0))
br label %26
11: ; preds = %2
%12 = icmp slt i32 %0, 2
br i1 %12, label %13, label %16
13: ; preds = %11
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %11
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
switch i32 %19, label %24 [
i32 0, label %21
i32 1, label %20
]
20: ; preds = %16
br label %21
21: ; preds = %16, %20
%22 = phi i32 [ 1, %20 ], [ %19, %16 ]
%23 = tail call i32 @ioctl(i32 %7, i32 %22, i32* null)
br label %24
24: ; preds = %21, %16
%25 = tail call i32 @close(i32 %7)
br label %26
26: ; preds = %24, %9
%27 = phi i32 [ -1, %9 ], [ 0, %24 ]
ret i32 %27
}