#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 */
struct bufferevent {
  int dummy;
};

/* Variables and functions */
#define BEV_EVENT_CONNECTED 133
#define BEV_EVENT_EOF 132
#define BEV_EVENT_ERROR 131
#define BEV_EVENT_READING 130
#define BEV_EVENT_TIMEOUT 129
#define BEV_EVENT_WRITING 128
int /*<<< orphan*/ printf(char *);
void on_event(struct bufferevent *bev, short what, void *info) {
  switch (what) {
  case BEV_EVENT_READING:
    printf("error encountered while reading\n");
    break;
  case BEV_EVENT_WRITING:
    printf("error encountered while writing\n");
    break;
  case BEV_EVENT_EOF:
    printf("eof file reached\n");
    break;
  case BEV_EVENT_ERROR:
    printf("unrecoverable error encountered\n");
    break;
  case BEV_EVENT_TIMEOUT:
    printf("user-specified timeout reached\n");
    break;
  case BEV_EVENT_CONNECTED:
    break;
  }
}


x86 assembly (clang, -O0):
<on_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %si,%ax
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
movswl -0xa(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x5,%eax
ja     11ab <on_event+0x9b>
mov    -0x20(%rbp),%rax
lea    0xeb8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xec0(%rip),%rdi
call   1030 <printf@plt>
jmp    11ab <on_event+0x9b>
lea    0xed0(%rip),%rdi
call   1030 <printf@plt>
jmp    11ab <on_event+0x9b>
lea    0xee0(%rip),%rdi
call   1030 <printf@plt>
jmp    11ab <on_event+0x9b>
lea    0xee1(%rip),%rdi
call   1030 <printf@plt>
jmp    11ab <on_event+0x9b>
lea    0xef1(%rip),%rdi
call   1030 <printf@plt>
jmp    11ab <on_event+0x9b>
jmp    11ab <on_event+0x9b>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<on_event>:
add    $0xffffff80,%esi
cmp    $0x4,%esi
ja     112e <on_event+0x1e>
movslq %esi,%rax
lea    0xf6e(%rip),%rcx
movslq (%rcx,%rax,4),%rdi
add    %rcx,%rdi
jmp    1030 <puts@plt>
ret

LLVM IR (-O0):
%struct.bufferevent = type { i32 }
@.str = [33 x i8] c"error encountered while reading\0A\00"
@.str.1 = [33 x i8] c"error encountered while writing\0A\00"
@.str.2 = [18 x i8] c"eof file reached\0A\00"
@.str.3 = [33 x i8] c"unrecoverable error encountered\0A\00"
@.str.4 = [32 x i8] c"user-specified timeout reached\0A\00"
define void @on_event(%struct.bufferevent* %0, i16 signext %1, i8* %2) {
%4 = alloca %struct.bufferevent*
%5 = alloca i16
%6 = alloca i8*
store %struct.bufferevent* %0, %struct.bufferevent** %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%7 = load i16, i16* %5
%8 = sext i16 %7 to i32
switch i32 %8, label %20 [
i32 130, label %9
i32 128, label %11
i32 132, label %13
i32 131, label %15
i32 129, label %17
i32 133, label %19
]
9: ; preds = %3
%10 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %20
11: ; preds = %3
%12 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %20
13: ; preds = %3
%14 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
br label %20
15: ; preds = %3
%16 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %20
17: ; preds = %3
%18 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
br label %20
19: ; preds = %3
br label %20
20: ; preds = %3, %19, %17, %15, %13, %11, %9
ret void
}

LLVM IR (-O2):
%struct.bufferevent = type { i32 }
@str = [31 x i8] c"user-specified timeout reached\00"
@str.5 = [32 x i8] c"unrecoverable error encountered\00"
@str.6 = [17 x i8] c"eof file reached\00"
@str.7 = [32 x i8] c"error encountered while writing\00"
@str.8 = [32 x i8] c"error encountered while reading\00"
@reltable.on_event = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @str.7 to i64), i64 ptrtoint ([5 x i32]* @reltable.on_event to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([31 x i8]* @str to i64), i64 ptrtoint ([5 x i32]* @reltable.on_event to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @str.8 to i64), i64 ptrtoint ([5 x i32]* @reltable.on_event to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([32 x i8]* @str.5 to i64), i64 ptrtoint ([5 x i32]* @reltable.on_event to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([17 x i8]* @str.6 to i64), i64 ptrtoint ([5 x i32]* @reltable.on_event to i64)) to i32)]
define void @on_event(%struct.bufferevent* nocapture readnone %0, i16 signext %1, i8* nocapture readnone %2) {
%4 = sext i16 %1 to i32
%5 = add nsw i32 %4, -128
%6 = icmp ult i32 %5, 5
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = sext i32 %5 to i64
%9 = shl i64 %8, 2
%10 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.on_event to i8*), i64 %9)
%11 = tail call i32 @puts(i8* dereferenceable(1) %10)
br label %12
12: ; preds = %3, %7
ret void
}