#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 ioctl(int, int, unsigned int);
int open(char *, int /*<<< orphan*/);
int rtai_shmrq(int srq, unsigned int whatever) {
  int fd;
  int ret;
  fd = open("/dev/rtai_shm", O_RDWR);
  if (fd < 0) {
    srq += 186;
    fd = open("/dev/RTAI_SHM", O_RDWR);
    if (fd < 0)
      return fd;
  }
  ret = ioctl(fd, srq, whatever);
  close(fd);
  return ret;
}


x86 assembly (clang, -O0):
<rtai_shmrq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%esi
lea    0xeb2(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    119d <rtai_shmrq+0x6d>
mov    -0x8(%rbp),%eax
add    $0xba,%eax
mov    %eax,-0x8(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%esi
lea    0xe93(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    1198 <rtai_shmrq+0x68>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11bc <rtai_shmrq+0x8c>
jmp    119d <rtai_shmrq+0x6d>
mov    -0x10(%rbp),%edi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <ioctl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtai_shmrq>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebp
mov    0x2ea5(%rip),%r15
mov    (%r15),%esi
lea    0xeb3(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     115a <rtai_shmrq+0x2a>
mov    %eax,%ebx
jmp    1175 <rtai_shmrq+0x45>
mov    (%r15),%esi
lea    0xeaa(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1197 <rtai_shmrq+0x67>
add    $0xba,%ebp
mov    %ebx,%edi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <ioctl@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%eax
jmp    118c <rtai_shmrq+0x5c>

LLVM IR (-O0):
@.str = [14 x i8] c"/dev/rtai_shm\00"
@O_RDWR = global i32 0
@.str.1 = [14 x i8] c"/dev/RTAI_SHM\00"
define i32 @rtai_shmrq(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %22
12: ; preds = %2
%13 = load i32, i32* %4
%14 = add nsw i32 %13, 186
store i32 %14, i32* %4
%15 = load i32, i32* @O_RDWR
%16 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = load i32, i32* %6
store i32 %20, i32* %3
br label %30
21: ; preds = %12
br label %22
22: ; preds = %21, %2
%23 = load i32, i32* %6
%24 = load i32, i32* %4
%25 = load i32, i32* %5
%26 = call i32 @ioctl(i32 %23, i32 %24, i32 %25)
store i32 %26, i32* %7
%27 = load i32, i32* %6
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %7
store i32 %29, i32* %3
br label %30
30: ; preds = %22, %19
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@.str = [14 x i8] c"/dev/rtai_shm\00"
@O_RDWR = global i32 0
@.str.1 = [14 x i8] c"/dev/RTAI_SHM\00"
define i32 @rtai_shmrq(i32 %0, i32 %1) {
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = add nsw i32 %0, 186
%8 = load i32, i32* @O_RDWR
%9 = tail call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %16, label %11
11: ; preds = %6, %2
%12 = phi i32 [ %7, %6 ], [ %0, %2 ]
%13 = phi i32 [ %9, %6 ], [ %4, %2 ]
%14 = tail call i32 @ioctl(i32 %13, i32 %12, i32 %1)
%15 = tail call i32 @close(i32 %13)
br label %16
16: ; preds = %6, %11
%17 = phi i32 [ %14, %11 ], [ %9, %6 ]
ret i32 %17
}