#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 */
int /*<<< orphan*/ find_exit_reason(int, unsigned long long);
scalar_t__ pevent_get_field_val(struct trace_seq *, struct event_format *,
                                char *, struct pevent_record *,
                                unsigned long long *, int);
int /*<<< orphan*/ pevent_print_num_field(struct trace_seq *, char *,
                                          struct event_format *, char *,
                                          struct pevent_record *, int);
int /*<<< orphan*/ trace_seq_printf(struct trace_seq *, char *,
                                    int /*<<< orphan*/);
int kvm_nested_vmexit_inject_handler(struct trace_seq *s,
                                     struct pevent_record *record,
                                     struct event_format *event,
                                     void *context) {
  unsigned long long val;
  pevent_print_num_field(s, " rip %0x016llx", event, "rip", record, 1);
  if (pevent_get_field_val(s, event, "exit_code", record, &val, 1) < 0)
    return -1;
  trace_seq_printf(s, "reason %s", find_exit_reason(2, val));
  pevent_print_num_field(s, " ext_inf1: %0x016llx", event, "exit_info1", record,
                         1);
  pevent_print_num_field(s, " ext_inf2: %0x016llx", event, "exit_info2", record,
                         1);
  pevent_print_num_field(s, " ext_int: %0x016llx", event, "exit_int_info",
                         record, 1);
  pevent_print_num_field(s, " ext_int_err: %0x016llx", event,
                         "exit_int_info_err", record, 1);
  return 0;
}


x86 assembly (clang, -O0):
<kvm_nested_vmexit_inject_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)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%r8
lea    0xe95(%rip),%rsi
lea    0xe9d(%rip),%rcx
mov    $0x1,%r9d
call   1060 <pevent_print_num_field@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xe83(%rip),%rdx
lea    -0x30(%rbp),%r8
mov    $0x1,%r9d
call   1050 <pevent_get_field_val@plt>
cmp    $0x0,%rax
jge    11b5 <kvm_nested_vmexit_inject_handler+0x75>
movl   $0xffffffff,-0x4(%rbp)
jmp    1278 <kvm_nested_vmexit_inject_handler+0x138>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rsi
mov    $0x2,%edi
call   1030 <find_exit_reason@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xe45(%rip),%rsi
call   1040 <trace_seq_printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%r8
lea    0xe37(%rip),%rsi
lea    0xe45(%rip),%rcx
mov    $0x1,%r9d
call   1060 <pevent_print_num_field@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%r8
lea    0xe32(%rip),%rsi
lea    0xe40(%rip),%rcx
mov    $0x1,%r9d
call   1060 <pevent_print_num_field@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%r8
lea    0xe2d(%rip),%rsi
lea    0xe3a(%rip),%rcx
mov    $0x1,%r9d
call   1060 <pevent_print_num_field@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%r8
lea    0xe2a(%rip),%rsi
lea    0xe3b(%rip),%rcx
mov    $0x1,%r9d
call   1060 <pevent_print_num_field@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kvm_nested_vmexit_inject_handler>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xea7(%rip),%rsi
lea    0xeaf(%rip),%rcx
mov    %r14,%r8
mov    $0x1,%r9d
call   1060 <pevent_print_num_field@plt>
lea    0xe9e(%rip),%rdx
lea    0x8(%rsp),%r8
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
mov    $0x1,%r9d
call   1050 <pevent_get_field_val@plt>
test   %rax,%rax
js     1243 <kvm_nested_vmexit_inject_handler+0x103>
mov    0x8(%rsp),%rsi
mov    $0x2,%edi
call   1030 <find_exit_reason@plt>
lea    0xe70(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1040 <trace_seq_printf@plt>
lea    0xe69(%rip),%rsi
lea    0xe77(%rip),%rcx
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%r8
mov    $0x1,%r9d
call   1060 <pevent_print_num_field@plt>
lea    0xe67(%rip),%rsi
lea    0xe75(%rip),%rcx
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%r8
mov    $0x1,%r9d
call   1060 <pevent_print_num_field@plt>
lea    0xe65(%rip),%rsi
lea    0xe72(%rip),%rcx
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%r8
mov    $0x1,%r9d
call   1060 <pevent_print_num_field@plt>
lea    0xe65(%rip),%rsi
lea    0xe76(%rip),%rcx
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%r8
mov    $0x1,%r9d
call   1060 <pevent_print_num_field@plt>
xor    %eax,%eax
jmp    1248 <kvm_nested_vmexit_inject_handler+0x108>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.trace_seq = type { i32 }
%struct.pevent_record = type { i32 }
%struct.event_format = type { i32 }
@.str = [15 x i8] c" rip %0x016llx\00"
@.str.1 = [4 x i8] c"rip\00"
@.str.2 = [10 x i8] c"exit_code\00"
@.str.3 = [10 x i8] c"reason %s\00"
@.str.4 = [21 x i8] c" ext_inf1: %0x016llx\00"
@.str.5 = [11 x i8] c"exit_info1\00"
@.str.6 = [21 x i8] c" ext_inf2: %0x016llx\00"
@.str.7 = [11 x i8] c"exit_info2\00"
@.str.8 = [20 x i8] c" ext_int: %0x016llx\00"
@.str.9 = [14 x i8] c"exit_int_info\00"
@.str.10 = [24 x i8] c" ext_int_err: %0x016llx\00"
@.str.11 = [18 x i8] c"exit_int_info_err\00"
define i32 @kvm_nested_vmexit_inject_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
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
%11 = load %struct.trace_seq*, %struct.trace_seq** %6
%12 = load %struct.event_format*, %struct.event_format** %8
%13 = load %struct.pevent_record*, %struct.pevent_record** %7
%14 = call i32 @pevent_print_num_field(%struct.trace_seq* %11, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.event_format* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %struct.pevent_record* %13, i32 1)
%15 = load %struct.trace_seq*, %struct.trace_seq** %6
%16 = load %struct.event_format*, %struct.event_format** %8
%17 = load %struct.pevent_record*, %struct.pevent_record** %7
%18 = call i64 @pevent_get_field_val(%struct.trace_seq* %15, %struct.event_format* %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %struct.pevent_record* %17, i64* %10, i32 1)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %4
store i32 -1, i32* %5
br label %42
21: ; preds = %4
%22 = load %struct.trace_seq*, %struct.trace_seq** %6
%23 = load i64, i64* %10
%24 = call i32 @find_exit_reason(i32 2, i64 %23)
%25 = call i32 @trace_seq_printf(%struct.trace_seq* %22, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load %struct.trace_seq*, %struct.trace_seq** %6
%27 = load %struct.event_format*, %struct.event_format** %8
%28 = load %struct.pevent_record*, %struct.pevent_record** %7
%29 = call i32 @pevent_print_num_field(%struct.trace_seq* %26, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), %struct.event_format* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), %struct.pevent_record* %28, i32 1)
%30 = load %struct.trace_seq*, %struct.trace_seq** %6
%31 = load %struct.event_format*, %struct.event_format** %8
%32 = load %struct.pevent_record*, %struct.pevent_record** %7
%33 = call i32 @pevent_print_num_field(%struct.trace_seq* %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), %struct.event_format* %31, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), %struct.pevent_record* %32, i32 1)
%34 = load %struct.trace_seq*, %struct.trace_seq** %6
%35 = load %struct.event_format*, %struct.event_format** %8
%36 = load %struct.pevent_record*, %struct.pevent_record** %7
%37 = call i32 @pevent_print_num_field(%struct.trace_seq* %34, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), %struct.event_format* %35, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), %struct.pevent_record* %36, i32 1)
%38 = load %struct.trace_seq*, %struct.trace_seq** %6
%39 = load %struct.event_format*, %struct.event_format** %8
%40 = load %struct.pevent_record*, %struct.pevent_record** %7
%41 = call i32 @pevent_print_num_field(%struct.trace_seq* %38, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), %struct.event_format* %39, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), %struct.pevent_record* %40, i32 1)
store i32 0, i32* %5
br label %42
42: ; preds = %21, %20
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
%struct.trace_seq = type { i32 }
%struct.pevent_record = type { i32 }
%struct.event_format = type { i32 }
@.str = [15 x i8] c" rip %0x016llx\00"
@.str.1 = [4 x i8] c"rip\00"
@.str.2 = [10 x i8] c"exit_code\00"
@.str.3 = [10 x i8] c"reason %s\00"
@.str.4 = [21 x i8] c" ext_inf1: %0x016llx\00"
@.str.5 = [11 x i8] c"exit_info1\00"
@.str.6 = [21 x i8] c" ext_inf2: %0x016llx\00"
@.str.7 = [11 x i8] c"exit_info2\00"
@.str.8 = [20 x i8] c" ext_int: %0x016llx\00"
@.str.9 = [14 x i8] c"exit_int_info\00"
@.str.10 = [24 x i8] c" ext_int_err: %0x016llx\00"
@.str.11 = [18 x i8] c"exit_int_info_err\00"
define i32 @kvm_nested_vmexit_inject_handler(%struct.trace_seq* %0, %struct.pevent_record* %1, %struct.event_format* %2, i8* nocapture readnone %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = tail call i32 @pevent_print_num_field(%struct.trace_seq* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %struct.event_format* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %struct.pevent_record* %1, i32 1)
%8 = call i64 @pevent_get_field_val(%struct.trace_seq* %0, %struct.event_format* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %struct.pevent_record* %1, i64* %5, i32 1)
%9 = icmp slt i64 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %4
%11 = load i64, i64* %5
%12 = call i32 @find_exit_reason(i32 2, i64 %11)
%13 = call i32 @trace_seq_printf(%struct.trace_seq* %0, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %12)
%14 = call i32 @pevent_print_num_field(%struct.trace_seq* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), %struct.event_format* %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), %struct.pevent_record* %1, i32 1)
%15 = call i32 @pevent_print_num_field(%struct.trace_seq* %0, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), %struct.event_format* %2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), %struct.pevent_record* %1, i32 1)
%16 = call i32 @pevent_print_num_field(%struct.trace_seq* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), %struct.event_format* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), %struct.pevent_record* %1, i32 1)
%17 = call i32 @pevent_print_num_field(%struct.trace_seq* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0), %struct.event_format* %2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), %struct.pevent_record* %1, i32 1)
br label %18
18: ; preds = %4, %10
%19 = phi i32 [ 0, %10 ], [ -1, %4 ]
ret i32 %19
}