#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 */
typedef int /*<<< orphan*/ ulong;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ _IO(char, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, int *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int main(int argc, char *argv[]) {
  int length, fd, rc;
  int buf[2] = {-1000, -1000};
  ulong MYIOC;
  fd = open("/dev/mymouse", O_RDWR);
  printf(" opened file descriptor  = %d\n", fd);
  if (argc > 1) {
    if (!strcmp(argv[1], "z")) {
      MYIOC = _IO('k', 1);
      rc = ioctl(fd, MYIOC, "anything");
      printf("\n\n rc from ioctl = %d \n\n", rc);
    }
  }
  length = 2 * sizeof(int);
  rc = read(fd, buf, length);
  printf("return code from read  = %d on %d, x = %d, y = %d\n", rc, fd, buf[0],
         buf[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)
mov    0xe63(%rip),%rax
mov    %rax,-0x24(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    122e <main+0xae>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe51(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
jne    1229 <main+0xa9>
mov    $0x6b,%edi
mov    $0x1,%esi
call   1040 <_IO@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%esi
lea    0xe26(%rip),%rdx
call   1050 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    122e <main+0xae>
movl   $0x8,-0x14(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x24(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1070 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%r8d
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%edi
call   1060 <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,%r14
mov    %edi,%ebp
movabs $0xfffffc18fffffc18,%rax
fc ff ff
mov    %rax,0x8(%rsp)
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    0xe54(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebx
lea    0xe53(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
cmp    $0x2,%ebp
jl     120b <main+0x8b>
mov    0x8(%r14),%rdi
lea    0xe59(%rip),%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
jne    120b <main+0x8b>
mov    $0x6b,%edi
mov    $0x1,%esi
call   1040 <_IO@plt>
lea    0xe3c(%rip),%rdx
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
lea    0xe35(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
call   1070 <read@plt>
mov    0x8(%rsp),%ecx
mov    0xc(%rsp),%r8d
lea    0xe24(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@__const.main.buf = [2 x i32] [i32 -1000, i32 -1000]
@.str = [13 x i8] c"/dev/mymouse\00"
@O_RDWR = global i32 0
@.str.1 = [31 x i8] c" opened file descriptor = %d\0A\00"
@.str.2 = [2 x i8] c"z\00"
@.str.3 = [9 x i8] c"anything\00"
@.str.4 = [25 x i8] c"\0A\0A rc from ioctl = %d \0A\0A\00"
@.str.5 = [51 x i8] c"return code from read = %d on %d, x = %d, y = %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
%9 = alloca [2 x i32]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = bitcast [2 x i32]* %9 to i8*
%12 = load i32, i32* @O_RDWR
%13 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %7
%14 = load i32, i32* %7
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 1
br i1 %17, label %18, label %32
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @strcmp(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%23 = icmp ne i32 %22, 0
br i1 %23, label %31, label %24
24: ; preds = %18
%25 = call i32 @_IO(i8 signext 107, i32 1)
store i32 %25, i32* %10
%26 = load i32, i32* %7
%27 = load i32, i32* %10
%28 = call i32 @ioctl(i32 %26, i32 %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %29)
br label %31
31: ; preds = %24, %18
br label %32
32: ; preds = %31, %2
store i32 8, i32* %6
%33 = load i32, i32* %7
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%35 = load i32, i32* %6
%36 = call i32 @read(i32 %33, i32* %34, i32 %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = load i32, i32* %7
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%40 = load i32, i32* %39
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%42 = load i32, i32* %41
%43 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), i32 %37, i32 %38, i32 %40, i32 %42)
%44 = load i32, i32* %7
%45 = call i32 @close(i32 %44)
%46 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/mymouse\00"
@O_RDWR = global i32 0
@.str.1 = [31 x i8] c" opened file descriptor = %d\0A\00"
@.str.2 = [2 x i8] c"z\00"
@.str.3 = [9 x i8] c"anything\00"
@.str.4 = [25 x i8] c"\0A\0A rc from ioctl = %d \0A\0A\00"
@.str.5 = [51 x i8] c"return code from read = %d on %d, x = %d, y = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
store i64 -4290672329704, i64* %3
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = icmp sgt i32 %0, 1
br i1 %8, label %9, label %18
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @strcmp(i8* dereferenceable(1) %11, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = tail call i32 @_IO(i8 signext 107, i32 1)
%16 = tail call i32 @ioctl(i32 %6, i32 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %9, %14, %2
%19 = bitcast i64* %3 to [2 x i32]*
%20 = bitcast i64* %3 to i32*
%21 = call i32 @read(i32 %6, i32* %20, i32 8)
%22 = load i32, i32* %20
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %19, i64 0, i64 1
%24 = load i32, i32* %23
%25 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.5, i64 0, i64 0), i32 %21, i32 %6, i32 %22, i32 %24)
%26 = tail call i32 @close(i32 %6)
%27 = tail call i32 @exit(i32 0)
unreachable
}