#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 */
typedef scalar_t__ u_int32_t;

/* Variables and functions */
scalar_t__ GPIOEVENT_REQUEST_BOTH_EDGES;
scalar_t__ GPIOEVENT_REQUEST_FALLING_EDGE;
scalar_t__ GPIOEVENT_REQUEST_RISING_EDGE;
scalar_t__ GPIOHANDLE_REQUEST_INPUT;
scalar_t__ GPIOHANDLE_REQUEST_OPEN_DRAIN;
scalar_t__ GPIOHANDLE_REQUEST_OPEN_SOURCE;
int getopt(int, char **, char *);
int monitor_device(char const *, unsigned int, scalar_t__, scalar_t__,
                   unsigned int);
char *optarg;
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *);
unsigned int strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  const char *device_name = NULL;
  unsigned int line = -1;
  unsigned int loops = 0;
  u_int32_t handleflags = GPIOHANDLE_REQUEST_INPUT;
  u_int32_t eventflags = 0;
  int c;
  while ((c = getopt(argc, argv, "c:n:o:dsrf?")) != -1) {
    switch (c) {
    case 'c':
      loops = strtoul(optarg, NULL, 10);
      break;
    case 'n':
      device_name = optarg;
      break;
    case 'o':
      line = strtoul(optarg, NULL, 10);
      break;
    case 'd':
      handleflags |= GPIOHANDLE_REQUEST_OPEN_DRAIN;
      break;
    case 's':
      handleflags |= GPIOHANDLE_REQUEST_OPEN_SOURCE;
      break;
    case 'r':
      eventflags |= GPIOEVENT_REQUEST_RISING_EDGE;
      break;
    case 'f':
      eventflags |= GPIOEVENT_REQUEST_FALLING_EDGE;
      break;
    case '?':
      print_usage();
      return -1;
    }
  }
  if (!device_name || line == -1) {
    print_usage();
    return -1;
  }
  if (!eventflags) {
    printf("No flags specified, listening on both rising and "
           "falling edges\n");
    eventflags = GPIOEVENT_REQUEST_BOTH_EDGES;
  }
  return monitor_device(device_name, line, handleflags, eventflags, loops);
}


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)
movq   $0x0,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xf34(%rip),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     12a1 <main+0x151>
mov    -0x34(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0x34,%eax
ja     129c <main+0x14c>
mov    -0x40(%rbp),%rax
lea    0xe2f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e17(%rip),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x20(%rbp)
jmp    129c <main+0x14c>
mov    0x2df7(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    129c <main+0x14c>
mov    0x2de4(%rip),%rax
mov    (%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %eax,-0x1c(%rbp)
jmp    129c <main+0x14c>
mov    0x2d84(%rip),%rax
mov    (%rax),%rax
or     -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    129c <main+0x14c>
mov    0x2d65(%rip),%rax
mov    (%rax),%rax
or     -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    129c <main+0x14c>
mov    0x2d76(%rip),%rax
mov    (%rax),%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    129c <main+0x14c>
mov    0x2d4f(%rip),%rax
mov    (%rax),%rax
or     -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    129c <main+0x14c>
mov    $0x0,%al
call   1060 <print_usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <main+0x1b9>
jmp    1192 <main+0x42>
cmpq   $0x0,-0x18(%rbp)
je     12b6 <main+0x166>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12c9 <main+0x179>
mov    $0x0,%al
call   1060 <print_usage@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1309 <main+0x1b9>
cmpq   $0x0,-0x30(%rbp)
jne    12ee <main+0x19e>
lea    0xe05(%rip),%rdi
call   1030 <printf@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%r8d
call   1070 <monitor_device@plt>
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   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
mov    0x2e55(%rip),%rax
mov    (%rax),%r13
xor    %eax,%eax
mov    %rax,0x10(%rsp)
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xf50(%rip),%r15
lea    0xe75(%rip),%r12
movl   $0x0,0x8(%rsp)
xor    %ebx,%ebx
jmp    11b0 <main+0x60>
mov    0x2e2a(%rip),%rax
or     (%rax),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1040 <getopt@plt>
lea    -0x3f(%rax),%ecx
cmp    $0x34,%ecx
ja     123f <main+0xef>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
mov    0x2e22(%rip),%rax
mov    (%rax),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %eax,0x8(%rsp)
jmp    11b0 <main+0x60>
mov    0x2dc6(%rip),%rax
or     (%rax),%r13
jmp    11b0 <main+0x60>
mov    0x2dfa(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
jmp    11b0 <main+0x60>
mov    0x2de9(%rip),%rax
mov    (%rax),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %eax,0xc(%rsp)
jmp    11b0 <main+0x60>
mov    0x2dad(%rip),%rax
or     (%rax),%rbx
jmp    11b0 <main+0x60>
mov    0x2d79(%rip),%rax
or     (%rax),%r13
jmp    11b0 <main+0x60>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x60>
mov    0x10(%rsp),%rbp
test   %rbp,%rbp
mov    0xc(%rsp),%r14d
je     129c <main+0x14c>
cmp    $0xffffffff,%r14d
je     129c <main+0x14c>
test   %rbx,%rbx
jne    1278 <main+0x128>
lea    0xe77(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%rbx
mov    %rbp,%rdi
mov    %r14d,%esi
mov    %r13,%rdx
mov    %rbx,%rcx
mov    0x8(%rsp),%r8d
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <monitor_device@plt>
xor    %eax,%eax
call   1060 <print_usage@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@GPIOHANDLE_REQUEST_INPUT = global i64 0
@.str = [12 x i8] c"c:n:o:dsrf?\00"
@optarg = global i8* null
@GPIOHANDLE_REQUEST_OPEN_DRAIN = global i64 0
@GPIOHANDLE_REQUEST_OPEN_SOURCE = global i64 0
@GPIOEVENT_REQUEST_RISING_EDGE = global i64 0
@GPIOEVENT_REQUEST_FALLING_EDGE = global i64 0
@.str.1 = [64 x i8] c"No flags specified, listening on both rising and falling edges\0A\00"
@GPIOEVENT_REQUEST_BOTH_EDGES = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 -1, i32* %7
store i32 0, i32* %8
%12 = load i64, i64* @GPIOHANDLE_REQUEST_INPUT
store i64 %12, i64* %9
store i64 0, i64* %10
br label %13
13: ; preds = %46, %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @getopt(i32 %14, i8** %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 %16, i32* %11
%17 = icmp ne i32 %16, -1
br i1 %17, label %18, label %47
18: ; preds = %13
%19 = load i32, i32* %11
switch i32 %19, label %46 [
i32 99, label %20
i32 110, label %23
i32 111, label %25
i32 100, label %28
i32 115, label %32
i32 114, label %36
i32 102, label %40
i32 63, label %44
]
20: ; preds = %18
%21 = load i8*, i8** @optarg
%22 = call i32 @strtoul(i8* %21, i32* null, i32 10)
store i32 %22, i32* %8
br label %46
23: ; preds = %18
%24 = load i8*, i8** @optarg
store i8* %24, i8** %6
br label %46
25: ; preds = %18
%26 = load i8*, i8** @optarg
%27 = call i32 @strtoul(i8* %26, i32* null, i32 10)
store i32 %27, i32* %7
br label %46
28: ; preds = %18
%29 = load i64, i64* @GPIOHANDLE_REQUEST_OPEN_DRAIN
%30 = load i64, i64* %9
%31 = or i64 %30, %29
store i64 %31, i64* %9
br label %46
32: ; preds = %18
%33 = load i64, i64* @GPIOHANDLE_REQUEST_OPEN_SOURCE
%34 = load i64, i64* %9
%35 = or i64 %34, %33
store i64 %35, i64* %9
br label %46
36: ; preds = %18
%37 = load i64, i64* @GPIOEVENT_REQUEST_RISING_EDGE
%38 = load i64, i64* %10
%39 = or i64 %38, %37
store i64 %39, i64* %10
br label %46
40: ; preds = %18
%41 = load i64, i64* @GPIOEVENT_REQUEST_FALLING_EDGE
%42 = load i64, i64* %10
%43 = or i64 %42, %41
store i64 %43, i64* %10
br label %46
44: ; preds = %18
%45 = call i32 (...) @print_usage()
store i32 -1, i32* %3
br label %68
46: ; preds = %18, %40, %36, %32, %28, %25, %23, %20
br label %13
47: ; preds = %13
%48 = load i8*, i8** %6
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %53
50: ; preds = %47
%51 = load i32, i32* %7
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %55
53: ; preds = %50, %47
%54 = call i32 (...) @print_usage()
store i32 -1, i32* %3
br label %68
55: ; preds = %50
%56 = load i64, i64* %10
%57 = icmp ne i64 %56, 0
br i1 %57, label %61, label %58
58: ; preds = %55
%59 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%60 = load i64, i64* @GPIOEVENT_REQUEST_BOTH_EDGES
store i64 %60, i64* %10
br label %61
61: ; preds = %58, %55
%62 = load i8*, i8** %6
%63 = load i32, i32* %7
%64 = load i64, i64* %9
%65 = load i64, i64* %10
%66 = load i32, i32* %8
%67 = call i32 @monitor_device(i8* %62, i32 %63, i64 %64, i64 %65, i32 %66)
store i32 %67, i32* %3
br label %68
68: ; preds = %61, %53, %44
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@GPIOHANDLE_REQUEST_INPUT = global i64 0
@.str = [12 x i8] c"c:n:o:dsrf?\00"
@optarg = global i8* null
@GPIOHANDLE_REQUEST_OPEN_DRAIN = global i64 0
@GPIOHANDLE_REQUEST_OPEN_SOURCE = global i64 0
@GPIOEVENT_REQUEST_RISING_EDGE = global i64 0
@GPIOEVENT_REQUEST_FALLING_EDGE = global i64 0
@GPIOEVENT_REQUEST_BOTH_EDGES = global i64 0
@str = [63 x i8] c"No flags specified, listening on both rising and falling edges\00"
define i32 @main(i32 %0, i8** %1) {
%3 = load i64, i64* @GPIOHANDLE_REQUEST_INPUT
br label %4
4: ; preds = %11, %2
%5 = phi i8* [ null, %2 ], [ %12, %11 ]
%6 = phi i32 [ -1, %2 ], [ %13, %11 ]
%7 = phi i32 [ 0, %2 ], [ %14, %11 ]
%8 = phi i64 [ %3, %2 ], [ %15, %11 ]
%9 = phi i64 [ 0, %2 ], [ %16, %11 ]
%10 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
switch i32 %10, label %11 [
i32 -1, label %39
i32 99, label %17
i32 110, label %20
i32 111, label %22
i32 100, label %25
i32 115, label %28
i32 114, label %31
i32 102, label %34
i32 63, label %37
]
11: ; preds = %4, %34, %31, %28, %25, %22, %20, %17
%12 = phi i8* [ %5, %34 ], [ %5, %31 ], [ %5, %28 ], [ %5, %25 ], [ %5, %22 ], [ %21, %20 ], [ %5, %17 ], [ %5, %4 ]
%13 = phi i32 [ %6, %34 ], [ %6, %31 ], [ %6, %28 ], [ %6, %25 ], [ %24, %22 ], [ %6, %20 ], [ %6, %17 ], [ %6, %4 ]
%14 = phi i32 [ %7, %34 ], [ %7, %31 ], [ %7, %28 ], [ %7, %25 ], [ %7, %22 ], [ %7, %20 ], [ %19, %17 ], [ %7, %4 ]
%15 = phi i64 [ %8, %34 ], [ %8, %31 ], [ %30, %28 ], [ %27, %25 ], [ %8, %22 ], [ %8, %20 ], [ %8, %17 ], [ %8, %4 ]
%16 = phi i64 [ %36, %34 ], [ %33, %31 ], [ %9, %28 ], [ %9, %25 ], [ %9, %22 ], [ %9, %20 ], [ %9, %17 ], [ %9, %4 ]
br label %4
17: ; preds = %4
%18 = load i8*, i8** @optarg
%19 = tail call i32 @strtoul(i8* nocapture %18, i32* null, i32 10)
br label %11
20: ; preds = %4
%21 = load i8*, i8** @optarg
br label %11
22: ; preds = %4
%23 = load i8*, i8** @optarg
%24 = tail call i32 @strtoul(i8* nocapture %23, i32* null, i32 10)
br label %11
25: ; preds = %4
%26 = load i64, i64* @GPIOHANDLE_REQUEST_OPEN_DRAIN
%27 = or i64 %26, %8
br label %11
28: ; preds = %4
%29 = load i64, i64* @GPIOHANDLE_REQUEST_OPEN_SOURCE
%30 = or i64 %29, %8
br label %11
31: ; preds = %4
%32 = load i64, i64* @GPIOEVENT_REQUEST_RISING_EDGE
%33 = or i64 %32, %9
br label %11
34: ; preds = %4
%35 = load i64, i64* @GPIOEVENT_REQUEST_FALLING_EDGE
%36 = or i64 %35, %9
br label %11
37: ; preds = %4
%38 = tail call i32 (...) @print_usage()
br label %53
39: ; preds = %4
%40 = icmp eq i8* %5, null
%41 = icmp eq i32 %6, -1
%42 = select i1 %40, i1 true, i1 %41
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = tail call i32 (...) @print_usage()
br label %53
45: ; preds = %39
%46 = icmp eq i64 %9, 0
br i1 %46, label %47, label %50
47: ; preds = %45
%48 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str, i64 0, i64 0))
%49 = load i64, i64* @GPIOEVENT_REQUEST_BOTH_EDGES
br label %50
50: ; preds = %47, %45
%51 = phi i64 [ %9, %45 ], [ %49, %47 ]
%52 = tail call i32 @monitor_device(i8* %5, i32 %6, i64 %8, i64 %51, i32 %7)
br label %53
53: ; preds = %50, %43, %37
%54 = phi i32 [ -1, %37 ], [ -1, %43 ], [ %52, %50 ]
ret i32 %54
}