#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 _IOC_DIR(unsigned int);
int _IOC_NR(unsigned int);
int _IOC_READ;
int /*<<< orphan*/ _IOC_SIZE(unsigned int);
int _IOC_WRITE;
int /*<<< orphan*/ tprintf(char *, int /*<<< orphan*/);
int hiddev_decode_number(unsigned int arg) {
  if (_IOC_DIR(arg) == _IOC_READ) {
    switch (_IOC_NR(arg)) {
    case 0x04:
      tprintf("HIDIOCGRAWNAME(%u)", _IOC_SIZE(arg));
      return 1;
    case 0x05:
      tprintf("HIDIOCGRAWPHYS(%u)", _IOC_SIZE(arg));
      return 1;
    case 0x06:
      tprintf("HIDIOCSFEATURE(%u)", _IOC_SIZE(arg));
      return 1;
    case 0x12:
      tprintf("HIDIOCGPHYS(%u)", _IOC_SIZE(arg));
      return 1;
    default:
      return 0;
    }
  } else if (_IOC_DIR(arg) == (_IOC_READ | _IOC_WRITE)) {
    switch (_IOC_NR(arg)) {
    case 0x06:
      tprintf("HIDIOCSFEATURE(%u)", _IOC_SIZE(arg));
      return 1;
    case 0x07:
      tprintf("HIDIOCGFEATURE(%u)", _IOC_SIZE(arg));
      return 1;
    default:
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<hiddev_decode_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1060 <_IOC_DIR@plt>
mov    0x2e86(%rip),%rcx
cmp    (%rcx),%eax
jne    1224 <hiddev_decode_number+0xe4>
mov    -0x8(%rbp),%edi
call   1050 <_IOC_NR@plt>
add    $0xfffffffc,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0xe,%eax
ja     1218 <hiddev_decode_number+0xd8>
mov    -0x10(%rbp),%rax
lea    0xe79(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%edi
call   1030 <_IOC_SIZE@plt>
mov    %eax,%esi
lea    0xe9b(%rip),%rdi
call   1040 <tprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ce <hiddev_decode_number+0x18e>
mov    -0x8(%rbp),%edi
call   1030 <_IOC_SIZE@plt>
mov    %eax,%esi
lea    0xe8c(%rip),%rdi
call   1040 <tprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ce <hiddev_decode_number+0x18e>
mov    -0x8(%rbp),%edi
call   1030 <_IOC_SIZE@plt>
mov    %eax,%esi
lea    0xe7d(%rip),%rdi
call   1040 <tprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ce <hiddev_decode_number+0x18e>
mov    -0x8(%rbp),%edi
call   1030 <_IOC_SIZE@plt>
mov    %eax,%esi
lea    0xe6e(%rip),%rdi
call   1040 <tprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ce <hiddev_decode_number+0x18e>
movl   $0x0,-0x4(%rbp)
jmp    12ce <hiddev_decode_number+0x18e>
mov    -0x8(%rbp),%edi
call   1060 <_IOC_DIR@plt>
mov    0x2dad(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2d94(%rip),%rdx
or     (%rdx),%ecx
cmp    %ecx,%eax
jne    12c2 <hiddev_decode_number+0x182>
mov    -0x8(%rbp),%edi
call   1050 <_IOC_NR@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0x6,%eax
je     1272 <hiddev_decode_number+0x132>
jmp    1261 <hiddev_decode_number+0x121>
mov    -0x14(%rbp),%eax
sub    $0x7,%eax
je     1294 <hiddev_decode_number+0x154>
jmp    12b6 <hiddev_decode_number+0x176>
mov    -0x8(%rbp),%edi
call   1030 <_IOC_SIZE@plt>
mov    %eax,%esi
lea    0xddf(%rip),%rdi
call   1040 <tprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ce <hiddev_decode_number+0x18e>
mov    -0x8(%rbp),%edi
call   1030 <_IOC_SIZE@plt>
mov    %eax,%esi
lea    0xde0(%rip),%rdi
call   1040 <tprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12ce <hiddev_decode_number+0x18e>
movl   $0x0,-0x4(%rbp)
jmp    12ce <hiddev_decode_number+0x18e>
jmp    12c7 <hiddev_decode_number+0x187>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hiddev_decode_number>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
call   1060 <_IOC_DIR@plt>
mov    0x2e8e(%rip),%rbp
cmp    0x0(%rbp),%eax
jne    1188 <hiddev_decode_number+0x48>
mov    %ebx,%edi
call   1050 <_IOC_NR@plt>
xor    %ebp,%ebp
add    $0xfffffffc,%eax
cmp    $0xe,%eax
ja     11e1 <hiddev_decode_number+0xa1>
lea    0xecd(%rip),%r14
lea    0xe8a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xec9(%rip),%r14
jmp    11cb <hiddev_decode_number+0x8b>
mov    %ebx,%edi
call   1060 <_IOC_DIR@plt>
mov    0x2e3a(%rip),%rcx
mov    (%rcx),%ecx
or     0x0(%rbp),%ecx
xor    %ebp,%ebp
cmp    %ecx,%eax
jne    11e1 <hiddev_decode_number+0xa1>
mov    %ebx,%edi
call   1050 <_IOC_NR@plt>
cmp    $0x6,%eax
je     11bb <hiddev_decode_number+0x7b>
cmp    $0x7,%eax
jne    11e1 <hiddev_decode_number+0xa1>
lea    0xecc(%rip),%r14
jmp    11cb <hiddev_decode_number+0x8b>
lea    0xea0(%rip),%r14
jmp    11cb <hiddev_decode_number+0x8b>
lea    0xeaa(%rip),%r14
mov    %ebx,%edi
call   1030 <_IOC_SIZE@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <tprintf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@_IOC_READ = global i32 0
@.str = [19 x i8] c"HIDIOCGRAWNAME(%u)\00"
@.str.1 = [19 x i8] c"HIDIOCGRAWPHYS(%u)\00"
@.str.2 = [19 x i8] c"HIDIOCSFEATURE(%u)\00"
@.str.3 = [16 x i8] c"HIDIOCGPHYS(%u)\00"
@_IOC_WRITE = global i32 0
@.str.4 = [19 x i8] c"HIDIOCGFEATURE(%u)\00"
define i32 @hiddev_decode_number(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = call i32 @_IOC_DIR(i32 %4)
%6 = load i32, i32* @_IOC_READ
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %28
8: ; preds = %1
%9 = load i32, i32* %3
%10 = call i32 @_IOC_NR(i32 %9)
switch i32 %10, label %27 [
i32 4, label %11
i32 5, label %15
i32 6, label %19
i32 18, label %23
]
11: ; preds = %8
%12 = load i32, i32* %3
%13 = call i32 @_IOC_SIZE(i32 %12)
%14 = call i32 @tprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 1, i32* %2
br label %49
15: ; preds = %8
%16 = load i32, i32* %3
%17 = call i32 @_IOC_SIZE(i32 %16)
%18 = call i32 @tprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %17)
store i32 1, i32* %2
br label %49
19: ; preds = %8
%20 = load i32, i32* %3
%21 = call i32 @_IOC_SIZE(i32 %20)
%22 = call i32 @tprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %21)
store i32 1, i32* %2
br label %49
23: ; preds = %8
%24 = load i32, i32* %3
%25 = call i32 @_IOC_SIZE(i32 %24)
%26 = call i32 @tprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 %25)
store i32 1, i32* %2
br label %49
27: ; preds = %8
store i32 0, i32* %2
br label %49
28: ; preds = %1
%29 = load i32, i32* %3
%30 = call i32 @_IOC_DIR(i32 %29)
%31 = load i32, i32* @_IOC_READ
%32 = load i32, i32* @_IOC_WRITE
%33 = or i32 %31, %32
%34 = icmp eq i32 %30, %33
br i1 %34, label %35, label %47
35: ; preds = %28
%36 = load i32, i32* %3
%37 = call i32 @_IOC_NR(i32 %36)
switch i32 %37, label %46 [
i32 6, label %38
i32 7, label %42
]
38: ; preds = %35
%39 = load i32, i32* %3
%40 = call i32 @_IOC_SIZE(i32 %39)
%41 = call i32 @tprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %40)
store i32 1, i32* %2
br label %49
42: ; preds = %35
%43 = load i32, i32* %3
%44 = call i32 @_IOC_SIZE(i32 %43)
%45 = call i32 @tprintf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %44)
store i32 1, i32* %2
br label %49
46: ; preds = %35
store i32 0, i32* %2
br label %49
47: ; preds = %28
br label %48
48: ; preds = %47
store i32 0, i32* %2
br label %49
49: ; preds = %48, %46, %42, %38, %27, %23, %19, %15, %11
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
@_IOC_READ = global i32 0
@.str = [19 x i8] c"HIDIOCGRAWNAME(%u)\00"
@.str.1 = [19 x i8] c"HIDIOCGRAWPHYS(%u)\00"
@.str.2 = [19 x i8] c"HIDIOCSFEATURE(%u)\00"
@.str.3 = [16 x i8] c"HIDIOCGPHYS(%u)\00"
@_IOC_WRITE = global i32 0
@.str.4 = [19 x i8] c"HIDIOCGFEATURE(%u)\00"
define i32 @hiddev_decode_number(i32 %0) {
%2 = tail call i32 @_IOC_DIR(i32 %0)
%3 = load i32, i32* @_IOC_READ
%4 = icmp eq i32 %2, %3
br i1 %4, label %5, label %10
5: ; preds = %1
%6 = tail call i32 @_IOC_NR(i32 %0)
switch i32 %6, label %23 [
i32 4, label %19
i32 5, label %7
i32 6, label %8
i32 18, label %9
]
7: ; preds = %5
br label %19
8: ; preds = %5
br label %19
9: ; preds = %5
br label %19
10: ; preds = %1
%11 = tail call i32 @_IOC_DIR(i32 %0)
%12 = load i32, i32* @_IOC_READ
%13 = load i32, i32* @_IOC_WRITE
%14 = or i32 %13, %12
%15 = icmp eq i32 %11, %14
br i1 %15, label %16, label %23
16: ; preds = %10
%17 = tail call i32 @_IOC_NR(i32 %0)
switch i32 %17, label %23 [
i32 6, label %19
i32 7, label %18
]
18: ; preds = %16
br label %19
19: ; preds = %16, %5, %7, %8, %9, %18
%20 = phi i8* [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), %18 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), %9 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), %16 ]
%21 = tail call i32 @_IOC_SIZE(i32 %0)
%22 = tail call i32 @tprintf(i8* %20, i32 %21)
br label %23
23: ; preds = %19, %10, %16, %5
%24 = phi i32 [ 0, %5 ], [ 0, %16 ], [ 0, %10 ], [ 1, %19 ]
ret i32 %24
}