#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ LOOP_CLR_FD;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int _unassociate(const char *device_path) {
  int device = (-1);
  int result = EXIT_FAILURE;
  assert(NULL != device_path);
  device = open(device_path, O_RDONLY);
  if (-1 == device) {
    goto end;
  }
  if (0 != ioctl(device, LOOP_CLR_FD, 0)) {
    goto close_device;
  }
  result = EXIT_SUCCESS;
close_device:
  (void)close(device);
end:
  return result;
}


x86 assembly (clang, -O0):
<_unassociate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e6b(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
mov    $0xffffffff,%eax
cmp    -0xc(%rbp),%eax
jne    119a <_unassociate+0x5a>
jmp    11d4 <_unassociate+0x94>
mov    -0xc(%rbp),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11c0 <_unassociate+0x80>
jmp    11cc <_unassociate+0x8c>
mov    0x2e01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_unassociate>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbp
mov    0x2e83(%rip),%rax
mov    (%rax),%ebx
xor    %edi,%edi
test   %rbp,%rbp
setne  %dil
call   1050 <assert@plt>
mov    0x2e84(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     119c <_unassociate+0x5c>
mov    %eax,%ebp
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <ioctl@plt>
test   %rax,%rax
jne    1195 <_unassociate+0x55>
mov    0x2e35(%rip),%rax
mov    (%rax),%ebx
mov    %ebp,%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@LOOP_CLR_FD = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @_unassociate(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %3
%5 = load i32, i32* @EXIT_FAILURE
store i32 %5, i32* %4
%6 = load i8*, i8** %2
%7 = icmp ne i8* null, %6
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i8*, i8** %2
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp eq i32 -1, %13
br i1 %14, label %15, label %16
15: ; preds = %1
br label %27
16: ; preds = %1
%17 = load i32, i32* %3
%18 = load i32, i32* @LOOP_CLR_FD
%19 = call i64 @ioctl(i32 %17, i32 %18, i32 0)
%20 = icmp ne i64 0, %19
br i1 %20, label %21, label %22
21: ; preds = %16
br label %24
22: ; preds = %16
%23 = load i32, i32* @EXIT_SUCCESS
store i32 %23, i32* %4
br label %24
24: ; preds = %22, %21
%25 = load i32, i32* %3
%26 = call i32 @close(i32 %25)
br label %27
27: ; preds = %24, %15
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@LOOP_CLR_FD = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @_unassociate(i8* %0) {
%2 = load i32, i32* @EXIT_FAILURE
%3 = icmp ne i8* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %16, label %9
9: ; preds = %1
%10 = load i32, i32* @LOOP_CLR_FD
%11 = tail call i64 @ioctl(i32 %7, i32 %10, i32 0)
%12 = icmp eq i64 %11, 0
%13 = load i32, i32* @EXIT_SUCCESS
%14 = select i1 %12, i32 %13, i32 %2
%15 = tail call i32 @close(i32 %7)
br label %16
16: ; preds = %1, %9
%17 = phi i32 [ %2, %1 ], [ %14, %9 ]
ret i32 %17
}