#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);
unsigned long ioctl(int, int, unsigned long);
int /*<<< orphan*/ munmap(void *, unsigned long);
int open(char *, int /*<<< orphan*/);
void rtai_free(unsigned long name, void *adr) {
  unsigned long size;
  int hook;
  struct {
    void *nameadr;
  } arg = {&name};
  (void)adr;
  if ((hook = open("/dev/RTAI_SHM", O_RDWR)) < 0)
    return;
  if ((size = ioctl(hook, 189, (unsigned long)&arg))) {
    munmap((void *)name, size);
  }
  close(hook);
}


x86 assembly (clang, -O0):
<rtai_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xe98(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    117e <rtai_free+0x3e>
jmp    11b2 <rtai_free+0x72>
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rdx
mov    $0xbd,%esi
call   1030 <ioctl@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11aa <rtai_free+0x6a>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <munmap@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtai_free>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,(%rsp)
mov    %rsp,%rax
mov    %rax,0x8(%rsp)
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xe9f(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     1195 <rtai_free+0x55>
mov    %eax,%ebx
lea    0x8(%rsp),%rdx
mov    %eax,%edi
mov    $0xbd,%esi
call   1030 <ioctl@plt>
test   %rax,%rax
je     118e <rtai_free+0x4e>
mov    (%rsp),%rdi
mov    %rax,%rsi
call   1050 <munmap@plt>
mov    %ebx,%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.anon = type { i8* }
@.str = [14 x i8] c"/dev/RTAI_SHM\00"
@O_RDWR = global i32 0
define void @rtai_free(i64 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
%7 = alloca %struct.anon
store i64 %0, i64* %3
store i8* %1, i8** %4
%8 = getelementptr inbounds %struct.anon, %struct.anon* %7, i32 0, i32 0
%9 = bitcast i64* %3 to i8*
store i8* %9, i8** %8
%10 = load i8*, i8** %4
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
br label %28
15: ; preds = %2
%16 = load i32, i32* %6
%17 = ptrtoint %struct.anon* %7 to i64
%18 = call i64 @ioctl(i32 %16, i32 189, i64 %17)
store i64 %18, i64* %5
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i64, i64* %3
%22 = inttoptr i64 %21 to i8*
%23 = load i64, i64* %5
%24 = call i32 @munmap(i8* %22, i64 %23)
br label %25
25: ; preds = %20, %15
%26 = load i32, i32* %6
%27 = call i32 @close(i32 %26)
br label %28
28: ; preds = %25, %14
ret void
}

LLVM IR (-O2):
%struct.anon = type { i8* }
@.str = [14 x i8] c"/dev/RTAI_SHM\00"
@O_RDWR = global i32 0
define void @rtai_free(i64 %0, i8* nocapture readnone %1) {
%3 = alloca i64
%4 = alloca %struct.anon
store i64 %0, i64* %3
%5 = bitcast %struct.anon* %4 to i8*
%6 = bitcast %struct.anon* %4 to i64**
store i64* %3, i64** %6
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %20, label %10
10: ; preds = %2
%11 = ptrtoint %struct.anon* %4 to i64
%12 = call i64 @ioctl(i32 %8, i32 189, i64 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %18, label %14
14: ; preds = %10
%15 = load i64, i64* %3
%16 = inttoptr i64 %15 to i8*
%17 = call i32 @munmap(i8* %16, i64 %12)
br label %18
18: ; preds = %14, %10
%19 = call i32 @close(i32 %8)
br label %20
20: ; preds = %2, %18
ret void
}