; LLVM IR from SourangshuGhosh/Fluid-Simulation-for-Computer-Graphics :: src (polygonizer3d)

; 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.Polygonizer3d::EdgeGrid" = type { %class.Array3d.1, %class.Array3d.1, %class.Array3d.1 }
%class.Array3d.1 = type <{ i32, i32, i32, [4 x i8], ptr, i8, [3 x i8], i32, i32, [4 x i8] }>
%struct.GridIndex = type { i32, i32, i32 }
%class.Polygonizer3d = type <{ i32, i32, i32, [4 x i8], double, double, ptr, i8, [7 x i8], ptr, i8, [7 x i8] }>

; 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13Polygonizer3d15_polygonizeCellE9GridIndexRNS_8EdgeGridER12TriangleMesh(ptr noundef nonnull align 8 dereferenceable(57), i64, i32, ptr noundef nonnull align 8 dereferenceable(120), ptr noundef nonnull align 8 dereferenceable(232)) #2 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13Polygonizer3d26_calculateSurfaceTrianglesER15GridIndexVectorR12TriangleMesh(ptr noundef nonnull align 8 dereferenceable(57) %0, ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef nonnull align 8 dereferenceable(232) %2) #2 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca %"struct.Polygonizer3d::EdgeGrid", align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca %struct.GridIndex, align 4
  %12 = alloca { i64, i32 }, align 8
  %13 = alloca { i64, i32 }, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %14 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 120, ptr %7) #5
  %15 = getelementptr inbounds %class.Polygonizer3d, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = getelementptr inbounds %class.Polygonizer3d, ptr %14, i32 0, i32 1
  %18 = load i32, ptr %17, align 4, !tbaa !14
  %19 = getelementptr inbounds %class.Polygonizer3d, ptr %14, i32 0, i32 2
  %20 = load i32, ptr %19, align 8, !tbaa !15
  call void @_ZN13Polygonizer3d8EdgeGridC2Eiii(ptr noundef nonnull align 8 dereferenceable(120) %7, i32 noundef %16, i32 noundef %18, i32 noundef %20)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !16
  br label %21

21:                                               ; preds = %44, %3
  %22 = load i32, ptr %8, align 4, !tbaa !16
  %23 = zext i32 %22 to i64
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = invoke noundef i64 @_ZN15GridIndexVector4sizeEv(ptr noundef nonnull align 8 dereferenceable(40) %24)
          to label %26 unwind label %29

26:                                               ; preds = %21
  %27 = icmp ult i64 %23, %25
  br i1 %27, label %33, label %28

28:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %47

29:                                               ; preds = %37, %33, %21
  %30 = landingpad { ptr, i32 }
          cleanup
  %31 = extractvalue { ptr, i32 } %30, 0
  store ptr %31, ptr %9, align 8
  %32 = extractvalue { ptr, i32 } %30, 1
  store i32 %32, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @_ZN13Polygonizer3d8EdgeGridD2Ev(ptr noundef nonnull align 8 dereferenceable(120) %7) #5
  call void @llvm.lifetime.end.p0(i64 120, ptr %7) #5
  br label %48

33:                                               ; preds = %26
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !16
  %36 = invoke { i64, i32 } @_ZN15GridIndexVectorixEi(ptr noundef nonnull align 8 dereferenceable(40) %34, i32 noundef %35)
          to label %37 unwind label %29

37:                                               ; preds = %33
  store { i64, i32 } %36, ptr %12, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 8 %12, i64 12, i1 false)
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %13, ptr align 4 %11, i64 12, i1 false)
  %39 = getelementptr inbounds { i64, i32 }, ptr %13, i32 0, i32 0
  %40 = load i64, ptr %39, align 4
  %41 = getelementptr inbounds { i64, i32 }, ptr %13, i32 0, i32 1
  %42 = load i32, ptr %41, align 4
  invoke void @_ZN13Polygonizer3d15_polygonizeCellE9GridIndexRNS_8EdgeGridER12TriangleMesh(ptr noundef nonnull align 8 dereferenceable(57) %14, i64 %40, i32 %42, ptr noundef nonnull align 8 dereferenceable(120) %7, ptr noundef nonnull align 8 dereferenceable(232) %38)
          to label %43 unwind label %29

43:                                               ; preds = %37
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %8, align 4, !tbaa !16
  %46 = add i32 %45, 1
  store i32 %46, ptr %8, align 4, !tbaa !16
  br label %21, !llvm.loop !17

47:                                               ; preds = %28
  call void @_ZN13Polygonizer3d8EdgeGridD2Ev(ptr noundef nonnull align 8 dereferenceable(120) %7) #5
  call void @llvm.lifetime.end.p0(i64 120, ptr %7) #5
  ret void

48:                                               ; preds = %29
  %49 = load ptr, ptr %9, align 8
  %50 = load i32, ptr %10, align 4
  %51 = insertvalue { ptr, i32 } poison, ptr %49, 0
  %52 = insertvalue { ptr, i32 } %51, i32 %50, 1
  resume { ptr, i32 } %52
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13Polygonizer3d8EdgeGridC2Eiii(ptr noundef nonnull align 8 dereferenceable(120), i32 noundef, i32 noundef, i32 noundef) unnamed_addr #2 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN15GridIndexVector4sizeEv(ptr noundef nonnull align 8 dereferenceable(40)) #3 align 2

declare { i64, i32 } @_ZN15GridIndexVectorixEi(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef) #4

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN13Polygonizer3d8EdgeGridD2Ev(ptr noundef nonnull align 8 dereferenceable(120)) unnamed_addr #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 = { inlinehint mustprogress 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 #4 = { "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 #5 = { 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++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS13Polygonizer3d", !11, i64 0, !11, i64 4, !11, i64 8, !12, i64 16, !12, i64 24, !6, i64 32, !13, i64 40, !6, i64 48, !13, i64 56}
!11 = !{!"int", !7, i64 0}
!12 = !{!"double", !7, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{!10, !11, i64 4}
!15 = !{!10, !11, i64 8}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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.Polygonizer3d::EdgeGrid" = type { %class.Array3d.1, %class.Array3d.1, %class.Array3d.1 }
%class.Array3d.1 = type <{ i32, i32, i32, [4 x i8], ptr, i8, [3 x i8], i32, i32, [4 x i8] }>

; 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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13Polygonizer3d15_polygonizeCellE9GridIndexRNS_8EdgeGridER12TriangleMesh(ptr noundef nonnull align 8 dereferenceable(57), i64, i32, ptr noundef nonnull align 8 dereferenceable(120), ptr noundef nonnull align 8 dereferenceable(232)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN13Polygonizer3d26_calculateSurfaceTrianglesER15GridIndexVectorR12TriangleMesh(ptr noundef nonnull align 8 dereferenceable(57) %0, ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef nonnull align 8 dereferenceable(232) %2) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca %"struct.Polygonizer3d::EdgeGrid", align 8
  call void @llvm.lifetime.start.p0(i64 120, ptr nonnull %4) #4
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !14
  call void @_ZN13Polygonizer3d8EdgeGridC2Eiii(ptr noundef nonnull align 8 dereferenceable(120) %4, i32 noundef %5, i32 noundef %7, i32 noundef %9)
  %10 = call noundef i64 @_ZN15GridIndexVector4sizeEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %.not = icmp eq i64 %10, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %15, %3
  call void @_ZN13Polygonizer3d8EdgeGridD2Ev(ptr noundef nonnull align 8 dereferenceable(120) %4) #4
  call void @llvm.lifetime.end.p0(i64 120, ptr nonnull %4) #4
  ret void

11:                                               ; preds = %14, %.lr.ph
  %12 = landingpad { ptr, i32 }
          cleanup
  call void @_ZN13Polygonizer3d8EdgeGridD2Ev(ptr noundef nonnull align 8 dereferenceable(120) %4) #4
  call void @llvm.lifetime.end.p0(i64 120, ptr nonnull %4) #4
  resume { ptr, i32 } %12

.lr.ph:                                           ; preds = %3, %15
  %.012 = phi i32 [ %16, %15 ], [ 0, %3 ]
  %13 = invoke { i64, i32 } @_ZN15GridIndexVectorixEi(ptr noundef nonnull align 8 dereferenceable(40) %1, i32 noundef %.012)
          to label %14 unwind label %11

14:                                               ; preds = %.lr.ph
  %.fca.0.extract = extractvalue { i64, i32 } %13, 0
  %.fca.1.extract = extractvalue { i64, i32 } %13, 1
  invoke void @_ZN13Polygonizer3d15_polygonizeCellE9GridIndexRNS_8EdgeGridER12TriangleMesh(ptr noundef nonnull align 8 dereferenceable(57) %0, i64 %.fca.0.extract, i32 %.fca.1.extract, ptr noundef nonnull align 8 dereferenceable(120) %4, ptr noundef nonnull align 8 dereferenceable(232) %2)
          to label %15 unwind label %11

15:                                               ; preds = %14
  %16 = add i32 %.012, 1
  %17 = zext i32 %16 to i64
  %18 = call noundef i64 @_ZN15GridIndexVector4sizeEv(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %19 = icmp ugt i64 %18, %17
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !15
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN13Polygonizer3d8EdgeGridC2Eiii(ptr noundef nonnull align 8 dereferenceable(120), i32 noundef, i32 noundef, i32 noundef) unnamed_addr #1 align 2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZN15GridIndexVector4sizeEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #2 align 2

declare { i64, i32 } @_ZN15GridIndexVectorixEi(ptr noundef nonnull align 8 dereferenceable(40), i32 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN13Polygonizer3d8EdgeGridD2Ev(ptr noundef nonnull align 8 dereferenceable(120)) unnamed_addr #2 align 2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { inlinehint mustprogress 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 = { "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 0}
!6 = !{!"_ZTS13Polygonizer3d", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !12, i64 40, !11, i64 48, !12, i64 56}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"double", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!"bool", !8, i64 0}
!13 = !{!6, !7, i64 4}
!14 = !{!6, !7, i64 8}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass