#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 */
unsigned long _IOC_DIR(unsigned long);
unsigned long _IOC_NR(unsigned long);
unsigned long _IOC_SIZE(unsigned long);
scalar_t__ _IOC_TYPE(unsigned long);
int /*<<< orphan*/ printf(char *, unsigned long, unsigned long, ...);
void decode_ioctl(unsigned long code) {
  printf("code: %ld 0x%08lx\n", code, code);
  printf("DIR:  %ld 0x%08lx\n", _IOC_DIR(code), _IOC_DIR(code));
  printf("TYPE: %ld 0x%08lx '%c'\n", _IOC_TYPE(code), _IOC_TYPE(code),
         (char)_IOC_TYPE(code));
  printf("NR:   %ld 0x%08lx\n", _IOC_NR(code), _IOC_NR(code));
  printf("SIZE: %ld 0x%08lx\n", _IOC_SIZE(code), _IOC_SIZE(code));
}


x86 assembly (clang, -O0):
<decode_ioctl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x8(%rbp),%rdx
lea    0xe95(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <_IOC_DIR@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <_IOC_DIR@plt>
mov    -0x30(%rbp),%rsi
mov    %rax,%rdx
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <_IOC_TYPE@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <_IOC_TYPE@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <_IOC_TYPE@plt>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
movsbl %al,%ecx
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1060 <_IOC_NR@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <_IOC_NR@plt>
mov    -0x18(%rbp),%rsi
mov    %rax,%rdx
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1050 <_IOC_SIZE@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <_IOC_SIZE@plt>
mov    -0x10(%rbp),%rsi
mov    %rax,%rdx
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<decode_ioctl>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xea1(%rip),%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1070 <_IOC_DIR@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1070 <_IOC_DIR@plt>
lea    0xe8d(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1040 <_IOC_TYPE@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <_IOC_TYPE@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <_IOC_TYPE@plt>
movsbl %al,%ecx
lea    0xe6b(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1060 <_IOC_NR@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1060 <_IOC_NR@plt>
lea    0xe5c(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
call   1050 <_IOC_SIZE@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <_IOC_SIZE@plt>
lea    0xe48(%rip),%rdi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"code: %ld 0x%08lx\0A\00"
@.str.1 = [19 x i8] c"DIR: %ld 0x%08lx\0A\00"
@.str.2 = [24 x i8] c"TYPE: %ld 0x%08lx '%c'\0A\00"
@.str.3 = [19 x i8] c"NR: %ld 0x%08lx\0A\00"
@.str.4 = [19 x i8] c"SIZE: %ld 0x%08lx\0A\00"
define void @decode_ioctl(i64 %0) {
%2 = alloca i64
store i64 %0, i64* %2
%3 = load i64, i64* %2
%4 = load i64, i64* %2
%5 = call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %3, i64 %4)
%6 = load i64, i64* %2
%7 = call i64 @_IOC_DIR(i64 %6)
%8 = load i64, i64* %2
%9 = call i64 @_IOC_DIR(i64 %8)
%10 = call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i64 %7, i64 %9)
%11 = load i64, i64* %2
%12 = call i64 @_IOC_TYPE(i64 %11)
%13 = load i64, i64* %2
%14 = call i64 @_IOC_TYPE(i64 %13)
%15 = load i64, i64* %2
%16 = call i64 @_IOC_TYPE(i64 %15)
%17 = trunc i64 %16 to i8
%18 = sext i8 %17 to i32
%19 = call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i64 %12, i64 %14, i32 %18)
%20 = load i64, i64* %2
%21 = call i64 @_IOC_NR(i64 %20)
%22 = load i64, i64* %2
%23 = call i64 @_IOC_NR(i64 %22)
%24 = call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %21, i64 %23)
%25 = load i64, i64* %2
%26 = call i64 @_IOC_SIZE(i64 %25)
%27 = load i64, i64* %2
%28 = call i64 @_IOC_SIZE(i64 %27)
%29 = call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i64 %26, i64 %28)
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"code: %ld 0x%08lx\0A\00"
@.str.1 = [19 x i8] c"DIR: %ld 0x%08lx\0A\00"
@.str.2 = [24 x i8] c"TYPE: %ld 0x%08lx '%c'\0A\00"
@.str.3 = [19 x i8] c"NR: %ld 0x%08lx\0A\00"
@.str.4 = [19 x i8] c"SIZE: %ld 0x%08lx\0A\00"
define void @decode_ioctl(i64 %0) {
%2 = tail call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i64 %0, i64 %0)
%3 = tail call i64 @_IOC_DIR(i64 %0)
%4 = tail call i64 @_IOC_DIR(i64 %0)
%5 = tail call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i64 %3, i64 %4)
%6 = tail call i64 @_IOC_TYPE(i64 %0)
%7 = tail call i64 @_IOC_TYPE(i64 %0)
%8 = tail call i64 @_IOC_TYPE(i64 %0)
%9 = trunc i64 %8 to i32
%10 = shl i32 %9, 24
%11 = ashr exact i32 %10, 24
%12 = tail call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i64 %6, i64 %7, i32 %11)
%13 = tail call i64 @_IOC_NR(i64 %0)
%14 = tail call i64 @_IOC_NR(i64 %0)
%15 = tail call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i64 %13, i64 %14)
%16 = tail call i64 @_IOC_SIZE(i64 %0)
%17 = tail call i64 @_IOC_SIZE(i64 %0)
%18 = tail call i32 (i8*, i64, i64, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i64 %16, i64 %17)
ret void
}