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

/* Variables and functions */
int /*<<< orphan*/ EVIOCGBIT(int /*<<< orphan*/, int);
int /*<<< orphan*/ EV_REL;
int REL_MAX;
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_rel_log(int f) {
  unsigned char rel_bitmask[REL_MAX / 8 + 1];
  unsigned i;
  memset(rel_bitmask, 0, sizeof(rel_bitmask));
  if (ioctl(f, EVIOCGBIT(EV_REL, sizeof(rel_bitmask)), rel_bitmask) < 0) {
    log_f("event: error in ioctl(EVIOCGBIT(EV_REL,%d))\n", (int)REL_MAX);
    return;
  }
  log_f("event: EV_REL:");
  for (i = 0; i < REL_MAX; ++i) {
    if (event_test_bit(i, rel_bitmask)) {
      const char *desc;
      switch (i) {
      default:
        desc = 0;
        break;
      }
      if (desc)
        log_f(" %s", desc);
      else
        log_f(" 0x%x", i);
    }
  }
  log_f("\n");
}


x86 assembly (clang, -O0):
<event_rel_log>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
add    $0x7,%ecx
test   %eax,%eax
cmovs  %ecx,%eax
sar    $0x3,%eax
add    $0x1,%eax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x40(%rbp),%rax
mov    -0x4(%rbp),%ecx
mov    %ecx,-0x34(%rbp)
mov    0x2e33(%rip),%rcx
mov    (%rcx),%edi
mov    %eax,%esi
call   1040 <EVIOCGBIT@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rdx
mov    %eax,%esi
call   1070 <ioctl@plt>
cmp    $0x0,%rax
jge    11f9 <event_rel_log+0xa9>
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1050 <log_f@plt>
movl   $0x1,-0x20(%rbp)
jmp    129e <event_rel_log+0x14e>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1050 <log_f@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2dc8(%rip),%rcx
cmp    (%rcx),%eax
jae    1289 <event_rel_log+0x139>
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edi
call   1030 <event_test_bit@plt>
cmp    $0x0,%rax
je     1276 <event_rel_log+0x126>
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1260 <event_rel_log+0x110>
mov    -0x28(%rbp),%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <log_f@plt>
jmp    1271 <event_rel_log+0x121>
mov    -0x1c(%rbp),%esi
lea    0xdd6(%rip),%rdi
mov    $0x0,%al
call   1050 <log_f@plt>
jmp    1276 <event_rel_log+0x126>
jmp    127b <event_rel_log+0x12b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    120e <event_rel_log+0xbe>
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1050 <log_f@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<event_rel_log>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
mov    0x2e78(%rip),%r13
mov    0x0(%r13),%eax
lea    0x7(%rax),%r15d
test   %eax,%eax
cmovns %eax,%r15d
sar    $0x3,%r15d
add    $0x1,%r15d
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    %r12,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1060 <memset@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
mov    %r15d,%esi
call   1040 <EVIOCGBIT@plt>
mov    %r14d,%edi
mov    %eax,%esi
mov    %r12,%rdx
call   1070 <ioctl@plt>
test   %rax,%rax
js     1216 <event_rel_log+0xc6>
lea    0xe67(%rip),%rdi
xor    %eax,%eax
call   1050 <log_f@plt>
cmpl   $0x0,0x0(%r13)
je     1206 <event_rel_log+0xb6>
lea    0xe61(%rip),%r14
xor    %ebx,%ebx
jmp    11e9 <event_rel_log+0x99>
nop
add    $0x1,%ebx
cmp    0x0(%r13),%ebx
jae    1206 <event_rel_log+0xb6>
mov    %ebx,%edi
mov    %r12,%rsi
call   1030 <event_test_bit@plt>
test   %rax,%rax
je     11e0 <event_rel_log+0x90>
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <log_f@plt>
jmp    11e0 <event_rel_log+0x90>
lea    0xe1e(%rip),%rdi
xor    %eax,%eax
call   1050 <log_f@plt>
jmp    1228 <event_rel_log+0xd8>
mov    0x0(%r13),%esi
lea    0xddf(%rip),%rdi
xor    %eax,%eax
call   1050 <log_f@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@REL_MAX = global i32 0
@EV_REL = global i32 0
@.str = [45 x i8] c"event: error in ioctl(EVIOCGBIT(EV_REL,%d))\0A\00"
@.str.1 = [15 x i8] c"event: EV_REL:\00"
@.str.2 = [4 x i8] c" %s\00"
@.str.3 = [6 x i8] c" 0x%x\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @event_rel_log(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %2
%8 = load i32, i32* @REL_MAX
%9 = sdiv i32 %8, 8
%10 = add nsw i32 %9, 1
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %3
%13 = alloca i8, i64 %11
store i64 %11, i64* %4
%14 = trunc i64 %11 to i32
%15 = call i32 @memset(i8* %13, i32 0, i32 %14)
%16 = load i32, i32* %2
%17 = load i32, i32* @EV_REL
%18 = trunc i64 %11 to i32
%19 = call i32 @EVIOCGBIT(i32 %17, i32 %18)
%20 = call i64 @ioctl(i32 %16, i32 %19, i8* %13)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %1
%23 = load i32, i32* @REL_MAX
%24 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %23)
store i32 1, i32* %6
br label %54
25: ; preds = %1
%26 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %27
27: ; preds = %49, %25
%28 = load i32, i32* %5
%29 = load i32, i32* @REL_MAX
%30 = icmp ult i32 %28, %29
br i1 %30, label %31, label %52
31: ; preds = %27
%32 = load i32, i32* %5
%33 = call i64 @event_test_bit(i32 %32, i8* %13)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %31
%36 = load i32, i32* %5
switch i32 %36, label %37 [
]
37: ; preds = %35
store i8* null, i8** %7
br label %38
38: ; preds = %37
%39 = load i8*, i8** %7
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load i8*, i8** %7
%43 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %42)
br label %47
44: ; preds = %38
%45 = load i32, i32* %5
%46 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %45)
br label %47
47: ; preds = %44, %41
br label %48
48: ; preds = %47, %31
br label %49
49: ; preds = %48
%50 = load i32, i32* %5
%51 = add i32 %50, 1
store i32 %51, i32* %5
br label %27
52: ; preds = %27
%53 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %54
54: ; preds = %52, %22
%55 = load i8*, i8** %3
%56 = load i32, i32* %6
switch i32 %56, label %58 [
i32 0, label %57
i32 1, label %57
]
57: ; preds = %54, %54
ret void
58: ; preds = %54
unreachable
}

LLVM IR (-O2):
@REL_MAX = global i32 0
@EV_REL = global i32 0
@.str = [45 x i8] c"event: error in ioctl(EVIOCGBIT(EV_REL,%d))\0A\00"
@.str.1 = [15 x i8] c"event: EV_REL:\00"
@.str.3 = [6 x i8] c" 0x%x\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @event_rel_log(i32 %0) {
%2 = load i32, i32* @REL_MAX
%3 = sdiv i32 %2, 8
%4 = add nsw i32 %3, 1
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = call i32 @memset(i8* %6, i32 0, i32 %4)
%8 = load i32, i32* @EV_REL
%9 = call i32 @EVIOCGBIT(i32 %8, i32 %4)
%10 = call i64 @ioctl(i32 %0, i32 %9, i8* %6)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* @REL_MAX
%14 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %13)
br label %31
15: ; preds = %1
%16 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%17 = load i32, i32* @REL_MAX
%18 = icmp eq i32 %17, 0
br i1 %18, label %29, label %19
19: ; preds = %15, %25
%20 = phi i32 [ %26, %25 ], [ 0, %15 ]
%21 = call i64 @event_test_bit(i32 %20, i8* %6)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %19
%24 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %20)
br label %25
25: ; preds = %19, %23
%26 = add nuw i32 %20, 1
%27 = load i32, i32* @REL_MAX
%28 = icmp ult i32 %26, %27
br i1 %28, label %19, label %29
29: ; preds = %25, %15
%30 = call i32 (i8*, ...) @log_f(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %31
31: ; preds = %29, %12
ret void
}