#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 */
#define EBADF 131
#define EFAULT 130
#define EINVAL 129
#define ENOTTY 128
int errno;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
char *strerror(int);
void print_ioctl_error(void) {
  switch (errno) {
  case EBADF:
    printf("Not a valid descriptor.");
    break;
  case EFAULT:
    printf("Argp is referencing inacessible memory area.");
    break;
  case EINVAL:
    printf("Request or argp is not valid.");
    break;
  case ENOTTY:
    printf("Request not available on this device.");
    break;
  default:
    printf("%s", strerror(errno));
    break;
  }
  fflush(stdout);
}


x86 assembly (clang, -O0):
<print_ioctl_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x8(%rbp)
sub    $0x3,%eax
ja     11b3 <print_ioctl_error+0x83>
mov    -0x8(%rbp),%rax
lea    0xea2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d2 <print_ioctl_error+0xa2>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d2 <print_ioctl_error+0xa2>
lea    0xec1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d2 <print_ioctl_error+0xa2>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11d2 <print_ioctl_error+0xa2>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xece(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_ioctl_error>:
push   %rax
mov    0x2ea8(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rdi),%eax
cmp    $0x3,%eax
ja     115b <print_ioctl_error+0x2b>
lea    0xeb7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf1a(%rip),%rdi
jmp    118c <print_ioctl_error+0x5c>
call   1050 <strerror@plt>
lea    0xf32(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1193 <print_ioctl_error+0x63>
lea    0xedb(%rip),%rdi
jmp    118c <print_ioctl_error+0x5c>
lea    0xea5(%rip),%rdi
jmp    118c <print_ioctl_error+0x5c>
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
pop    %rax
jmp    1040 <fflush@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [24 x i8] c"Not a valid descriptor.\00"
@.str.1 = [45 x i8] c"Argp is referencing inacessible memory area.\00"
@.str.2 = [30 x i8] c"Request or argp is not valid.\00"
@.str.3 = [38 x i8] c"Request not available on this device.\00"
@.str.4 = [3 x i8] c"%s\00"
@stdout = global i32 0
define void @print_ioctl_error() {
%1 = load i32, i32* @errno
switch i32 %1, label %10 [
i32 131, label %2
i32 130, label %4
i32 129, label %6
i32 128, label %8
]
2: ; preds = %0
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %14
4: ; preds = %0
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %14
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %14
8: ; preds = %0
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %14
10: ; preds = %0
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %10, %8, %6, %4, %2
%15 = load i32, i32* @stdout
%16 = call i32 @fflush(i32 %15)
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [24 x i8] c"Not a valid descriptor.\00"
@.str.1 = [45 x i8] c"Argp is referencing inacessible memory area.\00"
@.str.2 = [30 x i8] c"Request or argp is not valid.\00"
@.str.3 = [38 x i8] c"Request not available on this device.\00"
@.str.4 = [3 x i8] c"%s\00"
@stdout = global i32 0
define void @print_ioctl_error() {
%1 = load i32, i32* @errno
switch i32 %1, label %10 [
i32 131, label %2
i32 130, label %4
i32 129, label %6
i32 128, label %8
]
2: ; preds = %0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %13
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %13
6: ; preds = %0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %13
8: ; preds = %0
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %13
10: ; preds = %0
%11 = tail call i8* @strerror(i32 %1)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %11)
br label %13
13: ; preds = %10, %8, %6, %4, %2
%14 = load i32, i32* @stdout
%15 = tail call i32 @fflush(i32 %14)
ret void
}