; LLVM IR from frozein/DoonEngine :: src/DoonEngine (voxel)

; 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.DNcompressedVoxel = type { i32, i32 }
%struct.DNivec3 = type { i32, i32, i32 }
%struct.DNvolume = type { i32, i32, i32, %struct.DNuvec3, i64, i64, i64, i64, i64, i64, ptr, ptr, ptr, ptr, ptr, %union.QMvec3, %union.QMvec3, float, i32, %union.QMvec3, %union.QMvec3, %union.QMvec3, i32, i32, float, i8, i32, %union.QMvec3, %union.QMvec3, i32, float }
%struct.DNuvec3 = type { i32, i32, i32 }
%union.QMvec3 = type { [3 x float] }
%struct.DNchunkHandle = type { i8, i32 }
%struct.DNchunk = type { %struct.DNivec3, i8, i32, i32, [8 x [8 x [8 x %struct.DNcompressedVoxel]]] }

; 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) #0

; Function Attrs: nounwind uwtable
define dso_local i64 @DN_get_compressed_voxel(ptr noundef %0, i64 %1, i32 %2, i64 %3, i32 %4) #1 {
  %6 = alloca %struct.DNcompressedVoxel, align 4
  %7 = alloca %struct.DNivec3, align 4
  %8 = alloca { i64, i32 }, align 4
  %9 = alloca %struct.DNivec3, align 4
  %10 = alloca { i64, i32 }, align 4
  %11 = alloca ptr, align 8
  %12 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 0
  store i64 %1, ptr %12, align 4
  %13 = getelementptr inbounds { i64, i32 }, ptr %8, i32 0, i32 1
  store i32 %2, ptr %13, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %8, i64 12, i1 false)
  %14 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 0
  store i64 %3, ptr %14, align 4
  %15 = getelementptr inbounds { i64, i32 }, ptr %10, i32 0, i32 1
  store i32 %4, ptr %15, align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %9, ptr align 4 %10, i64 12, i1 false)
  store ptr %0, ptr %11, align 8, !tbaa !5
  %16 = load ptr, ptr %11, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.DNvolume, ptr %16, i32 0, i32 11
  %18 = load ptr, ptr %17, align 8, !tbaa !9
  %19 = load ptr, ptr %11, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.DNvolume, ptr %19, i32 0, i32 10
  %21 = load ptr, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds %struct.DNivec3, ptr %7, i32 0, i32 0
  %23 = load i32, ptr %22, align 4, !tbaa !17
  %24 = load ptr, ptr %11, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.DNvolume, ptr %24, i32 0, i32 3
  %26 = getelementptr inbounds %struct.DNuvec3, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 4, !tbaa !19
  %28 = getelementptr inbounds %struct.DNivec3, ptr %7, i32 0, i32 1
  %29 = load i32, ptr %28, align 4, !tbaa !20
  %30 = getelementptr inbounds %struct.DNivec3, ptr %7, i32 0, i32 2
  %31 = load i32, ptr %30, align 4, !tbaa !21
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.DNvolume, ptr %32, i32 0, i32 3
  %34 = getelementptr inbounds %struct.DNuvec3, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !22
  %36 = mul i32 %31, %35
  %37 = add i32 %29, %36
  %38 = mul i32 %27, %37
  %39 = add i32 %23, %38
  %40 = zext i32 %39 to i64
  %41 = getelementptr inbounds %struct.DNchunkHandle, ptr %21, i64 %40
  %42 = getelementptr inbounds %struct.DNchunkHandle, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !23
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds %struct.DNchunk, ptr %18, i64 %44
  %46 = getelementptr inbounds %struct.DNchunk, ptr %45, i32 0, i32 4
  %47 = getelementptr inbounds %struct.DNivec3, ptr %9, i32 0, i32 0
  %48 = load i32, ptr %47, align 4, !tbaa !17
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [8 x [8 x [8 x %struct.DNcompressedVoxel]]], ptr %46, i64 0, i64 %49
  %51 = getelementptr inbounds %struct.DNivec3, ptr %9, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !20
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [8 x [8 x %struct.DNcompressedVoxel]], ptr %50, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.DNivec3, ptr %9, i32 0, i32 2
  %56 = load i32, ptr %55, align 4, !tbaa !21
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [8 x %struct.DNcompressedVoxel], ptr %54, i64 0, i64 %57
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 %58, i64 8, i1 false), !tbaa.struct !25
  %59 = load i64, ptr %6, align 4
  ret i64 %59
}

attributes #0 = { nocallback nofree 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" }

!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, !6, i64 80}
!10 = !{!"DNvolume", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 12, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !7, i64 112, !7, i64 124, !14, i64 136, !11, i64 140, !7, i64 144, !7, i64 156, !7, i64 168, !11, i64 180, !11, i64 184, !14, i64 188, !15, i64 192, !11, i64 196, !7, i64 200, !7, i64 212, !11, i64 224, !14, i64 228}
!11 = !{!"int", !7, i64 0}
!12 = !{!"DNuvec3", !11, i64 0, !11, i64 4, !11, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!"_Bool", !7, i64 0}
!16 = !{!10, !6, i64 72}
!17 = !{!18, !11, i64 0}
!18 = !{!"DNivec3", !11, i64 0, !11, i64 4, !11, i64 8}
!19 = !{!10, !11, i64 12}
!20 = !{!18, !11, i64 4}
!21 = !{!18, !11, i64 8}
!22 = !{!10, !11, i64 16}
!23 = !{!24, !11, i64 4}
!24 = !{!"DNchunkHandle", !7, i64 0, !11, i64 4}
!25 = !{i64 0, i64 4, !26, i64 4, i64 4, !26}
!26 = !{!11, !11, 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"

%struct.DNchunkHandle = type { i8, i32 }
%struct.DNchunk = type { %struct.DNivec3, i8, i32, i32, [8 x [8 x [8 x %struct.DNcompressedVoxel]]] }
%struct.DNivec3 = type { i32, i32, i32 }
%struct.DNcompressedVoxel = type { i32, i32 }

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local i64 @DN_get_compressed_voxel(ptr nocapture noundef readonly %0, i64 %1, i32 %2, i64 %3, i32 %4) local_unnamed_addr #0 {
  %.sroa.08.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.29.0.extract.shift = lshr i64 %1, 32
  %.sroa.29.0.extract.trunc = trunc nuw i64 %.sroa.29.0.extract.shift to i32
  %6 = getelementptr inbounds i8, ptr %0, i64 80
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 72
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %0, i64 12
  %11 = load i32, ptr %10, align 4, !tbaa !16
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load i32, ptr %12, align 4, !tbaa !17
  %14 = mul i32 %13, %2
  %15 = add i32 %14, %.sroa.29.0.extract.trunc
  %16 = mul i32 %15, %11
  %17 = add i32 %16, %.sroa.08.0.extract.trunc
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds %struct.DNchunkHandle, ptr %9, i64 %18, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !18
  %21 = zext i32 %20 to i64
  %sext = shl i64 %3, 32
  %22 = ashr exact i64 %sext, 32
  %23 = ashr i64 %3, 32
  %24 = sext i32 %4 to i64
  %25 = getelementptr inbounds %struct.DNchunk, ptr %7, i64 %21, i32 4, i64 %22, i64 %23, i64 %24
  %.sroa.011.0.copyload = load i64, ptr %25, align 4
  ret i64 %.sroa.011.0.copyload
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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, !12, i64 80}
!6 = !{!"DNvolume", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 12, !11, i64 24, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !8, i64 112, !8, i64 124, !13, i64 136, !7, i64 140, !8, i64 144, !8, i64 156, !8, i64 168, !7, i64 180, !7, i64 184, !13, i64 188, !14, i64 192, !7, i64 196, !8, i64 200, !8, i64 212, !7, i64 224, !13, i64 228}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"DNuvec3", !7, i64 0, !7, i64 4, !7, i64 8}
!11 = !{!"long", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"float", !8, i64 0}
!14 = !{!"_Bool", !8, i64 0}
!15 = !{!6, !12, i64 72}
!16 = !{!6, !7, i64 12}
!17 = !{!6, !7, i64 16}
!18 = !{!19, !7, i64 4}
!19 = !{!"DNchunkHandle", !8, i64 0, !7, i64 4}


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