#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 *, ...);
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, "created", record, &val, 1) < 0) {
    return -1;
  }
  trace_seq_printf(s, "%s ", val ? "new" : "existing");
  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    1212 <kvm_mmu_get_page_handler+0xe2>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rcx
lea    0xe81(%rip),%rdx
lea    0xe76(%rip),%rax
cmp    $0x0,%rcx
cmovne %rax,%rdx
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1030 <trace_seq_printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xe5a(%rip),%rdx
lea    -0x30(%rbp),%r8
mov    $0x1,%r9d
call   1040 <pevent_get_field_val@plt>
cmp    $0x0,%rax
jge    11e4 <kvm_mmu_get_page_handler+0xb4>
movl   $0xffffffff,-0x4(%rbp)
jmp    1212 <kvm_mmu_get_page_handler+0xe2>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xe2a(%rip),%rsi
mov    $0x0,%al
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   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0xeb1(%rip),%rdx
lea    0x8(%rsp),%r8
mov    %r15,%rsi
mov    %r12,%rcx
mov    $0x1,%r9d
call   1040 <pevent_get_field_val@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
js     11e6 <kvm_mmu_get_page_handler+0xb6>
cmpq   $0x0,0x8(%rsp)
lea    0xe94(%rip),%rax
lea    0xe89(%rip),%rdx
cmove  %rax,%rdx
lea    0xe7a(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <trace_seq_printf@plt>
lea    0xe7a(%rip),%rdx
lea    0x8(%rsp),%r8
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rcx
mov    $0x1,%r9d
call   1040 <pevent_get_field_val@plt>
test   %rax,%rax
js     11e6 <kvm_mmu_get_page_handler+0xb6>
mov    0x8(%rsp),%rdx
lea    0xe54(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
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>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
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 = [8 x i8] c"created\00"
@.str.1 = [4 x i8] c"%s \00"
@.str.2 = [4 x i8] c"new\00"
@.str.3 = [9 x i8] c"existing\00"
@.str.4 = [4 x i8] c"gfn\00"
@.str.5 = [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 ([8 x i8], [8 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 %39
17: ; preds = %4
%18 = load %struct.trace_seq*, %struct.trace_seq** %6
%19 = load i64, i64* %10
%20 = icmp ne i64 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0)
%23 = call i32 (%struct.trace_seq*, i8*, ...) @trace_seq_printf(%struct.trace_seq* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load %struct.trace_seq*, %struct.trace_seq** %6
%25 = load %struct.event_format*, %struct.event_format** %8
%26 = load %struct.pevent_record*, %struct.pevent_record** %7
%27 = call i64 @pevent_get_field_val(%struct.trace_seq* %24, %struct.event_format* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), %struct.pevent_record* %26, i64* %10, i32 1)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %17
store i32 -1, i32* %5
br label %39
30: ; preds = %17
%31 = load %struct.trace_seq*, %struct.trace_seq** %6
%32 = load i64, i64* %10
%33 = call i32 (%struct.trace_seq*, i8*, ...) @trace_seq_printf(%struct.trace_seq* %31, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 %32)
%34 = load %struct.trace_seq*, %struct.trace_seq** %6
%35 = load %struct.pevent_record*, %struct.pevent_record** %7
%36 = load %struct.event_format*, %struct.event_format** %8
%37 = load i8*, i8** %9
%38 = call i32 @kvm_mmu_print_role(%struct.trace_seq* %34, %struct.pevent_record* %35, %struct.event_format* %36, i8* %37)
store i32 %38, i32* %5
br label %39
39: ; preds = %30, %29, %16
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
%struct.trace_seq = type { i32 }
%struct.pevent_record = type { i32 }
%struct.event_format = type { i32 }
@.str = [8 x i8] c"created\00"
@.str.1 = [4 x i8] c"%s \00"
@.str.2 = [4 x i8] c"new\00"
@.str.3 = [9 x i8] c"existing\00"
@.str.4 = [4 x i8] c"gfn\00"
@.str.5 = [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 ([8 x i8], [8 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 %20, label %9
9: ; preds = %4
%10 = load i64, i64* %5
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%13 = call i32 (%struct.trace_seq*, i8*, ...) @trace_seq_printf(%struct.trace_seq* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = call i64 @pevent_get_field_val(%struct.trace_seq* %0, %struct.event_format* %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), %struct.pevent_record* %1, i64* %5, i32 1)
%15 = icmp slt i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %9
%17 = load i64, i64* %5
%18 = call i32 (%struct.trace_seq*, i8*, ...) @trace_seq_printf(%struct.trace_seq* %0, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 %17)
%19 = call i32 @kvm_mmu_print_role(%struct.trace_seq* %0, %struct.pevent_record* %1, %struct.event_format* %2, i8* %3)
br label %20
20: ; preds = %9, %4, %16
%21 = phi i32 [ %19, %16 ], [ -1, %4 ], [ -1, %9 ]
ret i32 %21
}