#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 trace_seq {
  int dummy;
};
struct pevent_record {
  int dummy;
};
struct event_format {
  int dummy;
};

/* Variables and functions */
scalar_t__ pevent_get_field_val(struct trace_seq *, struct event_format *,
                                char *, struct pevent_record *,
                                unsigned long long *, int /*<<< orphan*/);
int /*<<< orphan*/ pevent_print_num_field(struct trace_seq *, char *,
                                          struct event_format *, char *,
                                          struct pevent_record *, int);
scalar_t__ print_exit_reason(struct trace_seq *, struct pevent_record *,
                             struct event_format *, char *);
int /*<<< orphan*/ trace_seq_printf(struct trace_seq *, char *,
                                    unsigned long long, unsigned long long);
int kvm_exit_handler(struct trace_seq *s, struct pevent_record *record,
                     struct event_format *event, void *context) {
  unsigned long long info1 = 0, info2 = 0;
  if (print_exit_reason(s, record, event, "exit_reason") < 0)
    return -1;
  pevent_print_num_field(s, " rip 0x%lx", event, "guest_rip", record, 1);
  if (pevent_get_field_val(s, event, "info1", record, &info1, 0) >= 0 &&
      pevent_get_field_val(s, event, "info2", record, &info2, 0) >= 0)
    trace_seq_printf(s, " info %llx %llx\n", info1, info2);
  return 0;
}


x86 assembly (clang, -O0):
<kvm_exit_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    0xe85(%rip),%rcx
call   1060 <print_exit_reason@plt>
cmp    $0x0,%rax
jge    1196 <kvm_exit_handler+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    122c <kvm_exit_handler+0xec>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%r8
lea    0xe63(%rip),%rsi
lea    0xe67(%rip),%rcx
mov    $0x1,%r9d
call   1050 <pevent_print_num_field@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xe53(%rip),%rdx
lea    -0x30(%rbp),%r8
xor    %r9d,%r9d
call   1040 <pevent_get_field_val@plt>
cmp    $0x0,%rax
jl     1225 <kvm_exit_handler+0xe5>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xe30(%rip),%rdx
lea    -0x38(%rbp),%r8
xor    %r9d,%r9d
call   1040 <pevent_get_field_val@plt>
cmp    $0x0,%rax
jl     1225 <kvm_exit_handler+0xe5>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x38(%rbp),%rcx
lea    0xe0d(%rip),%rsi
call   1030 <trace_seq_printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kvm_exit_handler>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe94(%rip),%rcx
call   1060 <print_exit_reason@plt>
test   %rax,%rax
js     11ff <kvm_exit_handler+0xbf>
lea    0xe8b(%rip),%rsi
lea    0xe8f(%rip),%rcx
mov    %r14,%rdi
mov    %rbx,%rdx
mov    %r15,%r8
mov    $0x1,%r9d
call   1050 <pevent_print_num_field@plt>
lea    0xe7e(%rip),%rdx
lea    0x10(%rsp),%r8
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rcx
xor    %r9d,%r9d
call   1040 <pevent_get_field_val@plt>
test   %rax,%rax
js     1204 <kvm_exit_handler+0xc4>
lea    0xe60(%rip),%rdx
lea    0x8(%rsp),%r8
xor    %ebp,%ebp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rcx
xor    %r9d,%r9d
call   1040 <pevent_get_field_val@plt>
test   %rax,%rax
js     1204 <kvm_exit_handler+0xc4>
mov    0x10(%rsp),%rdx
mov    0x8(%rsp),%rcx
lea    0xe38(%rip),%rsi
mov    %r14,%rdi
call   1030 <trace_seq_printf@plt>
jmp    1204 <kvm_exit_handler+0xc4>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.trace_seq = type { i32 }
%struct.pevent_record = type { i32 }
%struct.event_format = type { i32 }
@.str = [12 x i8] c"exit_reason\00"
@.str.1 = [11 x i8] c" rip 0x%lx\00"
@.str.2 = [10 x i8] c"guest_rip\00"
@.str.3 = [6 x i8] c"info1\00"
@.str.4 = [6 x i8] c"info2\00"
@.str.5 = [17 x i8] c" info %llx %llx\0A\00"
define i32 @kvm_exit_handler(%struct.trace_seq* %0, %struct.pevent_record* %1, %struct.event_format* %2, i8* %3) {
%5 = alloca i32
%6 = alloca %struct.trace_seq*
%7 = alloca %struct.pevent_record*
%8 = alloca %struct.event_format*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i64
store %struct.trace_seq* %0, %struct.trace_seq** %6
store %struct.pevent_record* %1, %struct.pevent_record** %7
store %struct.event_format* %2, %struct.event_format** %8
store i8* %3, i8** %9
store i64 0, i64* %10
store i64 0, i64* %11
%12 = load %struct.trace_seq*, %struct.trace_seq** %6
%13 = load %struct.pevent_record*, %struct.pevent_record** %7
%14 = load %struct.event_format*, %struct.event_format** %8
%15 = call i64 @print_exit_reason(%struct.trace_seq* %12, %struct.pevent_record* %13, %struct.event_format* %14, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %4
store i32 -1, i32* %5
br label %40
18: ; preds = %4
%19 = load %struct.trace_seq*, %struct.trace_seq** %6
%20 = load %struct.event_format*, %struct.event_format** %8
%21 = load %struct.pevent_record*, %struct.pevent_record** %7
%22 = call i32 @pevent_print_num_field(%struct.trace_seq* %19, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %struct.event_format* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %struct.pevent_record* %21, i32 1)
%23 = load %struct.trace_seq*, %struct.trace_seq** %6
%24 = load %struct.event_format*, %struct.event_format** %8
%25 = load %struct.pevent_record*, %struct.pevent_record** %7
%26 = call i64 @pevent_get_field_val(%struct.trace_seq* %23, %struct.event_format* %24, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %struct.pevent_record* %25, i64* %10, i32 0)
%27 = icmp sge i64 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %18
%29 = load %struct.trace_seq*, %struct.trace_seq** %6
%30 = load %struct.event_format*, %struct.event_format** %8
%31 = load %struct.pevent_record*, %struct.pevent_record** %7
%32 = call i64 @pevent_get_field_val(%struct.trace_seq* %29, %struct.event_format* %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), %struct.pevent_record* %31, i64* %11, i32 0)
%33 = icmp sge i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = load %struct.trace_seq*, %struct.trace_seq** %6
%36 = load i64, i64* %10
%37 = load i64, i64* %11
%38 = call i32 @trace_seq_printf(%struct.trace_seq* %35, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64 %36, i64 %37)
br label %39
39: ; preds = %34, %28, %18
store i32 0, i32* %5
br label %40
40: ; preds = %39, %17
%41 = load i32, i32* %5
ret i32 %41
}

LLVM IR (-O2):
%struct.trace_seq = type { i32 }
%struct.pevent_record = type { i32 }
%struct.event_format = type { i32 }
@.str = [12 x i8] c"exit_reason\00"
@.str.1 = [11 x i8] c" rip 0x%lx\00"
@.str.2 = [10 x i8] c"guest_rip\00"
@.str.3 = [6 x i8] c"info1\00"
@.str.4 = [6 x i8] c"info2\00"
@.str.5 = [17 x i8] c" info %llx %llx\0A\00"
define i32 @kvm_exit_handler(%struct.trace_seq* %0, %struct.pevent_record* %1, %struct.event_format* %2, i8* nocapture readnone %3) {
%5 = alloca i64
%6 = alloca i64
%7 = bitcast i64* %5 to i8*
store i64 0, i64* %5
%8 = bitcast i64* %6 to i8*
store i64 0, i64* %6
%9 = tail call i64 @print_exit_reason(%struct.trace_seq* %0, %struct.pevent_record* %1, %struct.event_format* %2, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = icmp slt i64 %9, 0
br i1 %10, label %22, label %11
11: ; preds = %4
%12 = tail call i32 @pevent_print_num_field(%struct.trace_seq* %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %struct.event_format* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %struct.pevent_record* %1, i32 1)
%13 = call i64 @pevent_get_field_val(%struct.trace_seq* %0, %struct.event_format* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), %struct.pevent_record* %1, i64* %5, i32 0)
%14 = icmp sgt i64 %13, -1
br i1 %14, label %15, label %22
15: ; preds = %11
%16 = call i64 @pevent_get_field_val(%struct.trace_seq* %0, %struct.event_format* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), %struct.pevent_record* %1, i64* %6, i32 0)
%17 = icmp sgt i64 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i64, i64* %5
%20 = load i64, i64* %6
%21 = call i32 @trace_seq_printf(%struct.trace_seq* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i64 %19, i64 %20)
br label %22
22: ; preds = %11, %15, %18, %4
%23 = phi i32 [ -1, %4 ], [ 0, %18 ], [ 0, %15 ], [ 0, %11 ]
ret i32 %23
}