#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*/ NBD_CLEAR_QUE;
int /*<<< orphan*/ NBD_CLEAR_SOCK;
int /*<<< orphan*/ NBD_DISCONNECT;
int /*<<< orphan*/ O_RDWR;
scalar_t__ ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int main(void) {
  int nbd = open("/dev/nbd0", O_RDWR);
  if (nbd < 0) {
    perror("open");
    return 1;
  }
  if (ioctl(nbd, NBD_CLEAR_QUE) < 0)
    perror("ioctl");
  if (ioctl(nbd, NBD_CLEAR_SOCK) < 0)
    perror("ioctl");
  if (ioctl(nbd, NBD_DISCONNECT) < 0)
    perror("ioctl");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1040 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1179 <main+0x49>
lea    0xea2(%rip),%rdi
call   1050 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f5 <main+0xc5>
mov    -0x8(%rbp),%edi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11a0 <main+0x70>
lea    0xe74(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11c7 <main+0x97>
lea    0xe4d(%rip),%rdi
call   1050 <perror@plt>
mov    -0x8(%rbp),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11ee <main+0xbe>
lea    0xe26(%rip),%rdi
call   1050 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2eb0(%rip),%rax
mov    (%rax),%esi
lea    0xebf(%rip),%rdi
call   1040 <open@plt>
test   %eax,%eax
js     1191 <main+0x61>
mov    %eax,%ebx
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %rax,%rax
js     119f <main+0x6f>
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %rax,%rax
js     11ad <main+0x7d>
mov    0x2e53(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1030 <ioctl@plt>
xor    %ebx,%ebx
test   %rax,%rax
js     11bb <main+0x8b>
mov    %ebx,%eax
pop    %rbx
ret
mov    $0x1,%ebx
lea    0xe6d(%rip),%rdi
jmp    11c2 <main+0x92>
lea    0xe69(%rip),%rdi
call   1050 <perror@plt>
jmp    1161 <main+0x31>
lea    0xe5b(%rip),%rdi
call   1050 <perror@plt>
jmp    1176 <main+0x46>
lea    0xe4d(%rip),%rdi
call   1050 <perror@plt>
jmp    118d <main+0x5d>

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

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/nbd0\00"
@O_RDWR = global i32 0
@.str.1 = [5 x i8] c"open\00"
@NBD_CLEAR_QUE = global i32 0
@.str.2 = [6 x i8] c"ioctl\00"
@NBD_CLEAR_SOCK = global i32 0
@NBD_DISCONNECT = global i32 0
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %0
%5 = load i32, i32* @NBD_CLEAR_QUE
%6 = tail call i64 @ioctl(i32 %2, i32 %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %4
%11 = load i32, i32* @NBD_CLEAR_SOCK
%12 = tail call i64 @ioctl(i32 %2, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = load i32, i32* @NBD_DISCONNECT
%18 = tail call i64 @ioctl(i32 %2, i32 %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16, %0
%21 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %0 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %16 ]
%22 = phi i32 [ 1, %0 ], [ 0, %16 ]
%23 = tail call i32 @perror(i8* %21)
br label %24
24: ; preds = %20, %16
%25 = phi i32 [ 0, %16 ], [ %22, %20 ]
ret i32 %25
}