#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 */
typedef int int64_t;

/* Variables and functions */
int /*<<< orphan*/ EACCES;
int /*<<< orphan*/ EAGAIN;
int /*<<< orphan*/ EBUSY;
int /*<<< orphan*/ ECONNRESET;
int /*<<< orphan*/ EEXIST;
int /*<<< orphan*/ EFBIG;
int /*<<< orphan*/ EINVAL;
int /*<<< orphan*/ EISDIR;
int /*<<< orphan*/ EMFILE;
int /*<<< orphan*/ ENAMETOOLONG;
int /*<<< orphan*/ ENOENT;
int /*<<< orphan*/ ENOMEM;
int /*<<< orphan*/ ENOSPC;
int /*<<< orphan*/ ENOTDIR;
int /*<<< orphan*/ ENOTEMPTY;
int /*<<< orphan*/ ENOTSUP;
int /*<<< orphan*/ ESPIPE;
int /*<<< orphan*/ ESRCH;
int /*<<< orphan*/ EXDEV;
int /*<<< orphan*/ errno;
int64_t convert_result(int64_t result) {
  if (result >= 0) {
    return result;
  } else {
    switch (result) {
    case -1:
    case -2:
      errno = EACCES;
      break;
    case -3:
      errno = ENOENT;
      break;
    case -4:
      errno = EEXIST;
      break;
    case -5:
      errno = EFBIG;
      break;
    case -6:
      errno = ENOSPC;
      break;
    case -7:
      errno = ENOMEM;
      break;
    case -8:
      errno = EINVAL;
      break;
    case -9:
      errno = EMFILE;
      break;
    case -10:
      errno = EBUSY;
      break;
    case -11:
      errno = EAGAIN;
      break;
    case -14:
      errno = ENOTDIR;
      break;
    case -13:
      errno = EISDIR;
      break;
    case -15:
      errno = ENOTEMPTY;
      break;
    case -16:
      errno = EXDEV;
      break;
    case -21:
      errno = ESRCH;
      break;
    case -22:
      errno = ESPIPE;
      break;
    case -23:
      errno = ENOTSUP;
      break;
    case -24:
      errno = ENAMETOOLONG;
      break;
    case -20:
    case -18:
    case -19:
    case -127:
      errno = ECONNRESET;
      break;
    }
    return -1;
  }
}


x86 assembly (clang, -O0):
<convert_result>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     111c <convert_result+0x1c>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12fc <convert_result+0x1fc>
mov    -0x8(%rbp),%eax
add    $0x7f,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x7e,%eax
ja     12f5 <convert_result+0x1f5>
mov    -0x10(%rbp),%rax
lea    0xec4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e74(%rip),%rax
mov    (%rax),%ecx
mov    0x2e3b(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2dfd(%rip),%rax
mov    (%rax),%ecx
mov    0x2e24(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2e2e(%rip),%rax
mov    (%rax),%ecx
mov    0x2e0d(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2e47(%rip),%rax
mov    (%rax),%ecx
mov    0x2df6(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2dd8(%rip),%rax
mov    (%rax),%ecx
mov    0x2ddf(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2dd9(%rip),%rax
mov    (%rax),%ecx
mov    0x2dc8(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2db2(%rip),%rax
mov    (%rax),%ecx
mov    0x2db1(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2d6b(%rip),%rax
mov    (%rax),%ecx
mov    0x2d9a(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2d6c(%rip),%rax
mov    (%rax),%ecx
mov    0x2d83(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2d2d(%rip),%rax
mov    (%rax),%ecx
mov    0x2d6c(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2dc6(%rip),%rax
mov    (%rax),%ecx
mov    0x2d55(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2d97(%rip),%rax
mov    (%rax),%ecx
mov    0x2d3e(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2cf0(%rip),%rax
mov    (%rax),%ecx
mov    0x2d27(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2d29(%rip),%rax
mov    (%rax),%ecx
mov    0x2d10(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2cb2(%rip),%rax
mov    (%rax),%ecx
mov    0x2cf9(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2d23(%rip),%rax
mov    (%rax),%ecx
mov    0x2ce2(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2d14(%rip),%rax
mov    (%rax),%ecx
mov    0x2ccb(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2ca5(%rip),%rax
mov    (%rax),%ecx
mov    0x2cb4(%rip),%rax
mov    %ecx,(%rax)
jmp    12f5 <convert_result+0x1f5>
mov    0x2cc6(%rip),%rax
mov    (%rax),%ecx
mov    0x2c9d(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert_result>:
test   %edi,%edi
js     1107 <convert_result+0x7>
mov    %edi,%eax
ret
mov    $0xffffffff,%eax
add    $0x7f,%edi
cmp    $0x7e,%edi
ja     11e3 <convert_result+0xe3>
mov    0x2ea1(%rip),%rcx
lea    0xeda(%rip),%rdx
movslq (%rdx,%rdi,4),%rsi
add    %rdx,%rsi
jmp    *%rsi
mov    0x2e7a(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2e36(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2e82(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2e6e(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2ddd(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2e34(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2ddb(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2e7a(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2e59(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2db8(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2dd7(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2db6(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2ddd(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2de4(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2dc3(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2e12(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2dd9(%rip),%rcx
jmp    11d8 <convert_result+0xd8>
mov    0x2d88(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2daf(%rip),%rdx
mov    %ecx,(%rdx)
ret

LLVM IR (-O0):
@EACCES = global i32 0
@errno = global i32 0
@ENOENT = global i32 0
@EEXIST = global i32 0
@EFBIG = global i32 0
@ENOSPC = global i32 0
@ENOMEM = global i32 0
@EINVAL = global i32 0
@EMFILE = global i32 0
@EBUSY = global i32 0
@EAGAIN = global i32 0
@ENOTDIR = global i32 0
@EISDIR = global i32 0
@ENOTEMPTY = global i32 0
@EXDEV = global i32 0
@ESRCH = global i32 0
@ESPIPE = global i32 0
@ENOTSUP = global i32 0
@ENAMETOOLONG = global i32 0
@ECONNRESET = global i32 0
define i32 @convert_result(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = icmp sge i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = load i32, i32* %3
store i32 %7, i32* %2
br label %49
8: ; preds = %1
%9 = load i32, i32* %3
switch i32 %9, label %48 [
i32 -1, label %10
i32 -2, label %10
i32 -3, label %12
i32 -4, label %14
i32 -5, label %16
i32 -6, label %18
i32 -7, label %20
i32 -8, label %22
i32 -9, label %24
i32 -10, label %26
i32 -11, label %28
i32 -14, label %30
i32 -13, label %32
i32 -15, label %34
i32 -16, label %36
i32 -21, label %38
i32 -22, label %40
i32 -23, label %42
i32 -24, label %44
i32 -20, label %46
i32 -18, label %46
i32 -19, label %46
i32 -127, label %46
]
10: ; preds = %8, %8
%11 = load i32, i32* @EACCES
store i32 %11, i32* @errno
br label %48
12: ; preds = %8
%13 = load i32, i32* @ENOENT
store i32 %13, i32* @errno
br label %48
14: ; preds = %8
%15 = load i32, i32* @EEXIST
store i32 %15, i32* @errno
br label %48
16: ; preds = %8
%17 = load i32, i32* @EFBIG
store i32 %17, i32* @errno
br label %48
18: ; preds = %8
%19 = load i32, i32* @ENOSPC
store i32 %19, i32* @errno
br label %48
20: ; preds = %8
%21 = load i32, i32* @ENOMEM
store i32 %21, i32* @errno
br label %48
22: ; preds = %8
%23 = load i32, i32* @EINVAL
store i32 %23, i32* @errno
br label %48
24: ; preds = %8
%25 = load i32, i32* @EMFILE
store i32 %25, i32* @errno
br label %48
26: ; preds = %8
%27 = load i32, i32* @EBUSY
store i32 %27, i32* @errno
br label %48
28: ; preds = %8
%29 = load i32, i32* @EAGAIN
store i32 %29, i32* @errno
br label %48
30: ; preds = %8
%31 = load i32, i32* @ENOTDIR
store i32 %31, i32* @errno
br label %48
32: ; preds = %8
%33 = load i32, i32* @EISDIR
store i32 %33, i32* @errno
br label %48
34: ; preds = %8
%35 = load i32, i32* @ENOTEMPTY
store i32 %35, i32* @errno
br label %48
36: ; preds = %8
%37 = load i32, i32* @EXDEV
store i32 %37, i32* @errno
br label %48
38: ; preds = %8
%39 = load i32, i32* @ESRCH
store i32 %39, i32* @errno
br label %48
40: ; preds = %8
%41 = load i32, i32* @ESPIPE
store i32 %41, i32* @errno
br label %48
42: ; preds = %8
%43 = load i32, i32* @ENOTSUP
store i32 %43, i32* @errno
br label %48
44: ; preds = %8
%45 = load i32, i32* @ENAMETOOLONG
store i32 %45, i32* @errno
br label %48
46: ; preds = %8, %8, %8, %8
%47 = load i32, i32* @ECONNRESET
store i32 %47, i32* @errno
br label %48
48: ; preds = %8, %46, %44, %42, %40, %38, %36, %34, %32, %30, %28, %26, %24, %22, %20, %18, %16, %14, %12, %10
store i32 -1, i32* %2
br label %49
49: ; preds = %48, %6
%50 = load i32, i32* %2
ret i32 %50
}

LLVM IR (-O2):
@EACCES = global i32 0
@errno = global i32 0
@ENOENT = global i32 0
@EEXIST = global i32 0
@EFBIG = global i32 0
@ENOSPC = global i32 0
@ENOMEM = global i32 0
@EINVAL = global i32 0
@EMFILE = global i32 0
@EBUSY = global i32 0
@EAGAIN = global i32 0
@ENOTDIR = global i32 0
@EISDIR = global i32 0
@ENOTEMPTY = global i32 0
@EXDEV = global i32 0
@ESRCH = global i32 0
@ESPIPE = global i32 0
@ENOTSUP = global i32 0
@ENAMETOOLONG = global i32 0
@ECONNRESET = global i32 0
define i32 @convert_result(i32 %0) {
%2 = icmp sgt i32 %0, -1
br i1 %2, label %25, label %3
3: ; preds = %1
switch i32 %0, label %25 [
i32 -1, label %22
i32 -2, label %22
i32 -3, label %4
i32 -4, label %5
i32 -5, label %6
i32 -6, label %7
i32 -7, label %8
i32 -8, label %9
i32 -9, label %10
i32 -10, label %11
i32 -11, label %12
i32 -14, label %13
i32 -13, label %14
i32 -15, label %15
i32 -16, label %16
i32 -21, label %17
i32 -22, label %18
i32 -23, label %19
i32 -24, label %20
i32 -20, label %21
i32 -18, label %21
i32 -19, label %21
i32 -127, label %21
]
4: ; preds = %3
br label %22
5: ; preds = %3
br label %22
6: ; preds = %3
br label %22
7: ; preds = %3
br label %22
8: ; preds = %3
br label %22
9: ; preds = %3
br label %22
10: ; preds = %3
br label %22
11: ; preds = %3
br label %22
12: ; preds = %3
br label %22
13: ; preds = %3
br label %22
14: ; preds = %3
br label %22
15: ; preds = %3
br label %22
16: ; preds = %3
br label %22
17: ; preds = %3
br label %22
18: ; preds = %3
br label %22
19: ; preds = %3
br label %22
20: ; preds = %3
br label %22
21: ; preds = %3, %3, %3, %3
br label %22
22: ; preds = %3, %3, %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5, %4
%23 = phi i32* [ @ENOENT, %4 ], [ @EEXIST, %5 ], [ @EFBIG, %6 ], [ @ENOSPC, %7 ], [ @ENOMEM, %8 ], [ @EINVAL, %9 ], [ @EMFILE, %10 ], [ @EBUSY, %11 ], [ @EAGAIN, %12 ], [ @ENOTDIR, %13 ], [ @EISDIR, %14 ], [ @ENOTEMPTY, %15 ], [ @EXDEV, %16 ], [ @ESRCH, %17 ], [ @ESPIPE, %18 ], [ @ENOTSUP, %19 ], [ @ENAMETOOLONG, %20 ], [ @ECONNRESET, %21 ], [ @EACCES, %3 ], [ @EACCES, %3 ]
%24 = load i32, i32* %23
store i32 %24, i32* @errno
br label %25
25: ; preds = %22, %3, %1
%26 = phi i32 [ %0, %1 ], [ -1, %3 ], [ -1, %22 ]
ret i32 %26
}