; 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"

%struct.shared_cores_data_t = type { i16, i16, i32, i32, i64, i64, ptr, i64, i64, i64, i64, %struct.anon, i32, [6 x i8], i8, i8, i8, i32, %struct.spyware_data_t, %struct.memory_shadowing_pages_t }
%struct.anon = type { i64, i64, i64, i64 }
%struct.spyware_data_t = type { i8, [213 x i8] }
%struct.memory_shadowing_pages_t = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.ivt_entry_t = type { i16, i16 }

@shared_cores_data = external global %struct.shared_cores_data_t, align 8
@__const.setup_int15h_hook.vmcall_opcode = external hidden unnamed_addr constant [3 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @setup_int15h_hook() #1 {
  %1 = alloca ptr, align 8
  %2 = alloca [3 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #4
  store ptr null, ptr %1, align 8, !tbaa !5
  %3 = load ptr, ptr %1, align 8, !tbaa !5
  %4 = getelementptr inbounds %struct.ivt_entry_t, ptr %3, i64 21
  %5 = getelementptr inbounds %struct.ivt_entry_t, ptr %4, i32 0, i32 1
  %6 = load i16, ptr %5, align 1, !tbaa !9
  store i16 %6, ptr @shared_cores_data, align 8, !tbaa !12
  %7 = load ptr, ptr %1, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.ivt_entry_t, ptr %7, i64 21
  %9 = getelementptr inbounds %struct.ivt_entry_t, ptr %8, i32 0, i32 0
  %10 = load i16, ptr %9, align 1, !tbaa !19
  store i16 %10, ptr getelementptr inbounds (%struct.shared_cores_data_t, ptr @shared_cores_data, i32 0, i32 1), align 2, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 3, ptr %2) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %2, ptr align 1 @__const.setup_int15h_hook.vmcall_opcode, i64 3, i1 false)
  %11 = getelementptr inbounds [3 x i8], ptr %2, i64 0, i64 0
  %12 = call ptr @memcpy(ptr noundef inttoptr (i64 20476 to ptr), ptr noundef %11, i32 noundef 3)
  %13 = load ptr, ptr %1, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.ivt_entry_t, ptr %13, i64 21
  %15 = getelementptr inbounds %struct.ivt_entry_t, ptr %14, i32 0, i32 1
  store i16 0, ptr %15, align 1, !tbaa !9
  %16 = load ptr, ptr %1, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.ivt_entry_t, ptr %16, i64 21
  %18 = getelementptr inbounds %struct.ivt_entry_t, ptr %17, i32 0, i32 0
  store i16 20476, ptr %18, align 1, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 3, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #4
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare ptr @memcpy(ptr noundef, ptr noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { 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, !11, i64 2}
!10 = !{!"", !11, i64 0, !11, i64 2}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !11, i64 0}
!13 = !{!"", !11, i64 0, !11, i64 2, !14, i64 4, !14, i64 8, !15, i64 16, !15, i64 24, !6, i64 32, !15, i64 40, !15, i64 48, !15, i64 56, !15, i64 64, !16, i64 72, !14, i64 104, !7, i64 108, !7, i64 114, !7, i64 115, !7, i64 116, !14, i64 120, !17, i64 124, !18, i64 344}
!14 = !{!"int", !7, i64 0}
!15 = !{!"long long", !7, i64 0}
!16 = !{!"", !15, i64 0, !15, i64 8, !15, i64 16, !15, i64 24}
!17 = !{!"", !7, i64 0, !7, i64 1}
!18 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!19 = !{!10, !11, i64 0}
!20 = !{!13, !11, i64 2}


; 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"

%struct.shared_cores_data_t = type { i16, i16, i32, i32, i64, i64, ptr, i64, i64, i64, i64, %struct.anon, i32, [6 x i8], i8, i8, i8, i32, %struct.spyware_data_t, %struct.memory_shadowing_pages_t }
%struct.anon = type { i64, i64, i64, i64 }
%struct.spyware_data_t = type { i8, [213 x i8] }
%struct.memory_shadowing_pages_t = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@shared_cores_data = external local_unnamed_addr global %struct.shared_cores_data_t, align 8
@__const.setup_int15h_hook.vmcall_opcode = external hidden unnamed_addr constant [3 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @setup_int15h_hook() local_unnamed_addr #1 {
  %1 = alloca [3 x i8], align 1
  %2 = load i16, ptr inttoptr (i64 86 to ptr), align 2, !tbaa !5
  store i16 %2, ptr @shared_cores_data, align 8, !tbaa !10
  %3 = load i16, ptr inttoptr (i64 84 to ptr), align 4, !tbaa !18
  store i16 %3, ptr getelementptr inbounds (i8, ptr @shared_cores_data, i64 2), align 2, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %1) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(3) %1, ptr noundef nonnull align 1 dereferenceable(3) @__const.setup_int15h_hook.vmcall_opcode, i64 3, i1 false)
  %4 = call ptr @memcpy(ptr noundef nonnull inttoptr (i64 20476 to ptr), ptr noundef nonnull %1, i32 noundef 3) #4
  store i16 0, ptr inttoptr (i64 86 to ptr), align 2, !tbaa !5
  store i16 20476, ptr inttoptr (i64 84 to ptr), align 4, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %1) #4
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare ptr @memcpy(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 #4 = { 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, !7, i64 2}
!6 = !{!"", !7, i64 0, !7, i64 2}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !7, i64 0}
!11 = !{!"", !7, i64 0, !7, i64 2, !12, i64 4, !12, i64 8, !13, i64 16, !13, i64 24, !14, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !15, i64 72, !12, i64 104, !8, i64 108, !8, i64 114, !8, i64 115, !8, i64 116, !12, i64 120, !16, i64 124, !17, i64 344}
!12 = !{!"int", !8, i64 0}
!13 = !{!"long long", !8, i64 0}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!"", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24}
!16 = !{!"", !8, i64 0, !8, i64 1}
!17 = !{!"", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56}
!18 = !{!6, !7, i64 0}
!19 = !{!11, !7, i64 2}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,SROAPass