; LLVM IR from niessner/Matterport :: code/gaps/pkgs/R2Shapes/R2Grid.ll (ZN6R2GridC2EiiRK5R2Box)

; 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.R2Grid = type { %class.R2Affine, %class.R2Affine, double, ptr, [2 x i32], i32, i32 }
%class.R2Affine = type <{ %class.R2Transformation, %class.R3Matrix, i32, [4 x i8] }>
%class.R2Transformation = type { ptr }
%class.R3Matrix = type { [3 x [3 x double]] }

@.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 @_ZN8R2AffineC1Ev(ptr noundef nonnull align 8 dereferenceable(84)) 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 @_ZN16R2TransformationD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R2GridC2EiiRK5R2Box(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %1, i32 noundef %2, ptr noundef nonnull align 8 dereferenceable(40) %3) unnamed_addr #5 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  %13 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 0
  call void @_ZN8R2AffineC1Ev(ptr noundef nonnull align 8 dereferenceable(84) %13)
  %14 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 1
  invoke void @_ZN8R2AffineC1Ev(ptr noundef nonnull align 8 dereferenceable(84) %14)
          to label %15 unwind label %34

15:                                               ; preds = %4
  %16 = load i32, ptr %6, align 4, !tbaa !9
  %17 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 4
  %18 = getelementptr inbounds [2 x i32], ptr %17, i64 0, i64 0
  store i32 %16, ptr %18, align 8, !tbaa !9
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 4
  %21 = getelementptr inbounds [2 x i32], ptr %20, i64 0, i64 1
  store i32 %19, ptr %21, align 4, !tbaa !9
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 5
  store i32 %22, ptr %23, align 8, !tbaa !11
  %24 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 5
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = mul nsw i32 %25, %26
  %28 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 6
  store i32 %27, ptr %28, align 4, !tbaa !17
  %29 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 6
  %30 = load i32, ptr %29, align 4, !tbaa !17
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %38

32:                                               ; preds = %15
  %33 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 3
  store ptr null, ptr %33, align 8, !tbaa !18
  br label %53

34:                                               ; preds = %4
  %35 = landingpad { ptr, i32 }
          cleanup
  %36 = extractvalue { ptr, i32 } %35, 0
  store ptr %36, ptr %9, align 8
  %37 = extractvalue { ptr, i32 } %35, 1
  store i32 %37, ptr %10, align 4
  br label %82

38:                                               ; preds = %15
  %39 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 6
  %40 = load i32, ptr %39, align 4, !tbaa !17
  %41 = sext i32 %40 to i64
  %42 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %41, i64 8)
  %43 = extractvalue { i64, i1 } %42, 1
  %44 = extractvalue { i64, i1 } %42, 0
  %45 = select i1 %43, i64 -1, i64 %44
  %46 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %45) #6
          to label %47 unwind label %49

47:                                               ; preds = %38
  %48 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 3
  store ptr %46, ptr %48, align 8, !tbaa !18
  br label %53

49:                                               ; preds = %79, %61, %38
  %50 = landingpad { ptr, i32 }
          cleanup
  %51 = extractvalue { ptr, i32 } %50, 0
  store ptr %51, ptr %9, align 8
  %52 = extractvalue { ptr, i32 } %50, 1
  store i32 %52, ptr %10, align 4
  call void @_ZN16R2TransformationD2Ev(ptr noundef nonnull align 8 dereferenceable(84) %14) #7
  br label %82

53:                                               ; preds = %47, %32
  %54 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 6
  %55 = load i32, ptr %54, align 4, !tbaa !17
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %63

57:                                               ; preds = %53
  %58 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 3
  %59 = load ptr, ptr %58, align 8, !tbaa !18
  %60 = icmp ne ptr %59, null
  br i1 %60, label %63, label %61

61:                                               ; preds = %57
  invoke void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 56, ptr noundef @.str.2)
          to label %62 unwind label %49

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62, %57, %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #7
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %64

64:                                               ; preds = %76, %63
  %65 = load i32, ptr %11, align 4, !tbaa !9
  %66 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 6
  %67 = load i32, ptr %66, align 4, !tbaa !17
  %68 = icmp slt i32 %65, %67
  br i1 %68, label %70, label %69

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

70:                                               ; preds = %64
  %71 = getelementptr inbounds %class.R2Grid, ptr %12, i32 0, i32 3
  %72 = load ptr, ptr %71, align 8, !tbaa !18
  %73 = load i32, ptr %11, align 4, !tbaa !9
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds double, ptr %72, i64 %74
  store double 0.000000e+00, ptr %75, align 8, !tbaa !19
  br label %76

76:                                               ; preds = %70
  %77 = load i32, ptr %11, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %11, align 4, !tbaa !9
  br label %64, !llvm.loop !20

79:                                               ; preds = %69
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  invoke void @_ZN6R2Grid28SetWorldToGridTransformationERK5R2Box(ptr noundef nonnull align 8 dereferenceable(208) %12, ptr noundef nonnull align 8 dereferenceable(40) %80)
          to label %81 unwind label %49

81:                                               ; preds = %79
  ret void

82:                                               ; preds = %49, %34
  call void @_ZN16R2TransformationD2Ev(ptr noundef nonnull align 8 dereferenceable(84) %13) #7
  br label %83

83:                                               ; preds = %82
  %84 = load ptr, ptr %9, align 8
  %85 = load i32, ptr %10, align 4
  %86 = insertvalue { ptr, i32 } poison, ptr %84, 0
  %87 = insertvalue { ptr, i32 } %86, i32 %85, 1
  resume { ptr, i32 } %87
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6R2Grid28SetWorldToGridTransformationERK5R2Box(ptr noundef nonnull align 8 dereferenceable(208), ptr noundef nonnull align 8 dereferenceable(40)) #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 200}
!12 = !{!"_ZTS6R2Grid", !13, i64 0, !13, i64 88, !16, i64 176, !6, i64 184, !7, i64 192, !10, i64 200, !10, i64 204}
!13 = !{!"_ZTS8R2Affine", !14, i64 0, !15, i64 8, !10, i64 80}
!14 = !{!"_ZTS16R2Transformation"}
!15 = !{!"_ZTS8R3Matrix", !7, i64 0}
!16 = !{!"double", !7, i64 0}
!17 = !{!12, !10, i64 204}
!18 = !{!12, !6, i64 184}
!19 = !{!16, !16, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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 @_ZN8R2AffineC1Ev(ptr noundef nonnull align 8 dereferenceable(84)) 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 @_ZN16R2TransformationD2Ev(ptr noundef nonnull align 8 dereferenceable(8)) unnamed_addr #2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R2GridC2EiiRK5R2Box(ptr noundef nonnull align 8 dereferenceable(208) %0, i32 noundef %1, i32 noundef %2, ptr noundef nonnull align 8 dereferenceable(40) %3) unnamed_addr #3 align 2 personality ptr @__gxx_personality_v0 {
  tail call void @_ZN8R2AffineC1Ev(ptr noundef nonnull align 8 dereferenceable(84) %0)
  %5 = getelementptr inbounds i8, ptr %0, i64 88
  invoke void @_ZN8R2AffineC1Ev(ptr noundef nonnull align 8 dereferenceable(84) %5)
          to label %6 unwind label %14

6:                                                ; preds = %4
  %7 = getelementptr inbounds i8, ptr %0, i64 192
  store i32 %1, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 196
  store i32 %2, ptr %8, align 4, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 200
  store i32 %1, ptr %9, align 8, !tbaa !9
  %10 = mul nsw i32 %2, %1
  %11 = getelementptr inbounds i8, ptr %0, i64 204
  store i32 %10, ptr %11, align 4, !tbaa !16
  %12 = icmp eq i32 %10, 0
  br i1 %12, label %.thread21, label %16

.thread21:                                        ; preds = %6
  %13 = getelementptr inbounds i8, ptr %0, i64 184
  store ptr null, ptr %13, align 8, !tbaa !17
  br label %._crit_edge

14:                                               ; preds = %4
  %15 = landingpad { ptr, i32 }
          cleanup
  br label %30

16:                                               ; preds = %6
  %17 = zext nneg i32 %10 to i64
  %18 = icmp slt i32 %10, 0
  %19 = shl nuw nsw i64 %17, 3
  %20 = select i1 %18, i64 -1, i64 %19
  %21 = invoke noalias noundef nonnull ptr @_Znam(i64 noundef %20) #5
          to label %24 unwind label %22

22:                                               ; preds = %._crit_edge, %16
  %23 = landingpad { ptr, i32 }
          cleanup
  tail call void @_ZN16R2TransformationD2Ev(ptr noundef nonnull align 8 dereferenceable(84) %5) #6
  br label %30

24:                                               ; preds = %16
  %25 = getelementptr inbounds i8, ptr %0, i64 184
  store ptr %21, ptr %25, align 8, !tbaa !17
  %26 = icmp sgt i32 %10, 0
  br i1 %26, label %.lr.ph, label %._crit_edge

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

._crit_edge:                                      ; preds = %.thread21, %.lr.ph, %24
  invoke void @_ZN6R2Grid28SetWorldToGridTransformationERK5R2Box(ptr noundef nonnull align 8 dereferenceable(208) %0, ptr noundef nonnull align 8 dereferenceable(40) %3)
          to label %29 unwind label %22

29:                                               ; preds = %._crit_edge
  ret void

30:                                               ; preds = %22, %14
  %.pn = phi { ptr, i32 } [ %23, %22 ], [ %15, %14 ]
  tail call void @_ZN16R2TransformationD2Ev(ptr noundef nonnull align 8 dereferenceable(84) %0) #6
  resume { ptr, i32 } %.pn
}

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN6R2Grid28SetWorldToGridTransformationERK5R2Box(ptr noundef nonnull align 8 dereferenceable(208), ptr noundef nonnull align 8 dereferenceable(40)) 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 200}
!10 = !{!"_ZTS6R2Grid", !11, i64 0, !11, i64 88, !14, i64 176, !15, i64 184, !7, i64 192, !6, i64 200, !6, i64 204}
!11 = !{!"_ZTS8R2Affine", !12, i64 0, !13, i64 8, !6, i64 80}
!12 = !{!"_ZTS16R2Transformation"}
!13 = !{!"_ZTS8R3Matrix", !7, i64 0}
!14 = !{!"double", !7, i64 0}
!15 = !{!"any pointer", !7, i64 0}
!16 = !{!10, !6, i64 204}
!17 = !{!10, !15, i64 184}
!18 = !{!14, !14, i64 0}


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