; LLVM IR from gognl/VMBR :: victim/src/hooks (int15h)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
define dso_local void @emulate_iret(ptr noundef %0) #0 section ".vmm" {
  %2 = alloca ptr, align 8
  %3 = alloca i16, align 2
  %4 = alloca i16, align 2
  %5 = alloca i16, align 2
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #3
  %6 = call i64 @__vmread(i32 noundef 26634)
  %7 = call i64 @__vmread(i32 noundef 26652)
  %8 = add i64 %6, %7
  %9 = inttoptr i64 %8 to ptr
  %10 = load i16, ptr %9, align 2, !tbaa !9
  store i16 %10, ptr %3, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %4) #3
  %11 = call i64 @__vmread(i32 noundef 26634)
  %12 = call i64 @__vmread(i32 noundef 26652)
  %13 = add i64 %11, %12
  %14 = add i64 %13, 2
  %15 = inttoptr i64 %14 to ptr
  %16 = load i16, ptr %15, align 2, !tbaa !9
  store i16 %16, ptr %4, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #3
  %17 = call i64 @__vmread(i32 noundef 26634)
  %18 = call i64 @__vmread(i32 noundef 26652)
  %19 = add i64 %17, %18
  %20 = add i64 %19, 4
  %21 = inttoptr i64 %20 to ptr
  %22 = load i16, ptr %21, align 2, !tbaa !9
  store i16 %22, ptr %5, align 2, !tbaa !9
  %23 = load i16, ptr %3, align 2, !tbaa !9
  %24 = zext i16 %23 to i64
  call void @__vmwrite(i32 noundef 26654, i64 noundef %24)
  %25 = load i16, ptr %4, align 2, !tbaa !9
  %26 = zext i16 %25 to i64
  call void @__vmwrite(i32 noundef 2050, i64 noundef %26)
  %27 = load i16, ptr %4, align 2, !tbaa !9
  %28 = zext i16 %27 to i32
  %29 = shl i32 %28, 4
  %30 = sext i32 %29 to i64
  call void @__vmwrite(i32 noundef 26632, i64 noundef %30)
  %31 = call i64 @__vmread(i32 noundef 26656)
  %32 = and i64 %31, -65536
  %33 = load i16, ptr %5, align 2, !tbaa !9
  %34 = zext i16 %33 to i64
  %35 = or i64 %32, %34
  call void @__vmwrite(i32 noundef 26656, i64 noundef %35)
  %36 = call i64 @__vmread(i32 noundef 26652)
  %37 = add i64 %36, 6
  call void @__vmwrite(i32 noundef 26652, i64 noundef %37)
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #3
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: alwaysinline nounwind uwtable
declare i64 @__vmread(i32 noundef) #2

; Function Attrs: alwaysinline nounwind uwtable
declare void @__vmwrite(i32 noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { alwaysinline nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: nounwind uwtable
define dso_local void @emulate_iret(ptr nocapture noundef readnone %0) local_unnamed_addr #0 section ".vmm" {
  %2 = tail call i64 @__vmread(i32 noundef 26634)
  %3 = tail call i64 @__vmread(i32 noundef 26652)
  %4 = add i64 %3, %2
  %5 = inttoptr i64 %4 to ptr
  %6 = load i16, ptr %5, align 2, !tbaa !5
  %7 = tail call i64 @__vmread(i32 noundef 26634)
  %8 = tail call i64 @__vmread(i32 noundef 26652)
  %9 = add i64 %7, 2
  %10 = add i64 %9, %8
  %11 = inttoptr i64 %10 to ptr
  %12 = load i16, ptr %11, align 2, !tbaa !5
  %13 = tail call i64 @__vmread(i32 noundef 26634)
  %14 = tail call i64 @__vmread(i32 noundef 26652)
  %15 = add i64 %13, 4
  %16 = add i64 %15, %14
  %17 = inttoptr i64 %16 to ptr
  %18 = load i16, ptr %17, align 2, !tbaa !5
  %19 = zext i16 %6 to i64
  tail call void @__vmwrite(i32 noundef 26654, i64 noundef %19)
  %20 = zext i16 %12 to i64
  tail call void @__vmwrite(i32 noundef 2050, i64 noundef %20)
  %21 = shl nuw nsw i64 %20, 4
  tail call void @__vmwrite(i32 noundef 26632, i64 noundef %21)
  %22 = tail call i64 @__vmread(i32 noundef 26656)
  %23 = and i64 %22, -65536
  %24 = zext i16 %18 to i64
  %25 = or disjoint i64 %23, %24
  tail call void @__vmwrite(i32 noundef 26656, i64 noundef %25)
  %26 = tail call i64 @__vmread(i32 noundef 26652)
  %27 = add i64 %26, 6
  tail call void @__vmwrite(i32 noundef 26652, i64 noundef %27)
  ret void
}

; Function Attrs: alwaysinline nounwind uwtable
declare i64 @__vmread(i32 noundef) local_unnamed_addr #1

; Function Attrs: alwaysinline nounwind uwtable
declare void @__vmwrite(i32 noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { alwaysinline nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass