#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 138
#define EBUSY 137
#define EFBIG 136
#define EINVAL 135
#define EIO 134
#define ENODEV 133
#define ENOENT 132
#define ENOSPC 131
#define ENOSYS 130
#define EPERM 129
int EPROTO;
#define ETIMEDOUT 128
int errno;
void set_errno(unsigned char obex_response) {
  int i;
  unsigned char r;
  static const unsigned char resp[] = {0x40, 0x41, 0x43, 0x44, 0x45, 0x46,
                                       0x48, 0x49, 0x4d, 0x4f, 0x50, 0x51,
                                       0x53, 0x60, 0x61, 0};
  static const int err[] = {EINVAL,    EACCES, EACCES, ENOENT, EINVAL, EPERM,
                            ETIMEDOUT, EINVAL, EFBIG,  EIO,    EIO,    ENOSYS,
                            ENODEV,    ENOSPC, EBUSY,  0};
  r = obex_response & 0x7F;
  if (r < 0x30) {
    errno = EPROTO;
  } else {
    errno = EIO;
    for (i = 0; resp[i] != 0; i++) {
      if (r == resp[i]) {
        errno = err[i];
        break;
      }
    }
  }
  return;
}


x86 assembly (clang, -O0):
<set_errno>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
and    $0x7f,%eax
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
cmp    $0x30,%eax
jge    1138 <set_errno+0x38>
mov    0x2eb8(%rip),%rax
mov    (%rax),%ecx
mov    0x2ea7(%rip),%rax
mov    %ecx,(%rax)
jmp    11b3 <set_errno+0xb3>
mov    0x2e99(%rip),%rax
movl   $0x86,(%rax)
movl   $0x0,-0x8(%rbp)
movslq -0x8(%rbp),%rcx
lea    0xea9(%rip),%rax
movzbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     11ae <set_errno+0xae>
movzbl -0x9(%rbp),%eax
movslq -0x8(%rbp),%rdx
lea    0xe8d(%rip),%rcx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
jne    119b <set_errno+0x9b>
movslq -0x8(%rbp),%rcx
lea    0xe86(%rip),%rax
mov    (%rax,%rcx,4),%ecx
mov    0x2e44(%rip),%rax
mov    %ecx,(%rax)
jmp    11ae <set_errno+0xae>
jmp    11a0 <set_errno+0xa0>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    114c <set_errno+0x4c>
jmp    11b3 <set_errno+0xb3>
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_errno>:
and    $0x7f,%dil
cmp    $0x30,%dil
jae    1113 <set_errno+0x13>
mov    0x2ecf(%rip),%rax
jmp    1158 <set_errno+0x58>
mov    0x2ebe(%rip),%rax
movl   $0x86,(%rax)
add    $0xc0,%dil
cmp    $0x21,%dil
ja     1163 <set_errno+0x63>
movzbl %dil,%eax
movabs $0x3000ba37b,%rcx
bt     %rax,%rcx
jae    1163 <set_errno+0x63>
movsbq %dil,%rax
lea    0xef7(%rip),%rcx
mov    (%rcx,%rax,8),%rax
lea    0xeac(%rip),%rcx
lea    (%rcx,%rax,4),%rax
mov    (%rax),%eax
mov    0x2e77(%rip),%rcx
mov    %eax,(%rcx)
ret

LLVM IR (-O0):
@set_errno.resp = internal constant [16 x i8] c"@ACDEFHIMOPQS`a\00"
@set_errno.err = internal constant [16 x i32] [i32 135, i32 138, i32 138, i32 132, i32 135, i32 129, i32 128, i32 135, i32 136, i32 134, i32 134, i32 130, i32 133, i32 131, i32 137, i32 0]
@EPROTO = global i32 0
@errno = global i32 0
define void @set_errno(i8 zeroext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i8
store i8 %0, i8* %2
%5 = load i8, i8* %2
%6 = zext i8 %5 to i32
%7 = and i32 %6, 127
%8 = trunc i32 %7 to i8
store i8 %8, i8* %4
%9 = load i8, i8* %4
%10 = zext i8 %9 to i32
%11 = icmp slt i32 %10, 48
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = load i32, i32* @EPROTO
store i32 %13, i32* @errno
br label %41
14: ; preds = %1
store i32 134, i32* @errno
store i32 0, i32* %3
br label %15
15: ; preds = %37, %14
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [16 x i8], [16 x i8]* @set_errno.resp, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %40
22: ; preds = %15
%23 = load i8, i8* %4
%24 = zext i8 %23 to i32
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [16 x i8], [16 x i8]* @set_errno.resp, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = icmp eq i32 %24, %29
br i1 %30, label %31, label %36
31: ; preds = %22
%32 = load i32, i32* %3
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [16 x i32], [16 x i32]* @set_errno.err, i64 0, i64 %33
%35 = load i32, i32* %34
store i32 %35, i32* @errno
br label %40
36: ; preds = %22
br label %37
37: ; preds = %36
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %15
40: ; preds = %31, %15
br label %41
41: ; preds = %40, %12
ret void
}

LLVM IR (-O2):
@set_errno.err = internal unnamed_addr constant [16 x i32] [i32 135, i32 138, i32 138, i32 132, i32 135, i32 129, i32 128, i32 135, i32 136, i32 134, i32 134, i32 130, i32 133, i32 131, i32 137, i32 0]
@EPROTO = global i32 0
@errno = global i32 0
@switch.table.set_errno = [34 x i64] [i64 0, i64 1, i64 0, i64 2, i64 3, i64 4, i64 5, i64 0, i64 6, i64 7, i64 0, i64 0, i64 0, i64 8, i64 0, i64 9, i64 10, i64 11, i64 0, i64 12, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 0, i64 13, i64 14]
define void @set_errno(i8 zeroext %0) {
%2 = and i8 %0, 127
%3 = icmp ult i8 %2, 48
br i1 %3, label %17, label %4
4: ; preds = %1
store i32 134, i32* @errno
%5 = add nsw i8 %2, -64
%6 = icmp ult i8 %5, 34
br i1 %6, label %7, label %20
7: ; preds = %4
%8 = zext i8 %5 to i64
%9 = lshr i64 12885664635, %8
%10 = and i64 %9, 1
%11 = icmp eq i64 %10, 0
br i1 %11, label %20, label %12
12: ; preds = %7
%13 = sext i8 %5 to i64
%14 = getelementptr inbounds [34 x i64], [34 x i64]* @switch.table.set_errno, i64 0, i64 %13
%15 = load i64, i64* %14
%16 = getelementptr inbounds [16 x i32], [16 x i32]* @set_errno.err, i64 0, i64 %15
br label %17
17: ; preds = %1, %12
%18 = phi i32* [ %16, %12 ], [ @EPROTO, %1 ]
%19 = load i32, i32* %18
store i32 %19, i32* @errno
br label %20
20: ; preds = %7, %4, %17
ret void
}