#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 kvm_mmu_print_role(struct trace_seq *, struct pevent_record *,
                       struct event_format *, void *);
scalar_t__ pevent_get_field_val(struct trace_seq *, struct event_format *,
                                char *, struct pevent_record *,
                                unsigned long long *, int);
int /*<<< orphan*/ trace_seq_printf(struct trace_seq *, char *,
                                    unsigned long long);
int kvm_mmu_get_page_handler(struct trace_seq *s, struct pevent_record *record,
                             struct event_format *event, void *context) {
  unsigned long long val;
  if (pevent_get_field_val(s, event, "gfn", record, &val, 1) < 0)
    return -1;
  trace_seq_printf(s, "sp gfn %llx ", val);
  return kvm_mmu_print_role(s, record, event, context);
}


x86 assembly (clang, -O0):
<kvm_mmu_get_page_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xea5(%rip),%rdx
lea    -0x30(%rbp),%r8
mov    $0x1,%r9d
call   1040 <pevent_get_field_val@plt>
cmp    $0x0,%rax
jge    1180 <kvm_mmu_get_page_handler+0x50>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <kvm_mmu_get_page_handler+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xe75(%rip),%rsi
call   1030 <trace_seq_printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <kvm_mmu_print_role@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kvm_mmu_get_page_handler>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0xeb5(%rip),%rdx
mov    %rsp,%r8
mov    %r15,%rsi
mov    %r12,%rcx
mov    $0x1,%r9d
call   1040 <pevent_get_field_val@plt>
test   %rax,%rax
js     118a <kvm_mmu_get_page_handler+0x5a>
mov    (%rsp),%rdx
lea    0xe95(%rip),%rsi
mov    %rbx,%rdi
call   1030 <trace_seq_printf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
call   1050 <kvm_mmu_print_role@plt>
jmp    118f <kvm_mmu_get_page_handler+0x5f>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.trace_seq = type { i32 }
%struct.pevent_record = type { i32 }
%struct.event_format = type { i32 }
@.str = [4 x i8] c"gfn\00"
@.str.1 = [13 x i8] c"sp gfn %llx \00"
define i32 @kvm_mmu_get_page_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 i64 @pevent_get_field_val(%struct.trace_seq* %11, %struct.event_format* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %struct.pevent_record* %13, i64* %10, i32 1)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %4
store i32 -1, i32* %5
br label %26
17: ; preds = %4
%18 = load %struct.trace_seq*, %struct.trace_seq** %6
%19 = load i64, i64* %10
%20 = call i32 @trace_seq_printf(%struct.trace_seq* %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %19)
%21 = load %struct.trace_seq*, %struct.trace_seq** %6
%22 = load %struct.pevent_record*, %struct.pevent_record** %7
%23 = load %struct.event_format*, %struct.event_format** %8
%24 = load i8*, i8** %9
%25 = call i32 @kvm_mmu_print_role(%struct.trace_seq* %21, %struct.pevent_record* %22, %struct.event_format* %23, i8* %24)
store i32 %25, i32* %5
br label %26
26: ; preds = %17, %16
%27 = load i32, i32* %5
ret i32 %27
}

LLVM IR (-O2):
%struct.trace_seq = type { i32 }
%struct.pevent_record = type { i32 }
%struct.event_format = type { i32 }
@.str = [4 x i8] c"gfn\00"
@.str.1 = [13 x i8] c"sp gfn %llx \00"
define i32 @kvm_mmu_get_page_handler(%struct.trace_seq* %0, %struct.pevent_record* %1, %struct.event_format* %2, i8* %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = call i64 @pevent_get_field_val(%struct.trace_seq* %0, %struct.event_format* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %struct.pevent_record* %1, i64* %5, i32 1)
%8 = icmp slt i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %4
%10 = load i64, i64* %5
%11 = call i32 @trace_seq_printf(%struct.trace_seq* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i64 %10)
%12 = call i32 @kvm_mmu_print_role(%struct.trace_seq* %0, %struct.pevent_record* %1, %struct.event_format* %2, i8* %3)
br label %13
13: ; preds = %4, %9
%14 = phi i32 [ %12, %9 ], [ -1, %4 ]
ret i32 %14
}