#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int scsi_modeselect(int, unsigned char *);
scalar_t__ scsi_modesense(int, int, unsigned char *, int);
int scsi_smartDEXCPTdisable(int device) {
  unsigned char buf[255];
  if (scsi_modesense(device, 0x1c, buf, sizeof(buf)) != 0)
    return 1;
  if (buf[14] & 0x08) {
    buf[14] &= 0xf7;
    buf[15] = 0x04;
    return scsi_modeselect(device, buf);
  } else
    return 0;
}


x86 assembly (clang, -O0):
<scsi_smartDEXCPTdisable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rdx
mov    $0x1c,%esi
mov    $0xff,%ecx
call   1030 <scsi_modesense@plt>
cmp    $0x0,%rax
je     115d <scsi_smartDEXCPTdisable+0x3d>
movl   $0x1,-0x4(%rbp)
jmp    11a7 <scsi_smartDEXCPTdisable+0x87>
movzbl -0x102(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     11a0 <scsi_smartDEXCPTdisable+0x80>
movzbl -0x102(%rbp),%eax
and    $0xf7,%eax
mov    %al,-0x102(%rbp)
movb   $0x4,-0x101(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x110(%rbp),%rsi
call   1040 <scsi_modeselect@plt>
mov    %eax,-0x4(%rbp)
jmp    11a7 <scsi_smartDEXCPTdisable+0x87>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scsi_smartDEXCPTdisable>:
push   %rbx
sub    $0x100,%rsp
mov    %edi,%ebx
mov    %rsp,%rdx
mov    $0x1c,%esi
mov    $0xff,%ecx
call   1030 <scsi_modesense@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    116a <scsi_smartDEXCPTdisable+0x4a>
mov    0xe(%rsp),%cl
xor    %eax,%eax
test   $0x8,%cl
je     116a <scsi_smartDEXCPTdisable+0x4a>
and    $0xf7,%cl
mov    %cl,0xe(%rsp)
movb   $0x4,0xf(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
call   1040 <scsi_modeselect@plt>
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @scsi_smartDEXCPTdisable(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [255 x i8]
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%7 = call i64 @scsi_modesense(i32 %5, i32 28, i8* %6, i32 255)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 1, i32* %2
br label %27
10: ; preds = %1
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 14
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = and i32 %13, 8
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %10
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 14
%18 = load i8, i8* %17
%19 = zext i8 %18 to i32
%20 = and i32 %19, 247
%21 = trunc i32 %20 to i8
store i8 %21, i8* %17
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 15
store i8 4, i8* %22
%23 = load i32, i32* %3
%24 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%25 = call i32 @scsi_modeselect(i32 %23, i8* %24)
store i32 %25, i32* %2
br label %27
26: ; preds = %10
store i32 0, i32* %2
br label %27
27: ; preds = %26, %16, %9
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
define i32 @scsi_smartDEXCPTdisable(i32 %0) {
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%4 = call i64 @scsi_modesense(i32 %0, i32 28, i8* %3, i32 255)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %1
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 14
%8 = load i8, i8* %7
%9 = and i8 %8, 8
%10 = icmp eq i8 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %6
%12 = and i8 %8, -9
store i8 %12, i8* %7
%13 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 15
store i8 4, i8* %13
%14 = call i32 @scsi_modeselect(i32 %0, i8* %3)
br label %15
15: ; preds = %6, %1, %11
%16 = phi i32 [ %14, %11 ], [ 1, %1 ], [ 0, %6 ]
ret i32 %16
}