#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 EACCES 146
#define EBADF 145
#define ECHILD 144
#define EEXIST 143
#define EFAULT 142
#define EINVAL 141
#define EIO 140
#define EMFILE 139
#define ENAMETOOLONG 138
#define ENFILE 137
#define ENODEV 136
#define ENOENT 135
#define ENOEXEC 134
#define ENOMEM 133
#define ENOSPC 132
#define ENOTDIR 131
#define ENXIO 130
#define EPERM 129
#define EXDEV 128
int unix2toserrno(int unixerrno, int defaulttoserrno) {
  int retval = defaulttoserrno;
  switch (unixerrno) {
  case EACCES:
  case EPERM:
  case ENFILE:
    retval = -36;
    break;
  case EBADF:
    retval = -37;
    break;
  case ENOTDIR:
    retval = -34;
    break;
  case ENOENT:
  case ECHILD:
    retval = -33;
    break;
  case ENXIO:
    retval = -46;
    break;
  case EIO:
    retval = -90;
    break;
  case ENOEXEC:
    retval = -66;
    break;
  case ENOMEM:
    retval = -39;
    break;
  case EFAULT:
    retval = -40;
    break;
  case EEXIST:
    retval = -85;
    break;
  case EXDEV:
    retval = -48;
    break;
  case ENODEV:
    retval = -15;
    break;
  case EINVAL:
    retval = -32;
    break;
  case EMFILE:
    retval = -35;
    break;
  case ENOSPC:
    retval = -91;
    break;
  case ENAMETOOLONG:
    retval = -64;
    break;
  }
  return retval;
}


x86 assembly (clang, -O0):
<unix2toserrno>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x12,%eax
ja     11f4 <unix2toserrno+0xf4>
mov    -0x18(%rbp),%rax
lea    0xed0(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0xffffffdc,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffdb,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffde,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffdf,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffd2,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffa6,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffbe,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffd9,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffd8,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffab,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffd0,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xfffffff1,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffe0,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffdd,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffa5,-0xc(%rbp)
jmp    11f4 <unix2toserrno+0xf4>
movl   $0xffffffc0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<unix2toserrno>:
mov    %esi,%eax
add    $0xffffff80,%edi
cmp    $0x12,%edi
ja     1117 <unix2toserrno+0x17>
movslq %edi,%rax
lea    0xeec(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret

LLVM IR (-O0):
define i32 @unix2toserrno(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
store i32 %6, i32* %5
%7 = load i32, i32* %3
switch i32 %7, label %24 [
i32 146, label %8
i32 129, label %8
i32 137, label %8
i32 145, label %9
i32 131, label %10
i32 135, label %11
i32 144, label %11
i32 130, label %12
i32 140, label %13
i32 134, label %14
i32 133, label %15
i32 142, label %16
i32 143, label %17
i32 128, label %18
i32 136, label %19
i32 141, label %20
i32 139, label %21
i32 132, label %22
i32 138, label %23
]
8: ; preds = %2, %2, %2
store i32 -36, i32* %5
br label %24
9: ; preds = %2
store i32 -37, i32* %5
br label %24
10: ; preds = %2
store i32 -34, i32* %5
br label %24
11: ; preds = %2, %2
store i32 -33, i32* %5
br label %24
12: ; preds = %2
store i32 -46, i32* %5
br label %24
13: ; preds = %2
store i32 -90, i32* %5
br label %24
14: ; preds = %2
store i32 -66, i32* %5
br label %24
15: ; preds = %2
store i32 -39, i32* %5
br label %24
16: ; preds = %2
store i32 -40, i32* %5
br label %24
17: ; preds = %2
store i32 -85, i32* %5
br label %24
18: ; preds = %2
store i32 -48, i32* %5
br label %24
19: ; preds = %2
store i32 -15, i32* %5
br label %24
20: ; preds = %2
store i32 -32, i32* %5
br label %24
21: ; preds = %2
store i32 -35, i32* %5
br label %24
22: ; preds = %2
store i32 -91, i32* %5
br label %24
23: ; preds = %2
store i32 -64, i32* %5
br label %24
24: ; preds = %2, %23, %22, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
@switch.table.unix2toserrno = [19 x i32] [i32 -48, i32 -36, i32 -46, i32 -34, i32 -91, i32 -39, i32 -66, i32 -33, i32 -15, i32 -36, i32 -64, i32 -35, i32 -90, i32 -32, i32 -40, i32 -85, i32 -33, i32 -37, i32 -36]
define i32 @unix2toserrno(i32 %0, i32 %1) {
%3 = add i32 %0, -128
%4 = icmp ult i32 %3, 19
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds [19 x i32], [19 x i32]* @switch.table.unix2toserrno, i64 0, i64 %6
%8 = load i32, i32* %7
br label %9
9: ; preds = %5, %2
%10 = phi i32 [ %1, %2 ], [ %8, %5 ]
ret i32 %10
}