#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 EAGAIN 141
#define EBADF 140
#define ECONNABORTED 139
#define EFAULT 138
#define EINTR 137
#define EINVAL 136
#define EMFILE 135
#define ENFILE 134
#define ENOBUFS 133
#define ENOMEM 132
#define ENOTSOCK 131
#define EOPNOTSUPP 130
#define EPERM 129
#define EPROTO 128
int errno;
int /*<<< orphan*/ printf(char *);
void display_errno(int num) {
  switch (errno) {
  case EAGAIN:
    printf("errno: EAGAIN\n");
    break;
  case EBADF:
    printf("errno: EBADF\n");
    break;
  case ECONNABORTED:
    printf("errno: ECONNABORTED\n");
    break;
  case EINTR:
    printf("errno: EINTR\n");
    break;
  case EINVAL:
    printf("errno: EINVAL\n");
    break;
  case EMFILE:
    printf("errno: EMFILE\n");
    break;
  case ENFILE:
    printf("errno: ENFILE\n");
    break;
  case ENOTSOCK:
    printf("errno: ENOTSOCK\n");
    break;
  case EOPNOTSUPP:
    printf("errno: EOPNOTSUPP\n");
    break;
  case EFAULT:
    printf("errno: EFAULT\n");
    break;
  case ENOBUFS:
    printf("errno: ENOBUFS\n");
    break;
  case ENOMEM:
    printf("errno: ENOMEM\n");
    break;
  case EPROTO:
    printf("errno: EPROTO\n");
    break;
  case EPERM:
    printf("errno: EPERM\n");
    break;
  default:
    printf("errno: Unknown\n");
  }
}


x86 assembly (clang, -O0):
<display_errno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ebe(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0xd,%eax
ja     1238 <display_errno+0x128>
mov    -0x10(%rbp),%rax
lea    0xebf(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xee7(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xee5(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xee2(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xee6(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xee3(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xee1(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xedf(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xedd(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xedd(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xedf(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xedd(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xedc(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xeda(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xed8(%rip),%rdi
call   1030 <printf@plt>
jmp    1244 <display_errno+0x134>
lea    0xed5(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_errno>:
mov    0x2ec9(%rip),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
cmp    $0xd,%eax
ja     1136 <display_errno+0x26>
cltq
lea    0xfb6(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
jmp    1030 <puts@plt>
lea    0xf91(%rip),%rdi
jmp    1030 <puts@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [15 x i8] c"errno: EAGAIN\0A\00"
@.str.1 = [14 x i8] c"errno: EBADF\0A\00"
@.str.2 = [21 x i8] c"errno: ECONNABORTED\0A\00"
@.str.3 = [14 x i8] c"errno: EINTR\0A\00"
@.str.4 = [15 x i8] c"errno: EINVAL\0A\00"
@.str.5 = [15 x i8] c"errno: EMFILE\0A\00"
@.str.6 = [15 x i8] c"errno: ENFILE\0A\00"
@.str.7 = [17 x i8] c"errno: ENOTSOCK\0A\00"
@.str.8 = [19 x i8] c"errno: EOPNOTSUPP\0A\00"
@.str.9 = [15 x i8] c"errno: EFAULT\0A\00"
@.str.10 = [16 x i8] c"errno: ENOBUFS\0A\00"
@.str.11 = [15 x i8] c"errno: ENOMEM\0A\00"
@.str.12 = [15 x i8] c"errno: EPROTO\0A\00"
@.str.13 = [14 x i8] c"errno: EPERM\0A\00"
@.str.14 = [16 x i8] c"errno: Unknown\0A\00"
define void @display_errno(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @errno
switch i32 %3, label %32 [
i32 141, label %4
i32 140, label %6
i32 139, label %8
i32 137, label %10
i32 136, label %12
i32 135, label %14
i32 134, label %16
i32 131, label %18
i32 130, label %20
i32 138, label %22
i32 133, label %24
i32 132, label %26
i32 128, label %28
i32 129, label %30
]
4: ; preds = %1
%5 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %34
6: ; preds = %1
%7 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %34
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %34
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %34
12: ; preds = %1
%13 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %34
14: ; preds = %1
%15 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
br label %34
16: ; preds = %1
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %34
18: ; preds = %1
%19 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
br label %34
20: ; preds = %1
%21 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
br label %34
22: ; preds = %1
%23 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
br label %34
24: ; preds = %1
%25 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %34
26: ; preds = %1
%27 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %34
28: ; preds = %1
%29 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0))
br label %34
30: ; preds = %1
%31 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0))
br label %34
32: ; preds = %1
%33 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.14, i64 0, i64 0))
br label %34
34: ; preds = %32, %30, %28, %26, %24, %22, %20, %18, %16, %14, %12, %10, %8, %6, %4
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@str = [13 x i8] c"errno: EPERM\00"
@str.15 = [14 x i8] c"errno: EPROTO\00"
@str.16 = [14 x i8] c"errno: ENOMEM\00"
@str.17 = [15 x i8] c"errno: ENOBUFS\00"
@str.18 = [14 x i8] c"errno: EFAULT\00"
@str.19 = [18 x i8] c"errno: EOPNOTSUPP\00"
@str.20 = [16 x i8] c"errno: ENOTSOCK\00"
@str.21 = [14 x i8] c"errno: ENFILE\00"
@str.22 = [14 x i8] c"errno: EMFILE\00"
@str.23 = [14 x i8] c"errno: EINVAL\00"
@str.24 = [13 x i8] c"errno: EINTR\00"
@str.25 = [20 x i8] c"errno: ECONNABORTED\00"
@str.26 = [13 x i8] c"errno: EBADF\00"
@str.27 = [14 x i8] c"errno: EAGAIN\00"
@str.28 = [15 x i8] c"errno: Unknown\00"
@reltable.display_errno = [14 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.15 to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @str.19 to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([16 x i8]* @str.20 to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.16 to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([15 x i8]* @str.17 to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.21 to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.22 to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.23 to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str.24 to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.18 to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @str.25 to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @str.26 to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @str.27 to i64), i64 ptrtoint ([14 x i32]* @reltable.display_errno to i64)) to i32)]
define void @display_errno(i32 %0) {
%2 = load i32, i32* @errno
%3 = add i32 %2, -128
%4 = icmp ult i32 %3, 14
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = sext i32 %3 to i64
%7 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([14 x i32]* @reltable.display_errno to i8*), i64 %7)
br label %9
9: ; preds = %1, %5
%10 = phi i8* [ %8, %5 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.28, i64 0, i64 0), %1 ]
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
ret void
}