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

/* Variables and functions */
int /*<<< orphan*/ EVIOCGBIT(int /*<<< orphan*/, int);
int /*<<< orphan*/ EV_KEY;
int /*<<< orphan*/ EV_SW;
int ioctl(int, int /*<<< orphan*/, int /*<<< orphan*/ *);
scalar_t__ test_bit(int /*<<< orphan*/, int /*<<< orphan*/ *);
int device_is_suitable(int fd) {
  uint32_t bits[32];
  int rc = ioctl(fd, EVIOCGBIT(0, sizeof(bits)), bits);
  return rc > 0 && (test_bit(EV_KEY, bits) || test_bit(EV_SW, bits));
}


x86 assembly (clang, -O0):
<device_is_suitable>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x9c(%rbp)
xor    %edi,%edi
mov    $0x80,%esi
call   1030 <EVIOCGBIT@plt>
mov    -0x9c(%rbp),%edi
mov    %eax,%esi
lea    -0x90(%rbp),%rdx
call   1040 <ioctl@plt>
mov    %eax,-0x94(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x94(%rbp)
mov    %al,-0x95(%rbp)
jle    11da <device_is_suitable+0xaa>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rsi
call   1050 <test_bit@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x9d(%rbp)
jne    11ce <device_is_suitable+0x9e>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
lea    -0x90(%rbp),%rsi
call   1050 <test_bit@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x9d(%rbp)
mov    -0x9d(%rbp),%al
mov    %al,-0x95(%rbp)
mov    -0x95(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<device_is_suitable>:
push   %rbp
push   %rbx
sub    $0x88,%rsp
mov    %edi,%ebp
xor    %ebx,%ebx
xor    %edi,%edi
mov    $0x80,%esi
call   1030 <EVIOCGBIT@plt>
mov    %rsp,%rdx
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <ioctl@plt>
test   %eax,%eax
jle    118d <device_is_suitable+0x5d>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1050 <test_bit@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    118d <device_is_suitable+0x5d>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1050 <test_bit@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    %ebx,%eax
add    $0x88,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@EV_KEY = global i32 0
@EV_SW = global i32 0
define i32 @device_is_suitable(i32 %0) {
%2 = alloca i32
%3 = alloca [32 x i32]
%4 = alloca i32
store i32 %0, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @EVIOCGBIT(i32 0, i32 128)
%7 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%8 = call i32 @ioctl(i32 %5, i32 %6, i32* %7)
store i32 %8, i32* %4
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %1
%12 = load i32, i32* @EV_KEY
%13 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%14 = call i64 @test_bit(i32 %12, i32* %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = load i32, i32* @EV_SW
%18 = getelementptr inbounds [32 x i32], [32 x i32]* %3, i64 0, i64 0
%19 = call i64 @test_bit(i32 %17, i32* %18)
%20 = icmp ne i64 %19, 0
br label %21
21: ; preds = %16, %11
%22 = phi i1 [ true, %11 ], [ %20, %16 ]
br label %23
23: ; preds = %21, %1
%24 = phi i1 [ false, %1 ], [ %22, %21 ]
%25 = zext i1 %24 to i32
ret i32 %25
}

LLVM IR (-O2):
@EV_KEY = global i32 0
@EV_SW = global i32 0
define i32 @device_is_suitable(i32 %0) {
%2 = alloca [32 x i32]
%3 = bitcast [32 x i32]* %2 to i8*
%4 = tail call i32 @EVIOCGBIT(i32 0, i32 128)
%5 = getelementptr inbounds [32 x i32], [32 x i32]* %2, i64 0, i64 0
%6 = call i32 @ioctl(i32 %0, i32 %4, i32* %5)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = load i32, i32* @EV_KEY
%10 = call i64 @test_bit(i32 %9, i32* %5)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i32, i32* @EV_SW
%14 = call i64 @test_bit(i32 %13, i32* %5)
%15 = icmp ne i64 %14, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %8, %12, %1
%18 = phi i32 [ 0, %1 ], [ 1, %8 ], [ %16, %12 ]
ret i32 %18
}