#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 get_id_lun(char const *);
int is_sd_device(char const *);
int is_sg_device(char const *);
int is_usb_fdd_for_host(int);
int is_usb_fdd(const char *dev) {
  int idlun;
  int is_sd;
  int is_sg;
  if ((is_sd = is_sd_device(dev)) < 0 || (is_sg = is_sg_device(dev)) < 0) {
    return -1;
  }
  if (!is_sd && !is_sg) {
    return 0;
  }
  if ((idlun = get_id_lun(dev)) == -1) {
    return -1;
  }
  return is_usb_fdd_for_host(((idlun >> 24) & 0xff));
}


x86 assembly (clang, -O0):
<is_usb_fdd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <is_sd_device@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jl     1176 <is_usb_fdd+0x36>
mov    -0x10(%rbp),%rdi
call   1060 <is_sg_device@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1182 <is_usb_fdd+0x42>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <is_usb_fdd+0x97>
cmpl   $0x0,-0x18(%rbp)
jne    11a2 <is_usb_fdd+0x62>
cmpl   $0x0,-0x1c(%rbp)
jne    11a2 <is_usb_fdd+0x62>
movl   $0x0,-0x4(%rbp)
jmp    11d7 <is_usb_fdd+0x97>
mov    -0x10(%rbp),%rdi
call   1030 <get_id_lun@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11c3 <is_usb_fdd+0x83>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d7 <is_usb_fdd+0x97>
mov    -0x14(%rbp),%edi
sar    $0x18,%edi
and    $0xff,%edi
call   1040 <is_usb_fdd_for_host@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_usb_fdd>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1050 <is_sd_device@plt>
mov    $0xffffffff,%r14d
test   %eax,%eax
js     118c <is_usb_fdd+0x4c>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <is_sg_device@plt>
test   %eax,%eax
js     118c <is_usb_fdd+0x4c>
xor    %r14d,%r14d
or     %eax,%ebp
je     118c <is_usb_fdd+0x4c>
mov    %rbx,%rdi
call   1030 <get_id_lun@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%eax
je     118c <is_usb_fdd+0x4c>
shr    $0x18,%eax
mov    %eax,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <is_usb_fdd_for_host@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @is_usb_fdd(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @is_sd_device(i8* %7)
store i32 %8, i32* %5
%9 = icmp slt i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @is_sg_device(i8* %11)
store i32 %12, i32* %6
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %10, %1
store i32 -1, i32* %2
br label %32
15: ; preds = %10
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %18
store i32 0, i32* %2
br label %32
22: ; preds = %18, %15
%23 = load i8*, i8** %3
%24 = call i32 @get_id_lun(i8* %23)
store i32 %24, i32* %4
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 -1, i32* %2
br label %32
27: ; preds = %22
%28 = load i32, i32* %4
%29 = ashr i32 %28, 24
%30 = and i32 %29, 255
%31 = call i32 @is_usb_fdd_for_host(i32 %30)
store i32 %31, i32* %2
br label %32
32: ; preds = %27, %26, %21, %14
%33 = load i32, i32* %2
ret i32 %33
}

LLVM IR (-O2):
define i32 @is_usb_fdd(i8* %0) {
%2 = tail call i32 @is_sd_device(i8* %0)
%3 = icmp slt i32 %2, 0
br i1 %3, label %17, label %4
4: ; preds = %1
%5 = tail call i32 @is_sg_device(i8* %0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %17, label %7
7: ; preds = %4
%8 = icmp ne i32 %2, 0
%9 = icmp ne i32 %5, 0
%10 = select i1 %8, i1 true, i1 %9
br i1 %10, label %11, label %17
11: ; preds = %7
%12 = tail call i32 @get_id_lun(i8* %0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = lshr i32 %12, 24
%16 = tail call i32 @is_usb_fdd_for_host(i32 %15)
br label %17
17: ; preds = %11, %7, %1, %4, %14
%18 = phi i32 [ %16, %14 ], [ -1, %4 ], [ -1, %1 ], [ 0, %7 ], [ -1, %11 ]
ret i32 %18
}