#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 /*<<< orphan*/ uint32_t;

/* Variables and functions */
#define EACCES 136
#define EBADF 135
#define EDQUOT 134
#define ENAMETOOLONG 133
#define ENOENT 132
#define ENOTDIR 131
#define ENOTEMPTY 130
#define EPERM 129
#define EROFS 128
int /*<<< orphan*/ write_msg(int, int, int /*<<< orphan*/, int,
                             int /*<<< orphan*/, int, char *, int, char *,
                             int /*<<< orphan*/);
void write_error(uint32_t id, int error) {
  switch (error) {
  case EBADF:
  case ENOTEMPTY:
  case ENAMETOOLONG:
  case ENOTDIR:
    write_msg(101, -2, (uint32_t)id, -2, (uint32_t)5, -1, (""), -1, (""), 0);
    break;
  case ENOENT:
    write_msg(101, -2, (uint32_t)id, -2, (uint32_t)2, -1, (""), -1, (""), 0);
    break;
  case EDQUOT:
  case EACCES:
  case EPERM:
  case EROFS:
    write_msg(101, -2, (uint32_t)id, -2, (uint32_t)3, -1, (""), -1, (""), 0);
    break;
  default:
    write_msg(101, -2, (uint32_t)id, -2, (uint32_t)4, -1, (""), -1, (""), 0);
    break;
  }
}


x86 assembly (clang, -O0):
<write_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
add    $0xffffff80,%eax
sub    $0x2,%eax
jb     1238 <write_error+0x128>
jmp    1135 <write_error+0x25>
mov    -0xc(%rbp),%eax
add    $0xffffff7e,%eax
sub    $0x2,%eax
jb     11aa <write_error+0x9a>
jmp    114b <write_error+0x3b>
mov    -0xc(%rbp),%eax
sub    $0x84,%eax
je     11f1 <write_error+0xe1>
jmp    115e <write_error+0x4e>
mov    -0xc(%rbp),%eax
sub    $0x85,%eax
je     11aa <write_error+0x9a>
jmp    1171 <write_error+0x61>
mov    -0xc(%rbp),%eax
sub    $0x86,%eax
je     1238 <write_error+0x128>
jmp    1184 <write_error+0x74>
mov    -0xc(%rbp),%eax
sub    $0x87,%eax
je     11aa <write_error+0x9a>
jmp    1197 <write_error+0x87>
mov    -0xc(%rbp),%eax
sub    $0x88,%eax
je     1238 <write_error+0x128>
jmp    127f <write_error+0x16f>
mov    -0x4(%rbp),%edx
mov    $0x65,%edi
mov    $0xfffffffe,%ecx
mov    $0x5,%r8d
mov    $0xffffffff,%r9d
lea    0xe36(%rip),%rax
xor    %esi,%esi
mov    %ecx,%esi
mov    %rax,(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
mov    %rax,0x10(%rsp)
movl   $0x0,0x18(%rsp)
call   1030 <write_msg@plt>
jmp    12c1 <write_error+0x1b1>
mov    -0x4(%rbp),%edx
mov    $0x65,%edi
mov    $0xfffffffe,%ecx
mov    $0x2,%r8d
mov    $0xffffffff,%r9d
lea    0xdef(%rip),%rax
xor    %esi,%esi
mov    %ecx,%esi
mov    %rax,(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
mov    %rax,0x10(%rsp)
movl   $0x0,0x18(%rsp)
call   1030 <write_msg@plt>
jmp    12c1 <write_error+0x1b1>
mov    -0x4(%rbp),%edx
mov    $0x65,%edi
mov    $0xfffffffe,%ecx
mov    $0x3,%r8d
mov    $0xffffffff,%r9d
lea    0xda8(%rip),%rax
xor    %esi,%esi
mov    %ecx,%esi
mov    %rax,(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
mov    %rax,0x10(%rsp)
movl   $0x0,0x18(%rsp)
call   1030 <write_msg@plt>
jmp    12c1 <write_error+0x1b1>
mov    -0x4(%rbp),%edx
mov    $0x65,%edi
mov    $0xfffffffe,%ecx
mov    $0x4,%r8d
mov    $0xffffffff,%r9d
lea    0xd61(%rip),%rax
xor    %esi,%esi
mov    %ecx,%esi
mov    %rax,(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
mov    %rax,0x10(%rsp)
movl   $0x0,0x18(%rsp)
call   1030 <write_msg@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_error>:
push   %rax
mov    %edi,%edx
add    $0xffffff80,%esi
mov    $0x4,%r8d
cmp    $0x8,%esi
ja     112f <write_error+0x1f>
movslq %esi,%rax
lea    0xed9(%rip),%rcx
mov    (%rcx,%rax,4),%r8d
lea    0xeca(%rip),%rax
mov    $0x65,%edi
mov    $0xfffffffe,%esi
mov    $0xfffffffe,%ecx
mov    $0xffffffff,%r9d
push   $0x0
push   %rax
push   $0xffffffffffffffff
push   %rax
call   1030 <write_msg@plt>
add    $0x20,%rsp
pop    %rax
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define void @write_error(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %4
switch i32 %5, label %15 [
i32 135, label %6
i32 130, label %6
i32 133, label %6
i32 131, label %6
i32 132, label %9
i32 134, label %12
i32 136, label %12
i32 129, label %12
i32 128, label %12
]
6: ; preds = %2, %2, %2, %2
%7 = load i32, i32* %3
%8 = call i32 @write_msg(i32 101, i32 -2, i32 %7, i32 -2, i32 5, i32 -1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 -1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0)
br label %18
9: ; preds = %2
%10 = load i32, i32* %3
%11 = call i32 @write_msg(i32 101, i32 -2, i32 %10, i32 -2, i32 2, i32 -1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 -1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0)
br label %18
12: ; preds = %2, %2, %2, %2
%13 = load i32, i32* %3
%14 = call i32 @write_msg(i32 101, i32 -2, i32 %13, i32 -2, i32 3, i32 -1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 -1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0)
br label %18
15: ; preds = %2
%16 = load i32, i32* %3
%17 = call i32 @write_msg(i32 101, i32 -2, i32 %16, i32 -2, i32 4, i32 -1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 -1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0)
br label %18
18: ; preds = %15, %12, %9, %6
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@switch.table.write_error = [9 x i32] [i32 3, i32 3, i32 5, i32 5, i32 2, i32 5, i32 3, i32 5, i32 3]
define void @write_error(i32 %0, i32 %1) {
%3 = add i32 %1, -128
%4 = icmp ult i32 %3, 9
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds [9 x i32], [9 x i32]* @switch.table.write_error, i64 0, i64 %6
%8 = load i32, i32* %7
br label %9
9: ; preds = %2, %5
%10 = phi i32 [ %8, %5 ], [ 4, %2 ]
%11 = tail call i32 @write_msg(i32 101, i32 -2, i32 %0, i32 -2, i32 %10, i32 -1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 -1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i32 0)
ret void
}