#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*/ LOOP_CLR_FD;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char const *, int /*<<< orphan*/);
int crypt_loop_detach(const char *loop) {
  int loop_fd = -1, r = 1;
  loop_fd = open(loop, O_RDONLY);
  if (loop_fd < 0)
    return 1;
  if (!ioctl(loop_fd, LOOP_CLR_FD, 0))
    r = 0;
  close(loop_fd);
  return r;
}


x86 assembly (clang, -O0):
<crypt_loop_detach>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1175 <crypt_loop_detach+0x45>
movl   $0x1,-0x4(%rbp)
jmp    11a6 <crypt_loop_detach+0x76>
mov    -0x14(%rbp),%edi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
cmp    $0x0,%eax
jne    1198 <crypt_loop_detach+0x68>
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crypt_loop_detach>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eae(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     116a <crypt_loop_detach+0x3a>
mov    %eax,%ebx
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <ioctl@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
mov    %ebx,%edi
call   1040 <close@plt>
jmp    116f <crypt_loop_detach+0x3f>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@LOOP_CLR_FD = global i32 0
define i32 @crypt_loop_detach(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 -1, i32* %4
store i32 1, i32* %5
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 1, i32* %2
br label %22
12: ; preds = %1
%13 = load i32, i32* %4
%14 = load i32, i32* @LOOP_CLR_FD
%15 = call i32 @ioctl(i32 %13, i32 %14, i32 0)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %12
store i32 0, i32* %5
br label %18
18: ; preds = %17, %12
%19 = load i32, i32* %4
%20 = call i32 @close(i32 %19)
%21 = load i32, i32* %5
store i32 %21, i32* %2
br label %22
22: ; preds = %18, %11
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@LOOP_CLR_FD = global i32 0
define i32 @crypt_loop_detach(i8* nocapture %0) {
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp slt i32 %3, 0
br i1 %4, label %11, label %5
5: ; preds = %1
%6 = load i32, i32* @LOOP_CLR_FD
%7 = tail call i32 @ioctl(i32 %3, i32 %6, i32 0)
%8 = icmp ne i32 %7, 0
%9 = zext i1 %8 to i32
%10 = tail call i32 @close(i32 %3)
br label %11
11: ; preds = %1, %5
%12 = phi i32 [ %9, %5 ], [ 1, %1 ]
ret i32 %12
}