#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_RDWR;
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int close_loopback(char *loop_dev) {
  int loop_fd, ret;
  loop_fd = open(loop_dev, O_RDWR);
  if (loop_fd == -1)
    return -1;
  ret = ioctl(loop_fd, LOOP_CLR_FD, 0);
  close(loop_fd);
  if (ret == -1)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<close_loopback>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2ea1(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1167 <close_loopback+0x37>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <close_loopback+0x72>
mov    -0x14(%rbp),%edi
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    119b <close_loopback+0x6b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a2 <close_loopback+0x72>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_loopback>:
push   %rbp
push   %rbx
push   %rax
mov    0x2eae(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     116f <close_loopback+0x3f>
mov    %eax,%ebx
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1030 <ioctl@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
xor    %eax,%eax
cmp    $0xffffffff,%ebp
sete   %al
neg    %eax
jmp    1174 <close_loopback+0x44>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@O_RDWR = global i32 0
@LOOP_CLR_FD = global i32 0
define i32 @close_loopback(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp eq i32 %9, -1
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)
store i32 %15, i32* %5
%16 = load i32, i32* %4
%17 = call i32 @close(i32 %16)
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %12
store i32 -1, i32* %2
br label %22
21: ; preds = %12
store i32 0, i32* %2
br label %22
22: ; preds = %21, %20, %11
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@LOOP_CLR_FD = global i32 0
define i32 @close_loopback(i8* nocapture %0) {
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* %0, i32 %2)
%4 = icmp eq i32 %3, -1
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 = tail call i32 @close(i32 %3)
%9 = icmp eq i32 %7, -1
%10 = sext i1 %9 to i32
br label %11
11: ; preds = %5, %1
%12 = phi i32 [ -1, %1 ], [ %10, %5 ]
ret i32 %12
}