#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*/ unk_bitmask;

/* Variables and functions */
int /*<<< orphan*/ EVIOCGBIT(unsigned int, int);
scalar_t__ event_test_bit(unsigned int, unsigned char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, unsigned char *);
int /*<<< orphan*/ log_f(char *, ...);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
void event_unknown_log(int f, unsigned e) {
  unsigned char unk_bitmask[256 / 8];
  unsigned i;
  memset(unk_bitmask, 0, sizeof(unk_bitmask));
  if (ioctl(f, EVIOCGBIT(e, sizeof(unk_bitmask)), unk_bitmask) < 0) {
    log_f("event: error in ioctl(EVIOCGBIT(0x%x,%d))\n", e, (int)256);
    return;
  }
  log_f("event: EV_0x%x:", e);
  for (i = 0; i < 256; ++i) {
    if (event_test_bit(i, unk_bitmask)) {
      log_f(" 0x%x", i);
    }
  }
  log_f("\n");
}


x86 assembly (clang, -O0):
<event_unknown_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x20,%esi
call   1040 <EVIOCGBIT@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%esi
lea    -0x30(%rbp),%rdx
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    11b4 <event_unknown_log+0x64>
mov    -0x8(%rbp),%esi
lea    0xe5d(%rip),%rdi
mov    $0x100,%edx
mov    $0x0,%al
call   1050 <log_f@plt>
jmp    1221 <event_unknown_log+0xd1>
mov    -0x8(%rbp),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1050 <log_f@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0x100,-0x34(%rbp)
jae    1213 <event_unknown_log+0xc3>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1030 <event_test_bit@plt>
cmp    $0x0,%rax
je     1200 <event_unknown_log+0xb0>
mov    -0x34(%rbp),%esi
lea    0xe42(%rip),%rdi
mov    $0x0,%al
call   1050 <log_f@plt>
jmp    1205 <event_unknown_log+0xb5>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11cc <event_unknown_log+0x7c>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <log_f@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<event_unknown_log>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
mov    %ebx,%edi
mov    $0x20,%esi
call   1040 <EVIOCGBIT@plt>
mov    %ebp,%edi
mov    %eax,%esi
mov    %r14,%rdx
call   1070 <ioctl@plt>
test   %rax,%rax
js     11e8 <event_unknown_log+0x98>
lea    0xe99(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <log_f@plt>
mov    %rsp,%rbx
lea    0xe96(%rip),%r14
xor    %ebp,%ebp
jmp    11bb <event_unknown_log+0x6b>
nopl   0x0(%rax)
add    $0x1,%ebp
cmp    $0x100,%ebp
je     11d8 <event_unknown_log+0x88>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <event_test_bit@plt>
test   %rax,%rax
je     11b0 <event_unknown_log+0x60>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <log_f@plt>
jmp    11b0 <event_unknown_log+0x60>
lea    0xe4a(%rip),%rdi
xor    %eax,%eax
call   1050 <log_f@plt>
jmp    11fd <event_unknown_log+0xad>
lea    0xe11(%rip),%rdi
mov    %ebx,%esi
mov    $0x100,%edx
xor    %eax,%eax
call   1050 <log_f@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"event: error in ioctl(EVIOCGBIT(0x%x,%d))\0A\00"
@.str.1 = [16 x i8] c"event: EV_0x%x:\00"
@.str.2 = [6 x i8] c" 0x%x\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @event_unknown_log(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [32 x i8]
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 32)
%9 = load i32, i32* %3
%10 = load i32, i32* %4
%11 = call i32 @EVIOCGBIT(i32 %10, i32 32)
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%13 = call i64 @ioctl(i32 %9, i32 %11, i8* %12)
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = load i32, i32* %4
%17 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %16, i32 256)
br label %38
18: ; preds = %2
%19 = load i32, i32* %4
%20 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %19)
store i32 0, i32* %6
br label %21
21: ; preds = %33, %18
%22 = load i32, i32* %6
%23 = icmp ult i32 %22, 256
br i1 %23, label %24, label %36
24: ; preds = %21
%25 = load i32, i32* %6
%26 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%27 = call i64 @event_test_bit(i32 %25, i8* %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = load i32, i32* %6
%31 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %29, %24
br label %33
33: ; preds = %32
%34 = load i32, i32* %6
%35 = add i32 %34, 1
store i32 %35, i32* %6
br label %21
36: ; preds = %21
%37 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %15
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"event: error in ioctl(EVIOCGBIT(0x%x,%d))\0A\00"
@.str.1 = [16 x i8] c"event: EV_0x%x:\00"
@.str.2 = [6 x i8] c" 0x%x\00"
@.str.3 = [2 x i8] c"\0A\00"
define void @event_unknown_log(i32 %0, i32 %1) {
%3 = alloca [32 x i8]
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 32)
%6 = call i32 @EVIOCGBIT(i32 %1, i32 32)
%7 = call i64 @ioctl(i32 %0, i32 %6, i8* %4)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %1, i32 256)
br label %24
11: ; preds = %2
%12 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %1)
br label %13
13: ; preds = %11, %19
%14 = phi i32 [ 0, %11 ], [ %20, %19 ]
%15 = call i64 @event_test_bit(i32 %14, i8* %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %14)
br label %19
19: ; preds = %13, %17
%20 = add nuw nsw i32 %14, 1
%21 = icmp eq i32 %20, 256
br i1 %21, label %22, label %13
22: ; preds = %19
%23 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %9
ret void
}