#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*/ HDIO_DRIVE_CMD;
int /*<<< orphan*/ O_RDWR;
scalar_t__ ioctl(int, int /*<<< orphan*/, unsigned char **);
int open(char *, int /*<<< orphan*/);
int do_standby_idedisk(char *device) {
  unsigned char args1[4] = {0xE0, 0, 0, 0};
  unsigned char args2[4] = {0x94, 0, 0, 0};
  int fd;
  if ((fd = open(device, O_RDWR)) < 0)
    return -1;
  if (ioctl(fd, HDIO_DRIVE_CMD, &args1) && ioctl(fd, HDIO_DRIVE_CMD, &args2))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<do_standby_idedisk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xece(%rip),%eax
mov    %eax,-0x14(%rbp)
mov    0xec9(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e9f(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1168 <do_standby_idedisk+0x48>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <do_standby_idedisk+0x99>
mov    -0x1c(%rbp),%edi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
je     11b2 <do_standby_idedisk+0x92>
mov    -0x1c(%rbp),%edi
mov    0x2e4f(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
je     11b2 <do_standby_idedisk+0x92>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b9 <do_standby_idedisk+0x99>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_standby_idedisk>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0xe0,0xc(%rsp)
movl   $0x94,0x8(%rsp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
call   1040 <open@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
js     1182 <do_standby_idedisk+0x62>
mov    %eax,%ebp
mov    0x2e88(%rip),%r14
mov    (%r14),%esi
lea    0xc(%rsp),%rdx
mov    %eax,%edi
call   1030 <ioctl@plt>
test   %rax,%rax
je     1180 <do_standby_idedisk+0x60>
mov    (%r14),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1030 <ioctl@plt>
test   %rax,%rax
jne    1182 <do_standby_idedisk+0x62>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.do_standby_idedisk.args1 = [4 x i8] c"\E0\00\00\00"
@__const.do_standby_idedisk.args2 = [4 x i8] c"\94\00\00\00"
@O_RDWR = global i32 0
@HDIO_DRIVE_CMD = global i32 0
define i32 @do_standby_idedisk(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i8]
%5 = alloca [4 x i8]
%6 = alloca i32
store i8* %0, i8** %3
%7 = bitcast [4 x i8]* %4 to i8*
%8 = bitcast [4 x i8]* %5 to i8*
%9 = load i8*, i8** %3
%10 = load i32, i32* @O_RDWR
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 -1, i32* %2
br label %28
14: ; preds = %1
%15 = load i32, i32* %6
%16 = load i32, i32* @HDIO_DRIVE_CMD
%17 = bitcast [4 x i8]* %4 to i8**
%18 = call i64 @ioctl(i32 %15, i32 %16, i8** %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %27
20: ; preds = %14
%21 = load i32, i32* %6
%22 = load i32, i32* @HDIO_DRIVE_CMD
%23 = bitcast [4 x i8]* %5 to i8**
%24 = call i64 @ioctl(i32 %21, i32 %22, i8** %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
store i32 -1, i32* %2
br label %28
27: ; preds = %20, %14
store i32 0, i32* %2
br label %28
28: ; preds = %27, %26, %13
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@HDIO_DRIVE_CMD = global i32 0
define i32 @do_standby_idedisk(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = bitcast i32* %2 to i8*
store i32 224, i32* %2
%5 = bitcast i32* %3 to i8*
store i32 148, i32* %3
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %1
%10 = load i32, i32* @HDIO_DRIVE_CMD
%11 = bitcast i32* %2 to i8**
%12 = call i64 @ioctl(i32 %7, i32 %10, i8** %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = load i32, i32* @HDIO_DRIVE_CMD
%16 = bitcast i32* %3 to i8**
%17 = call i64 @ioctl(i32 %7, i32 %15, i8** %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14, %9
br label %20
20: ; preds = %14, %1, %19
%21 = phi i32 [ 0, %19 ], [ -1, %1 ], [ -1, %14 ]
ret i32 %21
}