#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*/ EXIT_FAILURE;
int O_NONBLOCK;
int O_RDWR;
int /*<<< orphan*/ err(int /*<<< orphan*/, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int ioctl(int, int);
int open(char *, int);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc < 2) {
    fprintf(stderr, "usage: %s <device name>\n", argv[0], argv[1]);
    exit(EXIT_FAILURE);
  }
  int fd;
  fd = open(argv[1], O_RDWR | O_NONBLOCK);
  if (fd == -1)
    err(EXIT_FAILURE, "open() failed.");
  int ret;
  ret = ioctl(fd, 0x5326);
  return (ret == 2) ? 0 : 1;
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    11a2 <main+0x52>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe71(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
mov    0x2e26(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11e3 <main+0x93>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
call   1050 <err@plt>
mov    -0x14(%rbp),%edi
mov    $0x5326,%esi
call   1030 <ioctl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edx
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x2,%edx
cmove  %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
cmp    $0x1,%edi
jle    11a5 <main+0x55>
mov    0x8(%rsi),%rdi
mov    0x2e87(%rip),%rax
mov    0x2e78(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    118d <main+0x3d>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
lea    0xe91(%rip),%rsi
call   1050 <err@plt>
mov    %ebx,%edi
mov    $0x5326,%esi
call   1030 <ioctl@plt>
xor    %ecx,%ecx
cmp    $0x2,%eax
setne  %cl
mov    %ecx,%eax
pop    %rbx
ret
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
mov    0x8(%rsi),%rcx
lea    0xe44(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"usage: %s <device name>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [15 x i8] c"open() failed.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %14, i8* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDWR
%26 = load i32, i32* @O_NONBLOCK
%27 = or i32 %25, %26
%28 = call i32 @open(i8* %24, i32 %27)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %21
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @err(i32 %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %31, %21
%35 = load i32, i32* %6
%36 = call i32 @ioctl(i32 %35, i32 21286)
store i32 %36, i32* %7
%37 = load i32, i32* %7
%38 = icmp eq i32 %37, 2
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 0, i32 1
ret i32 %40
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"usage: %s <device name>\0A\00"
@EXIT_FAILURE = global i32 0
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
@.str.1 = [15 x i8] c"open() failed.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = load i32, i32* @O_RDWR
%16 = load i32, i32* @O_NONBLOCK
%17 = or i32 %16, %15
%18 = tail call i32 @open(i8* %14, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %12
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @err(i32 %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %20, %12
%24 = tail call i32 @ioctl(i32 %18, i32 21286)
%25 = icmp ne i32 %24, 2
%26 = zext i1 %25 to i32
ret i32 %26
}