#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 EBADF;
int /*<<< orphan*/ _IO(char, int);
int /*<<< orphan*/ dasd_close_device(int);
int errno;
scalar_t__ ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
int dasd_disk_enable(int fd) {
  do {
    if (ioctl(fd, _IO('D', 1), NULL) != 0) {
      int err = errno;
      if (err != EBADF)
        dasd_close_device(fd);
      return err;
    }
  } while (0);
  dasd_close_device(fd);
  return 0;
}


x86 assembly (clang, -O0):
<dasd_disk_enable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x44,%edi
mov    $0x1,%esi
call   1030 <_IO@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
je     1199 <dasd_disk_enable+0x69>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2e5a(%rip),%rcx
cmp    (%rcx),%eax
je     118e <dasd_disk_enable+0x5e>
mov    -0x8(%rbp),%edi
call   1040 <dasd_close_device@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ad <dasd_disk_enable+0x7d>
jmp    119e <dasd_disk_enable+0x6e>
mov    -0x8(%rbp),%edi
call   1040 <dasd_close_device@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dasd_disk_enable>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x44,%edi
mov    $0x1,%esi
call   1030 <_IO@plt>
xor    %ebx,%ebx
mov    %ebp,%edi
mov    %eax,%esi
xor    %edx,%edx
call   1050 <ioctl@plt>
test   %rax,%rax
je     116a <dasd_disk_enable+0x3a>
mov    0x2e83(%rip),%rax
mov    (%rax),%ebx
mov    0x2e72(%rip),%rax
cmp    (%rax),%ebx
je     1171 <dasd_disk_enable+0x41>
mov    %ebp,%edi
call   1040 <dasd_close_device@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@EBADF = global i32 0
define i32 @dasd_disk_enable(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
br label %5
5: ; preds = %1
%6 = load i32, i32* %3
%7 = call i32 @_IO(i8 signext 68, i32 1)
%8 = call i64 @ioctl(i32 %6, i32 %7, i32* null)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %20
10: ; preds = %5
%11 = load i32, i32* @errno
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = load i32, i32* @EBADF
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = load i32, i32* %3
%17 = call i32 @dasd_close_device(i32 %16)
br label %18
18: ; preds = %15, %10
%19 = load i32, i32* %4
store i32 %19, i32* %2
br label %24
20: ; preds = %5
br label %21
21: ; preds = %20
%22 = load i32, i32* %3
%23 = call i32 @dasd_close_device(i32 %22)
store i32 0, i32* %2
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
@errno = global i32 0
@EBADF = global i32 0
define i32 @dasd_disk_enable(i32 %0) {
%2 = tail call i32 @_IO(i8 signext 68, i32 1)
%3 = tail call i64 @ioctl(i32 %0, i32 %2, i32* null)
%4 = icmp eq i64 %3, 0
br i1 %4, label %9, label %5
5: ; preds = %1
%6 = load i32, i32* @errno
%7 = load i32, i32* @EBADF
%8 = icmp eq i32 %6, %7
br i1 %8, label %12, label %9
9: ; preds = %1, %5
%10 = phi i32 [ %6, %5 ], [ 0, %1 ]
%11 = tail call i32 @dasd_close_device(i32 %0)
br label %12
12: ; preds = %9, %5
%13 = phi i32 [ %6, %5 ], [ %10, %9 ]
ret i32 %13
}