#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*/ O_RDWR;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int write(int, unsigned long *, int);
int __test(unsigned long cmd, unsigned long val1, unsigned long val2) {
  int fd, ret;
  unsigned long buf[3];
  fd = open("/dev/resch", O_RDWR);
  if (fd < 0) {
    printf("Error: failed to access the module!\n");
    return 1;
  }
  buf[0] = cmd;
  buf[1] = val1;
  buf[2] = val2;
  ret = write(fd, buf, sizeof(long) * 3);
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<__test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e8d(%rip),%rax
mov    (%rax),%esi
lea    0xe9c(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    118e <__test+0x4e>
lea    0xe8e(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c8 <__test+0x88>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x18,%edx
call   1030 <write@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__test>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    0x2e8c(%rip),%rax
mov    (%rax),%esi
lea    0xe9b(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1198 <__test+0x58>
mov    %eax,%ebx
mov    %r12,(%rsp)
mov    %r15,0x8(%rsp)
mov    %r14,0x10(%rsp)
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x18,%edx
call   1040 <write@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <close@plt>
jmp    11a9 <__test+0x69>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/resch\00"
@O_RDWR = global i32 0
@.str.1 = [37 x i8] c"Error: failed to access the module!\0A\00"
define i32 @__test(i64 %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
%10 = alloca [3 x i64]
store i64 %0, i64* %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %30
17: ; preds = %3
%18 = load i64, i64* %5
%19 = getelementptr inbounds [3 x i64], [3 x i64]* %10, i64 0, i64 0
store i64 %18, i64* %19
%20 = load i64, i64* %6
%21 = getelementptr inbounds [3 x i64], [3 x i64]* %10, i64 0, i64 1
store i64 %20, i64* %21
%22 = load i64, i64* %7
%23 = getelementptr inbounds [3 x i64], [3 x i64]* %10, i64 0, i64 2
store i64 %22, i64* %23
%24 = load i32, i32* %8
%25 = getelementptr inbounds [3 x i64], [3 x i64]* %10, i64 0, i64 0
%26 = call i32 @write(i32 %24, i64* %25, i32 24)
store i32 %26, i32* %9
%27 = load i32, i32* %8
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %9
store i32 %29, i32* %4
br label %30
30: ; preds = %17, %15
%31 = load i32, i32* %4
ret i32 %31
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/resch\00"
@O_RDWR = global i32 0
@str = [36 x i8] c"Error: failed to access the module!\00"
define i32 @__test(i64 %0, i64 %1, i64 %2) {
%4 = alloca [3 x i64]
%5 = bitcast [3 x i64]* %4 to i8*
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %17
11: ; preds = %3
%12 = getelementptr inbounds [3 x i64], [3 x i64]* %4, i64 0, i64 0
store i64 %0, i64* %12
%13 = getelementptr inbounds [3 x i64], [3 x i64]* %4, i64 0, i64 1
store i64 %1, i64* %13
%14 = getelementptr inbounds [3 x i64], [3 x i64]* %4, i64 0, i64 2
store i64 %2, i64* %14
%15 = call i32 @write(i32 %7, i64* %12, i32 24)
%16 = tail call i32 @close(i32 %7)
br label %17
17: ; preds = %11, %9
%18 = phi i32 [ 1, %9 ], [ %15, %11 ]
ret i32 %18
}