#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 O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, int);
int open(char *, int);
int stat_optical_get_caps(int);
int /*<<< orphan*/ stat_optical_print_caps(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage(char *);
int main(int argc, char **argv) {
  int rc = 0;
  int fd = 0;
  int capabilities = 0;
  if (argc != 2) {
    usage(argv[0]);
    exit(1);
  }
  fd = open(argv[1], O_RDONLY | O_NONBLOCK);
  if (fd < 0) {
    rc = -errno;
    fprintf(stderr, "[ERROR] %s: open('%s') rc = %d\n", argv[0], argv[1], rc);
    exit(2);
  }
  capabilities = stat_optical_get_caps(fd);
  close(fd);
  if (capabilities < 0) {
    fprintf(stderr, "[ERROR] %s: stat_optical_get_caps('%s') rc = %d\n",
            argv[0], argv[1], rc);
    exit(4);
  }
  stat_optical_print_caps(capabilities);
  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)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bb <main+0x4b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    0x2e15(%rip),%rax
or     (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1227 <main+0xb7>
xor    %eax,%eax
mov    0x2dd8(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x14(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x14(%rbp),%r8d
lea    0xde8(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%edi
call   1060 <stat_optical_get_caps@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
cmpl   $0x0,-0x1c(%rbp)
jge    1276 <main+0x106>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x14(%rbp),%r8d
lea    0xdb9(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x4,%edi
call   1090 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1030 <stat_optical_print_caps@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x2,%edi
jne    11bf <main+0x4f>
mov    0x8(%r14),%rdi
mov    0x2e59(%rip),%rax
mov    0x2e5a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1080 <open@plt>
test   %eax,%eax
js     11d1 <main+0x61>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <stat_optical_get_caps@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1040 <close@plt>
test   %ebx,%ebx
js     1204 <main+0x94>
mov    %ebx,%edi
call   1030 <stat_optical_print_caps@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%r14),%rdi
call   1070 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2df0(%rip),%rax
xor    %r8d,%r8d
sub    (%rax),%r8d
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
mov    0x8(%r14),%rcx
lea    0xe0b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
mov    0x8(%r14),%rcx
lea    0xe05(%rip),%rsi
xor    %r8d,%r8d
call   1050 <fprintf@plt>
mov    $0x4,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"[ERROR] %s: open('%s') rc = %d\0A\00"
@.str.1 = [49 x i8] c"[ERROR] %s: stat_optical_get_caps('%s') rc = %d\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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %17
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @usage(i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDONLY
%22 = load i32, i32* @O_NONBLOCK
%23 = or i32 %21, %22
%24 = call i32 @open(i8* %20, i32 %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %40
27: ; preds = %17
%28 = load i32, i32* @errno
%29 = sub nsw i32 0, %28
store i32 %29, i32* %6
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i32, i32* %6
%38 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %33, i8* %36, i32 %37)
%39 = call i32 @exit(i32 2)
unreachable
40: ; preds = %17
%41 = load i32, i32* %7
%42 = call i32 @stat_optical_get_caps(i32 %41)
store i32 %42, i32* %8
%43 = load i32, i32* %7
%44 = call i32 @close(i32 %43)
%45 = load i32, i32* %8
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %58
47: ; preds = %40
%48 = load i32, i32* @stderr
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 0
%51 = load i8*, i8** %50
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 1
%54 = load i8*, i8** %53
%55 = load i32, i32* %6
%56 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %51, i8* %54, i32 %55)
%57 = call i32 @exit(i32 4)
unreachable
58: ; preds = %40
%59 = load i32, i32* %8
%60 = call i32 @stat_optical_print_caps(i32 %59)
ret i32 0
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [32 x i8] c"[ERROR] %s: open('%s') rc = %d\0A\00"
@.str.1 = [49 x i8] c"[ERROR] %s: stat_optical_get_caps('%s') rc = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_RDONLY
%12 = load i32, i32* @O_NONBLOCK
%13 = or i32 %12, %11
%14 = tail call i32 @open(i8* %10, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %8
%17 = load i32, i32* @errno
%18 = sub nsw i32 0, %17
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %1
%21 = load i8*, i8** %9
%22 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %20, i8* %21, i32 %18)
%23 = tail call i32 @exit(i32 2)
unreachable
24: ; preds = %8
%25 = tail call i32 @stat_optical_get_caps(i32 %14)
%26 = tail call i32 @close(i32 %14)
%27 = icmp slt i32 %25, 0
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %1
%31 = load i8*, i8** %9
%32 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i8* %30, i8* %31, i32 0)
%33 = tail call i32 @exit(i32 4)
unreachable
34: ; preds = %24
%35 = tail call i32 @stat_optical_print_caps(i32 %25)
ret i32 0
}