#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 ukvm_hv {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ gdb_handle_exception(struct ukvm_hv *, int);
int /*<<< orphan*/ send_response(char, int /*<<< orphan*/, int);
int ukvm_gdb_read_last_signal(struct ukvm_hv *, int *);
int handle_exit(struct ukvm_hv *hv) {
  int sigval = 0;
  if (ukvm_gdb_read_last_signal(hv, &sigval) == -1)
    return -1;
  switch (sigval) {
  case 5:
    gdb_handle_exception(hv, sigval);
    return 0;
  case 15:
    send_response('W', 0, true);
    return -1;
  case 3:
  case 9:
  case 11:
    gdb_handle_exception(hv, sigval);
    return 0;
  default:
    return -1;
  }
}


x86 assembly (clang, -O0):
<handle_exit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <ukvm_gdb_read_last_signal@plt>
cmp    $0xffffffff,%eax
jne    1165 <handle_exit+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <handle_exit+0xb2>
mov    -0x14(%rbp),%eax
add    $0xfffffffd,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0xc,%eax
ja     11db <handle_exit+0xab>
mov    -0x20(%rbp),%rax
lea    0xe7b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <gdb_handle_exception@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e2 <handle_exit+0xb2>
mov    $0x57,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1040 <send_response@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e2 <handle_exit+0xb2>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <gdb_handle_exception@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e2 <handle_exit+0xb2>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_exit>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
movl   $0x0,0x4(%rsp)
lea    0x4(%rsp),%rsi
call   1030 <ukvm_gdb_read_last_signal@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     118d <handle_exit+0x5d>
mov    0x4(%rsp),%esi
lea    -0x3(%rsi),%eax
ror    %eax
cmp    $0x6,%eax
ja     118d <handle_exit+0x5d>
lea    0xe99(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    %rbx,%rdi
call   1050 <gdb_handle_exception@plt>
xor    %ebp,%ebp
jmp    118d <handle_exit+0x5d>
mov    $0x57,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1040 <send_response@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.ukvm_hv = type { i32 }
define i32 @handle_exit(%struct.ukvm_hv* %0) {
%2 = alloca i32
%3 = alloca %struct.ukvm_hv*
%4 = alloca i32
store %struct.ukvm_hv* %0, %struct.ukvm_hv** %3
store i32 0, i32* %4
%5 = load %struct.ukvm_hv*, %struct.ukvm_hv** %3
%6 = call i32 @ukvm_gdb_read_last_signal(%struct.ukvm_hv* %5, i32* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %22
9: ; preds = %1
%10 = load i32, i32* %4
switch i32 %10, label %21 [
i32 5, label %11
i32 15, label %15
i32 3, label %17
i32 9, label %17
i32 11, label %17
]
11: ; preds = %9
%12 = load %struct.ukvm_hv*, %struct.ukvm_hv** %3
%13 = load i32, i32* %4
%14 = call i32 @gdb_handle_exception(%struct.ukvm_hv* %12, i32 %13)
store i32 0, i32* %2
br label %22
15: ; preds = %9
%16 = call i32 @send_response(i8 signext 87, i32 0, i32 1)
store i32 -1, i32* %2
br label %22
17: ; preds = %9, %9, %9
%18 = load %struct.ukvm_hv*, %struct.ukvm_hv** %3
%19 = load i32, i32* %4
%20 = call i32 @gdb_handle_exception(%struct.ukvm_hv* %18, i32 %19)
store i32 0, i32* %2
br label %22
21: ; preds = %9
store i32 -1, i32* %2
br label %22
22: ; preds = %21, %17, %15, %11, %8
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
%struct.ukvm_hv = type { i32 }
define i32 @handle_exit(%struct.ukvm_hv* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%4 = call i32 @ukvm_gdb_read_last_signal(%struct.ukvm_hv* %0, i32* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %16, label %6
6: ; preds = %1
%7 = load i32, i32* %2
%8 = add i32 %7, -3
%9 = call i32 @llvm.fshl.i32(i32 %8, i32 %8, i32 31)
switch i32 %9, label %16 [
i32 1, label %10
i32 6, label %12
i32 0, label %14
i32 3, label %14
i32 4, label %14
]
10: ; preds = %6
%11 = call i32 @gdb_handle_exception(%struct.ukvm_hv* %0, i32 %7)
br label %16
12: ; preds = %6
%13 = call i32 @send_response(i8 signext 87, i32 0, i32 1)
br label %16
14: ; preds = %6, %6, %6
%15 = call i32 @gdb_handle_exception(%struct.ukvm_hv* %0, i32 %7)
br label %16
16: ; preds = %6, %1, %14, %12, %10
%17 = phi i32 [ 0, %14 ], [ -1, %12 ], [ 0, %10 ], [ -1, %1 ], [ -1, %6 ]
ret i32 %17
}