#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*/ IOC_INOUT;
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int fd, rc;
  fd = open("/dev/ioctl", 0);
  if (fd < 0) {
    printf("Error opening /dev/ioctl\n");
    return -1;
  }
  rc = ioctl(fd, IOC_INOUT, 0);
  rc = ioctl(fd, IOC_INOUT, 1);
  rc = ioctl(fd, IOC_INOUT, 2);
  rc = ioctl(fd, IOC_INOUT, 3);
  rc = ioctl(fd, IOC_INOUT, 55);
  printf("rc = %d\n", rc);
  close(fd);
  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)
lea    0xea3(%rip),%rdi
xor    %esi,%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    118b <main+0x4b>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1225 <main+0xe5>
mov    -0x14(%rbp),%edi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
mov    $0x2,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
mov    $0x3,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
mov    $0x37,%edx
call   1040 <ioctl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
lea    0xebc(%rip),%rdi
xor    %r14d,%r14d
xor    %esi,%esi
call   1070 <open@plt>
test   %eax,%eax
js     11ce <main+0x7e>
mov    %eax,%ebp
mov    0x2e7e(%rip),%rbx
mov    (%rbx),%esi
mov    %eax,%edi
xor    %edx,%edx
call   1050 <ioctl@plt>
mov    (%rbx),%esi
mov    %ebp,%edi
mov    $0x1,%edx
call   1050 <ioctl@plt>
mov    (%rbx),%esi
mov    %ebp,%edi
mov    $0x2,%edx
call   1050 <ioctl@plt>
mov    (%rbx),%esi
mov    %ebp,%edi
mov    $0x3,%edx
call   1050 <ioctl@plt>
mov    (%rbx),%esi
mov    %ebp,%edi
mov    $0x37,%edx
call   1050 <ioctl@plt>
lea    0xe44(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    11e0 <main+0x90>
lea    0xe34(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/ioctl\00"
@.str.1 = [26 x i8] c"Error opening /dev/ioctl\0A\00"
@IOC_INOUT = global i32 0
@.str.2 = [9 x i8] c"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
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %33
13: ; preds = %2
%14 = load i32, i32* %6
%15 = load i32, i32* @IOC_INOUT
%16 = call i32 @ioctl(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %7
%17 = load i32, i32* %6
%18 = load i32, i32* @IOC_INOUT
%19 = call i32 @ioctl(i32 %17, i32 %18, i32 1)
store i32 %19, i32* %7
%20 = load i32, i32* %6
%21 = load i32, i32* @IOC_INOUT
%22 = call i32 @ioctl(i32 %20, i32 %21, i32 2)
store i32 %22, i32* %7
%23 = load i32, i32* %6
%24 = load i32, i32* @IOC_INOUT
%25 = call i32 @ioctl(i32 %23, i32 %24, i32 3)
store i32 %25, i32* %7
%26 = load i32, i32* %6
%27 = load i32, i32* @IOC_INOUT
%28 = call i32 @ioctl(i32 %26, i32 %27, i32 55)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %29)
%31 = load i32, i32* %6
%32 = call i32 @close(i32 %31)
store i32 0, i32* %3
br label %33
33: ; preds = %13, %11
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/ioctl\00"
@IOC_INOUT = global i32 0
@.str.2 = [9 x i8] c"rc = %d\0A\00"
@str = [25 x i8] c"Error opening /dev/ioctl\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 0)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %20
7: ; preds = %2
%8 = load i32, i32* @IOC_INOUT
%9 = tail call i32 @ioctl(i32 %3, i32 %8, i32 0)
%10 = load i32, i32* @IOC_INOUT
%11 = tail call i32 @ioctl(i32 %3, i32 %10, i32 1)
%12 = load i32, i32* @IOC_INOUT
%13 = tail call i32 @ioctl(i32 %3, i32 %12, i32 2)
%14 = load i32, i32* @IOC_INOUT
%15 = tail call i32 @ioctl(i32 %3, i32 %14, i32 3)
%16 = load i32, i32* @IOC_INOUT
%17 = tail call i32 @ioctl(i32 %3, i32 %16, i32 55)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %17)
%19 = tail call i32 @close(i32 %3)
br label %20
20: ; preds = %7, %5
%21 = phi i32 [ -1, %5 ], [ 0, %7 ]
ret i32 %21
}