#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 EINVAL 130
#define ENOENT 129
#define EPERM 128
int EX_NOPERM;
int EX_UNAVAILABLE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int handle_get_next_errno(int eno) {
  switch (eno) {
  case ENOENT:
    return 0;
  case EINVAL:
    fprintf(stderr, "Kernel does not support BPF introspection\n");
    return EX_UNAVAILABLE;
  case EPERM:
    fprintf(stderr,
            "Require CAP_SYS_ADMIN capability.  Please retry as root\n");
    return EX_NOPERM;
  default:
    fprintf(stderr, "%s\n", strerror(errno));
    return 1;
  }
}


x86 assembly (clang, -O0):
<handle_get_next_errno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0x80,%eax
je     119b <handle_get_next_errno+0x7b>
jmp    1141 <handle_get_next_errno+0x21>
mov    -0xc(%rbp),%eax
sub    $0x81,%eax
je     1167 <handle_get_next_errno+0x47>
jmp    1154 <handle_get_next_errno+0x34>
mov    -0xc(%rbp),%eax
sub    $0x82,%eax
je     1173 <handle_get_next_errno+0x53>
jmp    11c3 <handle_get_next_errno+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    11f8 <handle_get_next_errno+0xd8>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f8 <handle_get_next_errno+0xd8>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    11f8 <handle_get_next_errno+0xd8>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe7a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_get_next_errno>:
push   %rbx
cmp    $0x80,%edi
je     1159 <handle_get_next_errno+0x39>
cmp    $0x81,%edi
je     117b <handle_get_next_errno+0x5b>
mov    0x2ea0(%rip),%rax
cmp    $0x82,%edi
jne    117f <handle_get_next_errno+0x5f>
mov    (%rax),%edi
lea    0xeb7(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e71(%rip),%rax
jmp    1177 <handle_get_next_errno+0x57>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
lea    0xec2(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret
mov    (%rax),%ebx
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
lea    0xece(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"Kernel does not support BPF introspection\0A\00"
@EX_UNAVAILABLE = global i32 0
@.str.1 = [57 x i8] c"Require CAP_SYS_ADMIN capability. Please retry as root\0A\00"
@EX_NOPERM = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
define i32 @handle_get_next_errno(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %14 [
i32 129, label %5
i32 130, label %6
i32 128, label %10
]
5: ; preds = %1
store i32 0, i32* %2
br label %19
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EX_UNAVAILABLE
store i32 %9, i32* %2
br label %19
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EX_NOPERM
store i32 %13, i32* %2
br label %19
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = load i32, i32* @errno
%17 = call i8* @strerror(i32 %16)
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %17)
store i32 1, i32* %2
br label %19
19: ; preds = %14, %10, %6, %5
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"Kernel does not support BPF introspection\0A\00"
@EX_UNAVAILABLE = global i32 0
@.str.1 = [57 x i8] c"Require CAP_SYS_ADMIN capability. Please retry as root\0A\00"
@EX_NOPERM = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@errno = global i32 0
define i32 @handle_get_next_errno(i32 %0) {
switch i32 %0, label %10 [
i32 129, label %15
i32 130, label %2
i32 128, label %6
]
2: ; preds = %1
%3 = load i32, i32* @stderr
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @EX_UNAVAILABLE
br label %15
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0))
%9 = load i32, i32* @EX_NOPERM
br label %15
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %1, %10, %6, %2
%16 = phi i32 [ 1, %10 ], [ %9, %6 ], [ %5, %2 ], [ 0, %1 ]
ret i32 %16
}