; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R3Shapes/R3Grid.ll (ZN6R3GridC2EiiiRK5R3Box)

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

%class.R3Grid = type { %class.R3Affine, %class.R3Affine, double, double, ptr, [3 x i32], i32, i32, i32 }
%class.R3Affine = type { %class.R3Transformation, %class.R4Matrix, %class.R4Matrix, %class.RNFlags }
%class.R3Transformation = type { ptr }
%class.R4Matrix = type { [4 x [4 x double]] }
%class.RNFlags = type { i64 }

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [88 x i8], align 1

declare void @_ZN8R3AffineC1Ev(ptr noundef nonnull align 8 dereferenceable(272)) unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #1

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #2

declare void @_Z7RNAbortPKcz(ptr noundef, ...) #0

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

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

; Function Attrs: nounwind
declare void @_ZN8R3AffineD1Ev(ptr noundef nonnull align 8 dereferenceable(272)) unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R3GridC2EiiiRK5R3Box(ptr noundef nonnull align 8 dereferenceable(592) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 8 dereferenceable(56) %4) unnamed_addr #5 align 2 personality ptr @__gxx_personality_v0 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  %14 = load ptr, ptr %6, align 8
  %15 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 0
  call void @_ZN8R3AffineC1Ev(ptr noundef nonnull align 8 dereferenceable(272) %15)
  %16 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 1
  invoke void @_ZN8R3AffineC1Ev(ptr noundef nonnull align 8 dereferenceable(272) %16)
          to label %17 unwind label %44

17:                                               ; preds = %5
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 5
  %20 = getelementptr inbounds [3 x i32], ptr %19, i64 0, i64 0
  store i32 %18, ptr %20, align 8, !tbaa !9
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 5
  %23 = getelementptr inbounds [3 x i32], ptr %22, i64 0, i64 1
  store i32 %21, ptr %23, align 4, !tbaa !9
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 5
  %26 = getelementptr inbounds [3 x i32], ptr %25, i64 0, i64 2
  store i32 %24, ptr %26, align 8, !tbaa !9
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 6
  store i32 %27, ptr %28, align 4, !tbaa !11
  %29 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 6
  %30 = load i32, ptr %29, align 4, !tbaa !11
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = mul nsw i32 %30, %31
  %33 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 7
  store i32 %32, ptr %33, align 8, !tbaa !19
  %34 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 7
  %35 = load i32, ptr %34, align 8, !tbaa !19
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = mul nsw i32 %35, %36
  %38 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 8
  store i32 %37, ptr %38, align 4, !tbaa !20
  %39 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 8
  %40 = load i32, ptr %39, align 4, !tbaa !20
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %42, label %48

42:                                               ; preds = %17
  %43 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 4
  store ptr null, ptr %43, align 8, !tbaa !21
  br label %63

44:                                               ; preds = %5
  %45 = landingpad { ptr, i32 }
          cleanup
  %46 = extractvalue { ptr, i32 } %45, 0
  store ptr %46, ptr %11, align 8
  %47 = extractvalue { ptr, i32 } %45, 1
  store i32 %47, ptr %12, align 4
  br label %92

48:                                               ; preds = %17
  %49 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 8
  %50 = load i32, ptr %49, align 4, !tbaa !20
  %51 = sext i32 %50 to i64
  %52 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %51, i64 8)
  %53 = extractvalue { i64, i1 } %52, 1
  %54 = extractvalue { i64, i1 } %52, 0
  %55 = select i1 %53, i64 -1, i64 %54
  %56 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %55) #6
          to label %57 unwind label %59

57:                                               ; preds = %48
  %58 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 4
  store ptr %56, ptr %58, align 8, !tbaa !21
  br label %63

59:                                               ; preds = %89, %71, %48
  %60 = landingpad { ptr, i32 }
          cleanup
  %61 = extractvalue { ptr, i32 } %60, 0
  store ptr %61, ptr %11, align 8
  %62 = extractvalue { ptr, i32 } %60, 1
  store i32 %62, ptr %12, align 4
  call void @_ZN8R3AffineD1Ev(ptr noundef nonnull align 8 dereferenceable(272) %16) #7
  br label %92

63:                                               ; preds = %57, %42
  %64 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 8
  %65 = load i32, ptr %64, align 4, !tbaa !20
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %73

67:                                               ; preds = %63
  %68 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 4
  %69 = load ptr, ptr %68, align 8, !tbaa !21
  %70 = icmp ne ptr %69, null
  br i1 %70, label %73, label %71

71:                                               ; preds = %67
  invoke void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 68, ptr noundef @.str.2)
          to label %72 unwind label %59

72:                                               ; preds = %71
  br label %73

73:                                               ; preds = %72, %67, %63
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %86, %73
  %75 = load i32, ptr %13, align 4, !tbaa !9
  %76 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 8
  %77 = load i32, ptr %76, align 4, !tbaa !20
  %78 = icmp slt i32 %75, %77
  br i1 %78, label %80, label %79

79:                                               ; preds = %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  br label %89

80:                                               ; preds = %74
  %81 = getelementptr inbounds %class.R3Grid, ptr %14, i32 0, i32 4
  %82 = load ptr, ptr %81, align 8, !tbaa !21
  %83 = load i32, ptr %13, align 4, !tbaa !9
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds double, ptr %82, i64 %84
  store double 0.000000e+00, ptr %85, align 8, !tbaa !22
  br label %86

86:                                               ; preds = %80
  %87 = load i32, ptr %13, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %13, align 4, !tbaa !9
  br label %74, !llvm.loop !23

89:                                               ; preds = %79
  %90 = load ptr, ptr %10, align 8, !tbaa !5
  invoke void @_ZN6R3Grid28SetWorldToGridTransformationERK5R3Box(ptr noundef nonnull align 8 dereferenceable(592) %14, ptr noundef nonnull align 8 dereferenceable(56) %90)
          to label %91 unwind label %59

91:                                               ; preds = %89
  ret void

92:                                               ; preds = %59, %44
  call void @_ZN8R3AffineD1Ev(ptr noundef nonnull align 8 dereferenceable(272) %15) #7
  br label %93

93:                                               ; preds = %92
  %94 = load ptr, ptr %11, align 8
  %95 = load i32, ptr %12, align 4
  %96 = insertvalue { ptr, i32 } poison, ptr %94, 0
  %97 = insertvalue { ptr, i32 } %96, i32 %95, 1
  resume { ptr, i32 } %97
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6R3Grid28SetWorldToGridTransformationERK5R3Box(ptr noundef nonnull align 8 dereferenceable(592), ptr noundef nonnull align 8 dereferenceable(56)) #5 align 2

attributes #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 #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nobuiltin allocsize(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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind "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 = { 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 #6 = { builtin allocsize(0) }
attributes #7 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 580}
!12 = !{!"_ZTS6R3Grid", !13, i64 0, !13, i64 272, !18, i64 544, !18, i64 552, !6, i64 560, !7, i64 568, !10, i64 580, !10, i64 584, !10, i64 588}
!13 = !{!"_ZTS8R3Affine", !14, i64 0, !15, i64 8, !15, i64 136, !16, i64 264}
!14 = !{!"_ZTS16R3Transformation"}
!15 = !{!"_ZTS8R4Matrix", !7, i64 0}
!16 = !{!"_ZTS7RNFlags", !17, i64 0}
!17 = !{!"long", !7, i64 0}
!18 = !{!"double", !7, i64 0}
!19 = !{!12, !10, i64 584}
!20 = !{!12, !10, i64 588}
!21 = !{!12, !6, i64 560}
!22 = !{!18, !18, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"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"

declare void @_ZN8R3AffineC1Ev(ptr noundef nonnull align 8 dereferenceable(272)) unnamed_addr #0

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare void @_ZN8R3AffineD1Ev(ptr noundef nonnull align 8 dereferenceable(272)) unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R3GridC2EiiiRK5R3Box(ptr noundef nonnull align 8 dereferenceable(592) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef nonnull align 8 dereferenceable(56) %4) unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN8R3AffineC1Ev(ptr noundef nonnull align 8 dereferenceable(272) %0)
  %6 = getelementptr inbounds i8, ptr %0, i64 272
  invoke void @_ZN8R3AffineC1Ev(ptr noundef nonnull align 8 dereferenceable(272) %6)
          to label %7 unwind label %18

7:                                                ; preds = %5
  %8 = getelementptr inbounds i8, ptr %0, i64 568
  store i32 %1, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 572
  store i32 %2, ptr %9, align 4, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 576
  store i32 %3, ptr %10, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 580
  store i32 %1, ptr %11, align 4, !tbaa !9
  %12 = mul nsw i32 %2, %1
  %13 = getelementptr inbounds i8, ptr %0, i64 584
  store i32 %12, ptr %13, align 8, !tbaa !18
  %14 = mul nsw i32 %12, %3
  %15 = getelementptr inbounds i8, ptr %0, i64 588
  store i32 %14, ptr %15, align 4, !tbaa !19
  %16 = icmp eq i32 %14, 0
  br i1 %16, label %.thread23, label %20

.thread23:                                        ; preds = %7
  %17 = getelementptr inbounds i8, ptr %0, i64 560
  store ptr null, ptr %17, align 8, !tbaa !20
  br label %._crit_edge

18:                                               ; preds = %5
  %19 = landingpad { ptr, i32 }
          cleanup
  br label %34

20:                                               ; preds = %7
  %21 = zext nneg i32 %14 to i64
  %22 = icmp slt i32 %14, 0
  %23 = shl nuw nsw i64 %21, 3
  %24 = select i1 %22, i64 -1, i64 %23
  %25 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %24) #5
          to label %28 unwind label %26

26:                                               ; preds = %._crit_edge, %20
  %27 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN8R3AffineD1Ev(ptr noundef nonnull align 8 dereferenceable(272) %6) #6
  br label %34

28:                                               ; preds = %20
  %29 = getelementptr inbounds i8, ptr %0, i64 560
  store ptr %25, ptr %29, align 8, !tbaa !20
  %30 = icmp sgt i32 %14, 0
  br i1 %30, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %28
  %31 = zext nneg i32 %14 to i64
  %32 = shl nuw nsw i64 %31, 3
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 %25, i8 0, i64 %32, i1 false), !tbaa !21
  br label %._crit_edge

._crit_edge:                                      ; preds = %.thread23, %.lr.ph, %28
  invoke void @_ZN6R3Grid28SetWorldToGridTransformationERK5R3Box(ptr noundef nonnull align 8 dereferenceable(592) %0, ptr noundef nonnull align 8 dereferenceable(56) %4)
          to label %33 unwind label %26

33:                                               ; preds = %._crit_edge
  ret void

34:                                               ; preds = %26, %18
  %.pn = phi { ptr, i32 } [ %27, %26 ], [ %19, %18 ]
  tail call void @_ZN8R3AffineD1Ev(ptr noundef nonnull align 8 dereferenceable(272) %0) #6
  resume { ptr, i32 } %.pn
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6R3Grid28SetWorldToGridTransformationERK5R3Box(ptr noundef nonnull align 8 dereferenceable(592), ptr noundef nonnull align 8 dereferenceable(56)) local_unnamed_addr #3 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

attributes #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 #1 = { nobuiltin allocsize(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 = { nounwind "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 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { builtin allocsize(0) }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 580}
!10 = !{!"_ZTS6R3Grid", !11, i64 0, !11, i64 272, !16, i64 544, !16, i64 552, !17, i64 560, !7, i64 568, !6, i64 580, !6, i64 584, !6, i64 588}
!11 = !{!"_ZTS8R3Affine", !12, i64 0, !13, i64 8, !13, i64 136, !14, i64 264}
!12 = !{!"_ZTS16R3Transformation"}
!13 = !{!"_ZTS8R4Matrix", !7, i64 0}
!14 = !{!"_ZTS7RNFlags", !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!"any pointer", !7, i64 0}
!18 = !{!10, !6, i64 584}
!19 = !{!10, !6, i64 588}
!20 = !{!10, !17, i64 560}
!21 = !{!16, !16, i64 0}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass