#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 144
#define EAGAIN 143
#define EBADF 142
#define EBUSY 141
#define EDEADLK 140
#define EINTR 139
#define EINVAL 138
#define EIO 137
#define ENODEV 136
#define ENOENT 135
#define ENOLCK 134
#define ENOSYS 133
#define ENOTCONN 132
#define ENXIO 131
#define EPERM 130
#define ESTALE 129
#define ETIMEDOUT 128
int unqliteErrorFromPosixError(int posixError, int unqliteIOErr) {
  switch (posixError) {
  case 0:
    return 0;
  case EAGAIN:
  case ETIMEDOUT:
  case EBUSY:
  case EINTR:
  case ENOLCK:
    return (-14);
  case EACCES:
    return (-14);
  case EPERM:
    return (-19);
  case EDEADLK:
    return (-2);
  case EIO:
  case EBADF:
  case EINVAL:
  case ENOTCONN:
  case ENODEV:
  case ENXIO:
  case ENOENT:
  case ESTALE:
  case ENOSYS:
  default:
    return unqliteIOErr;
  }
}


x86 assembly (clang, -O0):
<unqliteErrorFromPosixError>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x18(%rbp)
sub    $0x90,%rax
ja     1172 <unqliteErrorFromPosixError+0x72>
mov    -0x18(%rbp),%rax
lea    0xed8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x4(%rbp)
jmp    1178 <unqliteErrorFromPosixError+0x78>
movl   $0xfffffff2,-0x4(%rbp)
jmp    1178 <unqliteErrorFromPosixError+0x78>
movl   $0xfffffff2,-0x4(%rbp)
jmp    1178 <unqliteErrorFromPosixError+0x78>
movl   $0xffffffed,-0x4(%rbp)
jmp    1178 <unqliteErrorFromPosixError+0x78>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1178 <unqliteErrorFromPosixError+0x78>
jmp    1172 <unqliteErrorFromPosixError+0x72>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<unqliteErrorFromPosixError>:
mov    %edi,%eax
lea    -0x80(%rax),%ecx
cmp    $0x10,%ecx
ja     1120 <unqliteErrorFromPosixError+0x20>
lea    0xeef(%rip),%rax
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    $0xfffffff2,%eax
ret
test   %eax,%eax
je     1132 <unqliteErrorFromPosixError+0x32>
mov    %esi,%eax
ret
mov    $0xffffffed,%eax
ret
mov    $0xfffffffe,%eax
ret

LLVM IR (-O0):
define i32 @unqliteErrorFromPosixError(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%6 = load i32, i32* %4
switch i32 %6, label %13 [
i32 0, label %7
i32 143, label %8
i32 128, label %8
i32 141, label %8
i32 139, label %8
i32 134, label %8
i32 144, label %9
i32 130, label %10
i32 140, label %11
i32 137, label %12
i32 142, label %12
i32 138, label %12
i32 132, label %12
i32 136, label %12
i32 131, label %12
i32 135, label %12
i32 129, label %12
i32 133, label %12
]
7: ; preds = %2
store i32 0, i32* %3
br label %15
8: ; preds = %2, %2, %2, %2, %2
store i32 -14, i32* %3
br label %15
9: ; preds = %2
store i32 -14, i32* %3
br label %15
10: ; preds = %2
store i32 -19, i32* %3
br label %15
11: ; preds = %2
store i32 -2, i32* %3
br label %15
12: ; preds = %2, %2, %2, %2, %2, %2, %2, %2, %2
br label %13
13: ; preds = %2, %12
%14 = load i32, i32* %5
store i32 %14, i32* %3
br label %15
15: ; preds = %13, %11, %10, %9, %8, %7
%16 = load i32, i32* %3
ret i32 %16
}

LLVM IR (-O2):
define i32 @unqliteErrorFromPosixError(i32 %0, i32 %1) {
switch i32 %0, label %7 [
i32 0, label %8
i32 143, label %3
i32 128, label %3
i32 141, label %3
i32 139, label %3
i32 134, label %3
i32 144, label %4
i32 130, label %5
i32 140, label %6
]
3: ; preds = %2, %2, %2, %2, %2
br label %8
4: ; preds = %2
br label %8
5: ; preds = %2
br label %8
6: ; preds = %2
br label %8
7: ; preds = %2
br label %8
8: ; preds = %2, %7, %6, %5, %4, %3
%9 = phi i32 [ %1, %7 ], [ -2, %6 ], [ -19, %5 ], [ -14, %4 ], [ -14, %3 ], [ %0, %2 ]
ret i32 %9
}