; 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.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]]] }
%struct.DNcompressedVoxel = type { i32, i32 }

; 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: 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) #1

; Function Attrs: nounwind uwtable
declare dso_local void @DN_remove_chunk(ptr noundef, i64, i32) #2

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

55:                                               ; preds = %5
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.DNvolume, ptr %56, i32 0, i32 11
  %58 = load ptr, ptr %57, align 8, !tbaa !25
  %59 = load i32, ptr %11, align 4, !tbaa !24
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds %struct.DNchunk, ptr %58, i64 %60
  %62 = getelementptr inbounds %struct.DNchunk, ptr %61, i32 0, i32 2
  %63 = load i32, ptr %62, align 4, !tbaa !26
  %64 = add i32 %63, -1
  store i32 %64, ptr %62, align 4, !tbaa !26
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.DNvolume, ptr %65, i32 0, i32 11
  %67 = load ptr, ptr %66, align 8, !tbaa !25
  %68 = load i32, ptr %11, align 4, !tbaa !24
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds %struct.DNchunk, ptr %67, i64 %69
  %71 = getelementptr inbounds %struct.DNchunk, ptr %70, i32 0, i32 2
  %72 = load i32, ptr %71, align 4, !tbaa !26
  %73 = icmp ule i32 %72, 0
  br i1 %73, label %74, label %80

74:                                               ; preds = %55
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %14, ptr align 4 %6, i64 12, i1 false)
  %76 = getelementptr inbounds { i64, i32 }, ptr %14, i32 0, i32 0
  %77 = load i64, ptr %76, align 4
  %78 = getelementptr inbounds { i64, i32 }, ptr %14, i32 0, i32 1
  %79 = load i32, ptr %78, align 4
  call void @DN_remove_chunk(ptr noundef %75, i64 %77, i32 %79)
  store i32 1, ptr %15, align 4
  br label %109

80:                                               ; preds = %55
  br label %81

81:                                               ; preds = %80, %5
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.DNvolume, ptr %82, i32 0, i32 11
  %84 = load ptr, ptr %83, align 8, !tbaa !25
  %85 = load i32, ptr %11, align 4, !tbaa !24
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds %struct.DNchunk, ptr %84, i64 %86
  %88 = getelementptr inbounds %struct.DNchunk, ptr %87, i32 0, i32 4
  %89 = getelementptr inbounds %struct.DNivec3, ptr %8, i32 0, i32 0
  %90 = load i32, ptr %89, align 4, !tbaa !16
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [8 x [8 x [8 x %struct.DNcompressedVoxel]]], ptr %88, i64 0, i64 %91
  %93 = getelementptr inbounds %struct.DNivec3, ptr %8, i32 0, i32 1
  %94 = load i32, ptr %93, align 4, !tbaa !19
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [8 x [8 x %struct.DNcompressedVoxel]], ptr %92, i64 0, i64 %95
  %97 = getelementptr inbounds %struct.DNivec3, ptr %8, i32 0, i32 2
  %98 = load i32, ptr %97, align 4, !tbaa !20
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [8 x %struct.DNcompressedVoxel], ptr %96, i64 0, i64 %99
  %101 = getelementptr inbounds %struct.DNcompressedVoxel, ptr %100, i32 0, i32 0
  store i32 -1, ptr %101, align 4, !tbaa !28
  %102 = load ptr, ptr %10, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.DNvolume, ptr %102, i32 0, i32 11
  %104 = load ptr, ptr %103, align 8, !tbaa !25
  %105 = load i32, ptr %11, align 4, !tbaa !24
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds %struct.DNchunk, ptr %104, i64 %106
  %108 = getelementptr inbounds %struct.DNchunk, ptr %107, i32 0, i32 1
  store i8 1, ptr %108, align 4, !tbaa !30
  store i32 0, ptr %15, align 4
  br label %109

109:                                              ; preds = %81, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  %110 = load i32, ptr %15, align 4
  switch i32 %110, label %112 [
    i32 0, label %111
    i32 1, label %111
  ]

111:                                              ; preds = %109, %109
  ret void

112:                                              ; preds = %109
  unreachable
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @DN_does_voxel_exist(ptr noundef, i64, i32, i64, i32) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !6, i64 72}
!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 = !{!17, !11, i64 0}
!17 = !{!"DNivec3", !11, i64 0, !11, i64 4, !11, i64 8}
!18 = !{!10, !11, i64 12}
!19 = !{!17, !11, i64 4}
!20 = !{!17, !11, i64 8}
!21 = !{!10, !11, i64 16}
!22 = !{!23, !11, i64 4}
!23 = !{!"DNchunkHandle", !7, i64 0, !11, i64 4}
!24 = !{!11, !11, i64 0}
!25 = !{!10, !6, i64 80}
!26 = !{!27, !11, i64 16}
!27 = !{!"DNchunk", !17, i64 0, !15, i64 12, !11, i64 16, !11, i64 20, !7, i64 24}
!28 = !{!29, !11, i64 0}
!29 = !{!"DNcompressedVoxel", !11, i64 0, !11, i64 4}
!30 = !{!27, !15, i64 12}


; 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: nounwind uwtable
declare dso_local void @DN_remove_chunk(ptr noundef, i64, i32) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @DN_remove_voxel(ptr noundef %0, i64 %1, i32 %2, i64 %3, i32 %4) local_unnamed_addr #0 {
  %.sroa.022.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.426.0.extract.shift = lshr i64 %1, 32
  %.sroa.426.0.extract.trunc = trunc nuw i64 %.sroa.426.0.extract.shift to i32
  %6 = getelementptr inbounds i8, ptr %0, i64 72
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 12
  %9 = load i32, ptr %8, align 4, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i32, ptr %10, align 4, !tbaa !16
  %12 = mul i32 %11, %2
  %13 = add i32 %12, %.sroa.426.0.extract.trunc
  %14 = mul i32 %13, %9
  %15 = add i32 %14, %.sroa.022.0.extract.trunc
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds %struct.DNchunkHandle, ptr %7, i64 %16, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !17
  %19 = tail call zeroext i1 @DN_does_voxel_exist(ptr noundef %0, i64 %1, i32 %2, i64 %3, i32 %4)
  %20 = getelementptr inbounds i8, ptr %0, i64 80
  %21 = load ptr, ptr %20, align 8, !tbaa !19
  %22 = sext i32 %18 to i64
  br i1 %19, label %23, label %._crit_edge

23:                                               ; preds = %5
  %24 = getelementptr inbounds %struct.DNchunk, ptr %21, i64 %22, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !20
  %26 = add i32 %25, -1
  store i32 %26, ptr %24, align 4, !tbaa !20
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %._crit_edge

28:                                               ; preds = %23
  tail call void @DN_remove_chunk(ptr noundef nonnull %0, i64 %1, i32 %2)
  br label %34

._crit_edge:                                      ; preds = %5, %23
  %sext = shl i64 %3, 32
  %29 = ashr exact i64 %sext, 32
  %30 = ashr i64 %3, 32
  %31 = sext i32 %4 to i64
  %32 = getelementptr inbounds %struct.DNchunk, ptr %21, i64 %22, i32 4, i64 %29, i64 %30, i64 %31
  store i32 -1, ptr %32, align 4, !tbaa !23
  %33 = getelementptr inbounds %struct.DNchunk, ptr %21, i64 %22, i32 1
  store i8 1, ptr %33, align 4, !tbaa !25
  br label %34

34:                                               ; preds = %._crit_edge, %28
  ret void
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @DN_does_voxel_exist(ptr noundef, i64, i32, i64, i32) local_unnamed_addr #0

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

!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 72}
!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, !7, i64 12}
!16 = !{!6, !7, i64 16}
!17 = !{!18, !7, i64 4}
!18 = !{!"DNchunkHandle", !8, i64 0, !7, i64 4}
!19 = !{!6, !12, i64 80}
!20 = !{!21, !7, i64 16}
!21 = !{!"DNchunk", !22, i64 0, !14, i64 12, !7, i64 16, !7, i64 20, !8, i64 24}
!22 = !{!"DNivec3", !7, i64 0, !7, i64 4, !7, i64 8}
!23 = !{!24, !7, i64 0}
!24 = !{!"DNcompressedVoxel", !7, i64 0, !7, i64 4}
!25 = !{!21, !14, i64 12}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass