#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 EXIT_SUCCESS;
unsigned int atoi(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getopt(int, char **, char *);
int open_device();
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int work_mode(int, unsigned int);
int main(int argc, char *argv[]) {
  unsigned int pin = 0;
  int c;
  while ((c = getopt(argc, argv, "p:h")) != -1) {
    switch (c) {
    case 'p':
      pin = atoi(optarg);
      break;
    case 'h':
      usage();
      break;
    default:
      fprintf(stderr, "ERROR: no valid argument\n");
      usage();
    }
  }
  int fd = open_device();
  if (fd == -1)
    usage();
  if (work_mode(fd, pin) == -1)
    usage();
  close(fd);
  return EXIT_SUCCESS;
}


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)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe65(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1214 <main+0xa4>
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
sub    $0x68,%eax
je     11e7 <main+0x77>
jmp    11c0 <main+0x50>
mov    -0x20(%rbp),%eax
sub    $0x70,%eax
jne    11f3 <main+0x83>
jmp    11d1 <main+0x61>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    120f <main+0x9f>
mov    $0x0,%al
call   1070 <usage@plt>
jmp    120f <main+0x9f>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1070 <usage@plt>
jmp    118d <main+0x1d>
mov    $0x0,%al
call   1060 <open_device@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    122f <main+0xbf>
mov    $0x0,%al
call   1070 <usage@plt>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <work_mode@plt>
cmp    $0xffffffff,%eax
jne    124a <main+0xda>
mov    $0x0,%al
call   1070 <usage@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe79(%rip),%r15
mov    0x2e4a(%rip),%r13
lea    0xe6f(%rip),%r12
xor    %r14d,%r14d
jmp    11b3 <main+0x43>
nopw   0x0(%rax,%rax,1)
mov    0x0(%r13),%edi
mov    %r12,%rsi
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1070 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1080 <getopt@plt>
cmp    $0x68,%eax
je     11ac <main+0x3c>
cmp    $0xffffffff,%eax
je     11e2 <main+0x72>
cmp    $0x70,%eax
jne    11a0 <main+0x30>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
mov    %eax,%r14d
jmp    11b3 <main+0x43>
xor    %eax,%eax
call   1060 <open_device@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11f7 <main+0x87>
xor    %eax,%eax
call   1070 <usage@plt>
mov    %ebx,%edi
mov    %r14d,%esi
call   1030 <work_mode@plt>
cmp    $0xffffffff,%eax
jne    120d <main+0x9d>
xor    %eax,%eax
call   1070 <usage@plt>
mov    %ebx,%edi
call   1040 <close@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"p:h\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"ERROR: no valid argument\0A\00"
@EXIT_SUCCESS = global i32 0
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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %9
9: ; preds = %25, %2
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @getopt(i32 %10, i8** %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %7
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %26
14: ; preds = %9
%15 = load i32, i32* %7
switch i32 %15, label %21 [
i32 112, label %16
i32 104, label %19
]
16: ; preds = %14
%17 = load i32, i32* @optarg
%18 = call i32 @atoi(i32 %17)
store i32 %18, i32* %6
br label %25
19: ; preds = %14
%20 = call i32 (...) @usage()
br label %25
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 (...) @usage()
br label %25
25: ; preds = %21, %19, %16
br label %9
26: ; preds = %9
%27 = call i32 (...) @open_device()
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = call i32 (...) @usage()
br label %32
32: ; preds = %30, %26
%33 = load i32, i32* %8
%34 = load i32, i32* %6
%35 = call i32 @work_mode(i32 %33, i32 %34)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 (...) @usage()
br label %39
39: ; preds = %37, %32
%40 = load i32, i32* %8
%41 = call i32 @close(i32 %40)
%42 = load i32, i32* @EXIT_SUCCESS
ret i32 %42
}

LLVM IR (-O2):
@.str = [4 x i8] c"p:h\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"ERROR: no valid argument\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %7, %2
%4 = phi i32 [ %9, %7 ], [ 0, %2 ]
br label %5
5: ; preds = %16, %3
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %12 [
i32 -1, label %17
i32 112, label %7
i32 104, label %10
]
7: ; preds = %5
%8 = load i32, i32* @optarg
%9 = tail call i32 @atoi(i32 %8)
br label %3
10: ; preds = %5
%11 = tail call i32 (...) @usage()
br label %16
12: ; preds = %5
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 (...) @usage()
br label %16
16: ; preds = %12, %10
br label %5
17: ; preds = %5
%18 = tail call i32 (...) @open_device()
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 (...) @usage()
br label %22
22: ; preds = %20, %17
%23 = tail call i32 @work_mode(i32 %18, i32 %4)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 (...) @usage()
br label %27
27: ; preds = %25, %22
%28 = tail call i32 @close(i32 %18)
%29 = load i32, i32* @EXIT_SUCCESS
ret i32 %29
}