#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 */
struct utsname {
  int /*<<< orphan*/ release;
};

/* Variables and functions */
scalar_t__ ENOTTY;
int /*<<< orphan*/ FIGETBSZ;
int /*<<< orphan*/ FIOCLEX;
int /*<<< orphan*/ FIONBIO;
int /*<<< orphan*/ FS_IOC_GETVERSION;
int /*<<< orphan*/ FS_IOC_SETVERSION;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int ioctl(int, int /*<<< orphan*/, ...);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strverscmp(int /*<<< orphan*/, char *);
scalar_t__ uname(struct utsname *);
int main(int argc, char **argv) {
  struct utsname uts;
  int fd;
  int rc, useaccessmode = 1;
  int val;
  if (uname(&uts) < 0) {
    perror("uname");
    exit(1);
  }
  if (strverscmp(uts.release, "2.6.27") >= 0 &&
      strverscmp(uts.release, "2.6.39") < 0)
    useaccessmode = 0;
  fd = open(argv[1], O_RDONLY, 0);
  if (fd == -1) {
    perror("test_noioctl:open");
    exit(1);
  }
  rc = ioctl(fd, FIGETBSZ, &val);
  if (rc == 0) {
    printf("test_noioctl:FIGETBSZ");
    exit(1);
  }
  rc = ioctl(fd, FIOCLEX);
  if (rc == 0) {
    printf("test_noioctl:FIOCLEX");
    exit(1);
  }
  rc = ioctl(fd, FIONBIO, &val);
  if (!rc == !useaccessmode) {
    printf("test_noioctl:FIONBIO");
    exit(1);
  }
  rc = ioctl(fd, FS_IOC_GETVERSION, &val);
  if ((useaccessmode && rc == 0) ||
      (!useaccessmode && rc < 0 && errno != ENOTTY)) {
    perror("test_noioctl:FS_IOC_GETVERSION");
    exit(1);
  }
  val = 0;
  rc = ioctl(fd, FS_IOC_SETVERSION, &val);
  if (rc == 0) {
    perror("test_noioctl:FS_IOC_SETVERSION");
    exit(1);
  }
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <uname@plt>
cmp    $0x0,%rax
jge    11c6 <main+0x46>
lea    0xe49(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%edi
lea    0xe36(%rip),%rsi
call   1030 <strverscmp@plt>
cmp    $0x0,%rax
jl     11ff <main+0x7f>
mov    -0x18(%rbp),%edi
lea    0xe24(%rip),%rsi
call   1030 <strverscmp@plt>
cmp    $0x0,%rax
jge    11ff <main+0x7f>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    123a <main+0xba>
lea    0xde9(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    0x2d94(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    1274 <main+0xf4>
lea    0xdc1(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    12aa <main+0x12a>
lea    0xda1(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    0x2cfc(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
cmpl   $0x0,-0x24(%rbp)
setne  %cl
xor    $0xff,%cl
and    $0x1,%cl
movzbl %cl,%ecx
cmp    %ecx,%eax
jne    1300 <main+0x180>
lea    0xd60(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    0x2ce6(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     132e <main+0x1ae>
cmpl   $0x0,-0x20(%rbp)
je     135c <main+0x1dc>
cmpl   $0x0,-0x24(%rbp)
jne    1372 <main+0x1f2>
cmpl   $0x0,-0x20(%rbp)
jge    1372 <main+0x1f2>
mov    0x2c6f(%rip),%rax
mov    (%rax),%rax
mov    0x2c8d(%rip),%rcx
cmp    (%rcx),%rax
je     1372 <main+0x1f2>
lea    0xd03(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2c45(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jne    13b3 <main+0x233>
lea    0xce1(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rdi
call   1050 <uname@plt>
test   %rax,%rax
jns    11a3 <main+0x23>
lea    0xe5f(%rip),%rdi
jmp    11fd <main+0x7d>
mov    0x8(%rsp),%ebp
lea    0xe58(%rip),%rsi
mov    %ebp,%edi
call   1030 <strverscmp@plt>
test   %rax,%rax
js     11d8 <main+0x58>
lea    0xe4c(%rip),%rsi
mov    %ebp,%edi
call   1030 <strverscmp@plt>
mov    %rax,%rbp
shr    $0x3f,%rbp
test   %rax,%rax
setns  %r14b
jmp    11dd <main+0x5d>
mov    $0x1,%r14b
xor    %ebp,%ebp
mov    0x8(%rbx),%rdi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <open@plt>
cmp    $0xffffffff,%eax
jne    120c <main+0x8c>
lea    0xe17(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    %eax,%ebx
mov    0x2dc3(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
test   %eax,%eax
jne    1232 <main+0xb2>
lea    0xdf6(%rip),%rdi
jmp    1279 <main+0xf9>
mov    0x2d6f(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
test   %eax,%eax
jne    1251 <main+0xd1>
lea    0xded(%rip),%rdi
jmp    1279 <main+0xf9>
mov    0x2d58(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
test   %eax,%eax
sete   %al
cmp    %al,%r14b
je     1288 <main+0x108>
lea    0xdd8(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
test   %eax,%eax
sete   %cl
test   %cl,%r14b
je     12b5 <main+0x135>
lea    0xdb6(%rip),%rdi
jmp    11fd <main+0x7d>
test   %eax,%eax
sets   %al
and    %al,%bpl
cmp    $0x1,%bpl
jne    12d9 <main+0x159>
mov    0x2cee(%rip),%rax
mov    (%rax),%rax
mov    0x2d0c(%rip),%rcx
cmp    (%rcx),%rax
jne    12a9 <main+0x129>
movl   $0x0,0x4(%rsp)
mov    0x2ce0(%rip),%rax
mov    (%rax),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <ioctl@plt>
test   %eax,%eax
jne    1308 <main+0x188>
lea    0xd82(%rip),%rdi
jmp    11fd <main+0x7d>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.utsname = type { i32 }
@.str = [6 x i8] c"uname\00"
@.str.1 = [7 x i8] c"2.6.27\00"
@.str.2 = [7 x i8] c"2.6.39\00"
@O_RDONLY = global i32 0
@.str.3 = [18 x i8] c"test_noioctl:open\00"
@FIGETBSZ = global i32 0
@.str.4 = [22 x i8] c"test_noioctl:FIGETBSZ\00"
@FIOCLEX = global i32 0
@.str.5 = [21 x i8] c"test_noioctl:FIOCLEX\00"
@FIONBIO = global i32 0
@.str.6 = [21 x i8] c"test_noioctl:FIONBIO\00"
@FS_IOC_GETVERSION = global i32 0
@errno = global i64 0
@ENOTTY = global i64 0
@.str.7 = [31 x i8] c"test_noioctl:FS_IOC_GETVERSION\00"
@FS_IOC_SETVERSION = global i32 0
@.str.8 = [31 x i8] c"test_noioctl:FS_IOC_SETVERSION\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.utsname
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %9
%11 = call i64 @uname(%struct.utsname* %6)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @strverscmp(i32 %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp sge i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = getelementptr inbounds %struct.utsname, %struct.utsname* %6, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i64 @strverscmp(i32 %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 0, i32* %9
br label %27
27: ; preds = %26, %21, %16
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = load i32, i32* @O_RDONLY
%32 = call i32 @open(i8* %30, i32 %31, i32 0)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %27
%36 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %27
%39 = load i32, i32* %7
%40 = load i32, i32* @FIGETBSZ
%41 = call i32 (i32, i32, ...) @ioctl(i32 %39, i32 %40, i32* %10)
store i32 %41, i32* %8
%42 = load i32, i32* %8
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %38
%45 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %38
%48 = load i32, i32* %7
%49 = load i32, i32* @FIOCLEX
%50 = call i32 (i32, i32, ...) @ioctl(i32 %48, i32 %49)
store i32 %50, i32* %8
%51 = load i32, i32* %8
%52 = icmp eq i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %47
%57 = load i32, i32* %7
%58 = load i32, i32* @FIONBIO
%59 = call i32 (i32, i32, ...) @ioctl(i32 %57, i32 %58, i32* %10)
store i32 %59, i32* %8
%60 = load i32, i32* %8
%61 = icmp ne i32 %60, 0
%62 = xor i1 %61, true
%63 = zext i1 %62 to i32
%64 = load i32, i32* %9
%65 = icmp ne i32 %64, 0
%66 = xor i1 %65, true
%67 = zext i1 %66 to i32
%68 = icmp eq i32 %63, %67
br i1 %68, label %69, label %72
69: ; preds = %56
%70 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %56
%73 = load i32, i32* %7
%74 = load i32, i32* @FS_IOC_GETVERSION
%75 = call i32 (i32, i32, ...) @ioctl(i32 %73, i32 %74, i32* %10)
store i32 %75, i32* %8
%76 = load i32, i32* %9
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %72
%79 = load i32, i32* %8
%80 = icmp eq i32 %79, 0
br i1 %80, label %91, label %81
81: ; preds = %78, %72
%82 = load i32, i32* %9
%83 = icmp ne i32 %82, 0
br i1 %83, label %94, label %84
84: ; preds = %81
%85 = load i32, i32* %8
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %94
87: ; preds = %84
%88 = load i64, i64* @errno
%89 = load i64, i64* @ENOTTY
%90 = icmp ne i64 %88, %89
br i1 %90, label %91, label %94
91: ; preds = %87, %78
%92 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %87, %84, %81
store i32 0, i32* %10
%95 = load i32, i32* %7
%96 = load i32, i32* @FS_IOC_SETVERSION
%97 = call i32 (i32, i32, ...) @ioctl(i32 %95, i32 %96, i32* %10)
store i32 %97, i32* %8
%98 = load i32, i32* %8
%99 = icmp eq i32 %98, 0
br i1 %99, label %100, label %103
100: ; preds = %94
%101 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
%102 = call i32 @exit(i32 1)
unreachable
103: ; preds = %94
%104 = load i32, i32* %7
%105 = call i32 @close(i32 %104)
%106 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.utsname = type { i32 }
@.str = [6 x i8] c"uname\00"
@.str.1 = [7 x i8] c"2.6.27\00"
@.str.2 = [7 x i8] c"2.6.39\00"
@O_RDONLY = global i32 0
@.str.3 = [18 x i8] c"test_noioctl:open\00"
@FIGETBSZ = global i32 0
@.str.4 = [22 x i8] c"test_noioctl:FIGETBSZ\00"
@FIOCLEX = global i32 0
@.str.5 = [21 x i8] c"test_noioctl:FIOCLEX\00"
@FIONBIO = global i32 0
@.str.6 = [21 x i8] c"test_noioctl:FIONBIO\00"
@FS_IOC_GETVERSION = global i32 0
@errno = global i64 0
@ENOTTY = global i64 0
@.str.7 = [31 x i8] c"test_noioctl:FS_IOC_GETVERSION\00"
@FS_IOC_SETVERSION = global i32 0
@.str.8 = [31 x i8] c"test_noioctl:FS_IOC_SETVERSION\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.utsname
%4 = alloca i32
%5 = bitcast %struct.utsname* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i64 @uname(%struct.utsname* %3)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds %struct.utsname, %struct.utsname* %3, i64 0, i32 0
%14 = load i32, i32* %13
%15 = tail call i64 @strverscmp(i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp sgt i64 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = tail call i64 @strverscmp(i32 %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp slt i64 %18, 0
%20 = xor i1 %19, true
br label %21
21: ; preds = %17, %12
%22 = phi i1 [ true, %12 ], [ %20, %17 ]
%23 = phi i1 [ false, %12 ], [ %19, %17 ]
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_RDONLY
%27 = tail call i32 @open(i8* %25, i32 %26, i32 0)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %21
%30 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %21
%33 = load i32, i32* @FIGETBSZ
%34 = call i32 (i32, i32, ...) @ioctl(i32 %27, i32 %33, i32* %4)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %32
%37 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %32
%40 = load i32, i32* @FIOCLEX
%41 = call i32 (i32, i32, ...) @ioctl(i32 %27, i32 %40)
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %39
%47 = load i32, i32* @FIONBIO
%48 = call i32 (i32, i32, ...) @ioctl(i32 %27, i32 %47, i32* %4)
%49 = icmp eq i32 %48, 0
%50 = xor i1 %22, %49
br i1 %50, label %51, label %54
51: ; preds = %46
%52 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %46
%55 = load i32, i32* @FS_IOC_GETVERSION
%56 = call i32 (i32, i32, ...) @ioctl(i32 %27, i32 %55, i32* %4)
%57 = icmp eq i32 %56, 0
%58 = select i1 %22, i1 %57, i1 false
br i1 %58, label %66, label %59
59: ; preds = %54
%60 = icmp slt i32 %56, 0
%61 = select i1 %23, i1 %60, i1 false
br i1 %61, label %62, label %69
62: ; preds = %59
%63 = load i64, i64* @errno
%64 = load i64, i64* @ENOTTY
%65 = icmp eq i64 %63, %64
br i1 %65, label %69, label %66
66: ; preds = %54, %62
%67 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %62, %59
store i32 0, i32* %4
%70 = load i32, i32* @FS_IOC_SETVERSION
%71 = call i32 (i32, i32, ...) @ioctl(i32 %27, i32 %70, i32* %4)
%72 = icmp eq i32 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %69
%74 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %69
%77 = call i32 @close(i32 %27)
%78 = call i32 @exit(i32 0)
unreachable
}