#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*/ SG_SCSI_RESET;
int SG_SCSI_RESET_BUS;
scalar_t__ ioctl(int, int /*<<< orphan*/, int *);
int ufi_reset(int fd) {
  int mode = 4;
  if (ioctl(fd, SG_SCSI_RESET, &mode) < 0) {
    mode = SG_SCSI_RESET_BUS;
    if (ioctl(fd, SG_SCSI_RESET, &mode) < 0) {
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<ufi_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    117d <ufi_reset+0x6d>
mov    0x2ea0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1178 <ufi_reset+0x68>
movl   $0xffffffff,-0x4(%rbp)
jmp    1184 <ufi_reset+0x74>
jmp    117d <ufi_reset+0x6d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ufi_reset>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
movl   $0x4,0x4(%rsp)
mov    0x2eb3(%rip),%r14
mov    (%r14),%esi
lea    0x4(%rsp),%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
jns    1158 <ufi_reset+0x48>
mov    0x2eaa(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    (%r14),%esi
lea    0x4(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
test   %rax,%rax
js     1162 <ufi_reset+0x52>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    $0xffffffff,%eax
jmp    115a <ufi_reset+0x4a>

LLVM IR (-O0):
@SG_SCSI_RESET = global i32 0
@SG_SCSI_RESET_BUS = global i32 0
define i32 @ufi_reset(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 4, i32* %4
%5 = load i32, i32* %3
%6 = load i32, i32* @SG_SCSI_RESET
%7 = call i64 @ioctl(i32 %5, i32 %6, i32* %4)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = load i32, i32* @SG_SCSI_RESET_BUS
store i32 %10, i32* %4
%11 = load i32, i32* %3
%12 = load i32, i32* @SG_SCSI_RESET
%13 = call i64 @ioctl(i32 %11, i32 %12, i32* %4)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %9
store i32 -1, i32* %2
br label %18
16: ; preds = %9
br label %17
17: ; preds = %16, %1
store i32 0, i32* %2
br label %18
18: ; preds = %17, %15
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
@SG_SCSI_RESET = global i32 0
@SG_SCSI_RESET_BUS = global i32 0
define i32 @ufi_reset(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 4, i32* %2
%4 = load i32, i32* @SG_SCSI_RESET
%5 = call i64 @ioctl(i32 %0, i32 %4, i32* %2)
%6 = icmp slt i64 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32, i32* @SG_SCSI_RESET_BUS
store i32 %8, i32* %2
%9 = load i32, i32* @SG_SCSI_RESET
%10 = call i64 @ioctl(i32 %0, i32 %9, i32* %2)
%11 = icmp slt i64 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %7, %1
br label %13
13: ; preds = %7, %12
%14 = phi i32 [ 0, %12 ], [ -1, %7 ]
ret i32 %14
}