#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 *, 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, "open('%s') rc = %d\n", argv[1], rc);
    exit(2);
  }
  capabilities = stat_optical_get_caps(fd);
  close(fd);
  if (capabilities < 0) {
    fprintf(stderr, "stat_optical_get_caps('%s') rc = %d\n", 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    121f <main+0xaf>
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    0x8(%rax),%rdx
mov    -0x14(%rbp),%ecx
lea    0xdf0(%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    1266 <main+0xf6>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x14(%rbp),%ecx
lea    0xdbd(%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     11ff <main+0x8f>
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    %ecx,%ecx
sub    (%rax),%ecx
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe10(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1090 <exit@plt>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    0x8(%r14),%rdx
lea    0xe01(%rip),%rsi
xor    %ecx,%ecx
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 = [20 x i8] c"open('%s') rc = %d\0A\00"
@.str.1 = [37 x i8] c"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 %37
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 1
%33 = load i8*, i8** %32
%34 = load i32, i32* %6
%35 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %33, i32 %34)
%36 = call i32 @exit(i32 2)
unreachable
37: ; preds = %17
%38 = load i32, i32* %7
%39 = call i32 @stat_optical_get_caps(i32 %38)
store i32 %39, i32* %8
%40 = load i32, i32* %7
%41 = call i32 @close(i32 %40)
%42 = load i32, i32* %8
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %52
44: ; preds = %37
%45 = load i32, i32* @stderr
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = load i32, i32* %6
%50 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %48, i32 %49)
%51 = call i32 @exit(i32 4)
unreachable
52: ; preds = %37
%53 = load i32, i32* %8
%54 = call i32 @stat_optical_print_caps(i32 %53)
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 = [20 x i8] c"open('%s') rc = %d\0A\00"
@.str.1 = [37 x i8] c"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 %23
16: ; preds = %8
%17 = load i32, i32* @errno
%18 = sub nsw i32 0, %17
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %9
%21 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %20, i32 %18)
%22 = tail call i32 @exit(i32 2)
unreachable
23: ; preds = %8
%24 = tail call i32 @stat_optical_get_caps(i32 %14)
%25 = tail call i32 @close(i32 %14)
%26 = icmp slt i32 %24, 0
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i8*, i8** %9
%30 = tail call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %29, i32 0)
%31 = tail call i32 @exit(i32 4)
unreachable
32: ; preds = %23
%33 = tail call i32 @stat_optical_print_caps(i32 %24)
ret i32 0
}