#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 */
struct hidraw_devinfo {
  int vendor;
  int product;
};

/* Variables and functions */
int /*<<< orphan*/ HIDIOCGRAWINFO;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ ioctl(int, int /*<<< orphan*/, struct hidraw_devinfo *);
int open(char *, int /*<<< orphan*/);
int is_u1(char *_path) {
  int hid_h = open(_path, O_RDWR);
  if (hid_h < 0) {
    return 0;
  }
  struct hidraw_devinfo dev_i;
  ioctl(hid_h, HIDIOCGRAWINFO, &dev_i);
  if (dev_i.vendor != 0x0b05) {
    return 0;
  }
  if (dev_i.product != 0x1743) {
    return 0;
  }
  close(hid_h);
  return 1;
}


x86 assembly (clang, -O0):
<is_u1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1167 <is_u1+0x37>
movl   $0x0,-0x4(%rbp)
jmp    11bd <is_u1+0x8d>
mov    -0x14(%rbp),%edi
mov    0x2e7f(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1030 <ioctl@plt>
cmpl   $0xb05,-0x20(%rbp)
je     1195 <is_u1+0x65>
movl   $0x0,-0x4(%rbp)
jmp    11bd <is_u1+0x8d>
cmpl   $0x1743,-0x1c(%rbp)
je     11ae <is_u1+0x7e>
movl   $0x0,-0x4(%rbp)
jmp    11bd <is_u1+0x8d>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_u1>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ea4(%rip),%rax
mov    (%rax),%esi
call   1050 <open@plt>
test   %eax,%eax
js     1182 <is_u1+0x52>
mov    %eax,%ebx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1030 <ioctl@plt>
xor    %eax,%eax
cmpl   $0xb05,0x8(%rsp)
jne    1184 <is_u1+0x54>
cmpl   $0x1743,0xc(%rsp)
jne    1184 <is_u1+0x54>
mov    %ebx,%edi
call   1040 <close@plt>
mov    $0x1,%eax
jmp    1184 <is_u1+0x54>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.hidraw_devinfo = type { i32, i32 }
@O_RDWR = global i32 0
@HIDIOCGRAWINFO = global i32 0
define i32 @is_u1(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.hidraw_devinfo
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = load i32, i32* @O_RDWR
%8 = call i32 @open(i8* %6, i32 %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %28
12: ; preds = %1
%13 = load i32, i32* %4
%14 = load i32, i32* @HIDIOCGRAWINFO
%15 = call i32 @ioctl(i32 %13, i32 %14, %struct.hidraw_devinfo* %5)
%16 = getelementptr inbounds %struct.hidraw_devinfo, %struct.hidraw_devinfo* %5, i32 0, i32 0
%17 = load i32, i32* %16
%18 = icmp ne i32 %17, 2821
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 0, i32* %2
br label %28
20: ; preds = %12
%21 = getelementptr inbounds %struct.hidraw_devinfo, %struct.hidraw_devinfo* %5, i32 0, i32 1
%22 = load i32, i32* %21
%23 = icmp ne i32 %22, 5955
br i1 %23, label %24, label %25
24: ; preds = %20
store i32 0, i32* %2
br label %28
25: ; preds = %20
%26 = load i32, i32* %4
%27 = call i32 @close(i32 %26)
store i32 1, i32* %2
br label %28
28: ; preds = %25, %24, %19, %11
%29 = load i32, i32* %2
ret i32 %29
}

LLVM IR (-O2):
%struct.hidraw_devinfo = type { i32, i32 }
@O_RDWR = global i32 0
@HIDIOCGRAWINFO = global i32 0
define i32 @is_u1(i8* nocapture %0) {
%2 = alloca %struct.hidraw_devinfo
%3 = load i32, i32* @O_RDWR
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %21, label %6
6: ; preds = %1
%7 = bitcast %struct.hidraw_devinfo* %2 to i8*
%8 = load i32, i32* @HIDIOCGRAWINFO
%9 = call i32 @ioctl(i32 %4, i32 %8, %struct.hidraw_devinfo* %2)
%10 = getelementptr inbounds %struct.hidraw_devinfo, %struct.hidraw_devinfo* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = icmp eq i32 %11, 2821
%13 = getelementptr inbounds %struct.hidraw_devinfo, %struct.hidraw_devinfo* %2, i64 0, i32 1
%14 = load i32, i32* %13
%15 = icmp eq i32 %14, 5955
%16 = select i1 %12, i1 %15, i1 false
br i1 %16, label %17, label %19
17: ; preds = %6
%18 = call i32 @close(i32 %4)
br label %19
19: ; preds = %6, %17
%20 = phi i32 [ 1, %17 ], [ 0, %6 ]
br label %21
21: ; preds = %1, %19
%22 = phi i32 [ %20, %19 ], [ 0, %1 ]
ret i32 %22
}