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

; 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 hidden void @_DN_clear_chunk(ptr noundef, i32 noundef) #2

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

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


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

; Function Attrs: nounwind uwtable
declare hidden void @_DN_clear_chunk(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @DN_remove_chunk(ptr noundef %0, i64 %1, i32 %2) local_unnamed_addr #0 {
  %.sroa.09.0.extract.trunc = trunc i64 %1 to i32
  %.sroa.210.0.extract.shift = lshr i64 %1, 32
  %.sroa.210.0.extract.trunc = trunc nuw i64 %.sroa.210.0.extract.shift to i32
  %4 = getelementptr inbounds i8, ptr %0, i64 12
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 4, !tbaa !15
  %8 = mul i32 %7, %2
  %9 = add i32 %8, %.sroa.210.0.extract.trunc
  %10 = mul i32 %9, %5
  %11 = add i32 %10, %.sroa.09.0.extract.trunc
  %12 = getelementptr inbounds i8, ptr %0, i64 72
  %13 = load ptr, ptr %12, align 8, !tbaa !16
  %14 = sext i32 %11 to i64
  %15 = getelementptr inbounds %struct.DNchunkHandle, ptr %13, i64 %14
  store i8 0, ptr %15, align 4, !tbaa !17
  %16 = getelementptr inbounds %struct.DNchunkHandle, ptr %13, i64 %14, i32 1
  %17 = load i32, ptr %16, align 4, !tbaa !19
  %18 = zext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  store i64 %18, ptr %19, align 8, !tbaa !20
  tail call void @_DN_clear_chunk(ptr noundef %0, i32 noundef %17)
  ret void
}

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, !7, i64 12}
!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 16}
!16 = !{!6, !12, i64 72}
!17 = !{!18, !8, i64 0}
!18 = !{!"DNchunkHandle", !8, i64 0, !7, i64 4}
!19 = !{!18, !7, i64 4}
!20 = !{!6, !11, i64 32}


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