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

; 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.2 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [48 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R3Grid8SubtractERKS_(ptr noundef nonnull align 8 dereferenceable(592) %0, ptr noundef nonnull align 8 dereferenceable(592) %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %class.R3Grid, ptr %6, i32 0, i32 5
  %8 = getelementptr inbounds [3 x i32], ptr %7, i64 0, i64 0
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %class.R3Grid, ptr %10, i32 0, i32 5
  %12 = getelementptr inbounds [3 x i32], ptr %11, i64 0, i64 0
  %13 = load i32, ptr %12, align 8, !tbaa !9
  %14 = icmp eq i32 %9, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %2
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.16, i32 noundef 1248, ptr noundef @.str.2)
  br label %16

16:                                               ; preds = %15, %2
  %17 = getelementptr inbounds %class.R3Grid, ptr %6, i32 0, i32 5
  %18 = getelementptr inbounds [3 x i32], ptr %17, i64 0, i64 1
  %19 = load i32, ptr %18, align 4, !tbaa !9
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %class.R3Grid, ptr %20, i32 0, i32 5
  %22 = getelementptr inbounds [3 x i32], ptr %21, i64 0, i64 1
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = icmp eq i32 %19, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %16
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.17, i32 noundef 1249, ptr noundef @.str.2)
  br label %26

26:                                               ; preds = %25, %16
  %27 = getelementptr inbounds %class.R3Grid, ptr %6, i32 0, i32 5
  %28 = getelementptr inbounds [3 x i32], ptr %27, i64 0, i64 2
  %29 = load i32, ptr %28, align 8, !tbaa !9
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %class.R3Grid, ptr %30, i32 0, i32 5
  %32 = getelementptr inbounds [3 x i32], ptr %31, i64 0, i64 2
  %33 = load i32, ptr %32, align 8, !tbaa !9
  %34 = icmp eq i32 %29, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %26
  call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef @.str, ptr noundef @.str.18, i32 noundef 1250, ptr noundef @.str.2)
  br label %36

36:                                               ; preds = %35, %26
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %58, %36
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = getelementptr inbounds %class.R3Grid, ptr %6, i32 0, i32 8
  %40 = load i32, ptr %39, align 4, !tbaa !11
  %41 = icmp slt i32 %38, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %61

43:                                               ; preds = %37
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %class.R3Grid, ptr %44, i32 0, i32 4
  %46 = load ptr, ptr %45, align 8, !tbaa !19
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds double, ptr %46, i64 %48
  %50 = load double, ptr %49, align 8, !tbaa !20
  %51 = getelementptr inbounds %class.R3Grid, ptr %6, i32 0, i32 4
  %52 = load ptr, ptr %51, align 8, !tbaa !19
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds double, ptr %52, i64 %54
  %56 = load double, ptr %55, align 8, !tbaa !20
  %57 = fsub double %56, %50
  store double %57, ptr %55, align 8, !tbaa !20
  br label %58

58:                                               ; preds = %43
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %5, align 4, !tbaa !9
  br label %37, !llvm.loop !21

61:                                               ; preds = %42
  ret void
}

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 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 = { 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 588}
!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, !6, i64 560}
!20 = !{!18, !18, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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"

@.str = external hidden unnamed_addr constant [41 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [88 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [48 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [48 x i8], align 1

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6R3Grid8SubtractERKS_(ptr nocapture noundef nonnull readonly align 8 dereferenceable(592) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(592) %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 568
  %4 = load i32, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %1, i64 568
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = icmp eq i32 %4, %6
  br i1 %7, label %9, label %8

8:                                                ; preds = %2
  tail call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str, ptr noundef nonnull @.str.16, i32 noundef 1248, ptr noundef nonnull @.str.2)
  br label %9

9:                                                ; preds = %8, %2
  %10 = getelementptr inbounds i8, ptr %0, i64 572
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %1, i64 572
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = icmp eq i32 %11, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %9
  tail call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str, ptr noundef nonnull @.str.17, i32 noundef 1249, ptr noundef nonnull @.str.2)
  br label %16

16:                                               ; preds = %15, %9
  %17 = getelementptr inbounds i8, ptr %0, i64 576
  %18 = load i32, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %1, i64 576
  %20 = load i32, ptr %19, align 8, !tbaa !5
  %21 = icmp eq i32 %18, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %16
  tail call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str, ptr noundef nonnull @.str.18, i32 noundef 1250, ptr noundef nonnull @.str.2)
  br label %23

23:                                               ; preds = %22, %16
  %24 = getelementptr inbounds i8, ptr %0, i64 588
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %23
  %27 = getelementptr inbounds i8, ptr %1, i64 560
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = getelementptr inbounds i8, ptr %0, i64 560
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  %wide.trip.count = zext nneg i32 %25 to i64
  %min.iters.check = icmp ult i32 %25, 6
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.memcheck

scalar.ph.preheader:                              ; preds = %middle.block, %vector.memcheck, %.lr.ph
  %indvars.iv.ph = phi i64 [ 0, %vector.memcheck ], [ 0, %.lr.ph ], [ %n.vec, %middle.block ]
  %xtraiter = and i64 %wide.trip.count, 3
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol

scalar.ph.prol:                                   ; preds = %scalar.ph.preheader, %scalar.ph.prol
  %indvars.iv.prol = phi i64 [ %indvars.iv.next.prol, %scalar.ph.prol ], [ %indvars.iv.ph, %scalar.ph.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %scalar.ph.prol ], [ 0, %scalar.ph.preheader ]
  %31 = getelementptr inbounds double, ptr %28, i64 %indvars.iv.prol
  %32 = load double, ptr %31, align 8, !tbaa !19
  %33 = getelementptr inbounds double, ptr %30, i64 %indvars.iv.prol
  %34 = load double, ptr %33, align 8, !tbaa !19
  %35 = fsub double %34, %32
  store double %35, ptr %33, align 8, !tbaa !19
  %indvars.iv.next.prol = add nuw nsw i64 %indvars.iv.prol, 1
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %scalar.ph.prol.loopexit, label %scalar.ph.prol, !llvm.loop !20

scalar.ph.prol.loopexit:                          ; preds = %scalar.ph.prol, %scalar.ph.preheader
  %indvars.iv.unr = phi i64 [ %indvars.iv.ph, %scalar.ph.preheader ], [ %indvars.iv.next.prol, %scalar.ph.prol ]
  %36 = sub nsw i64 %indvars.iv.ph, %wide.trip.count
  %37 = icmp ugt i64 %36, -4
  br i1 %37, label %._crit_edge, label %scalar.ph

vector.memcheck:                                  ; preds = %.lr.ph
  %38 = shl nuw nsw i64 %wide.trip.count, 3
  %scevgep = getelementptr i8, ptr %30, i64 %38
  %scevgep10 = getelementptr i8, ptr %28, i64 %38
  %bound0 = icmp ult ptr %30, %scevgep10
  %bound1 = icmp ult ptr %28, %scevgep
  %found.conflict = and i1 %bound0, %bound1
  br i1 %found.conflict, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %vector.memcheck
  %n.vec = and i64 %wide.trip.count, 2147483644
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %39 = getelementptr inbounds double, ptr %28, i64 %index
  %40 = getelementptr inbounds i8, ptr %39, i64 16
  %wide.load = load <2 x double>, ptr %39, align 8, !tbaa !19, !alias.scope !22
  %wide.load11 = load <2 x double>, ptr %40, align 8, !tbaa !19, !alias.scope !22
  %41 = getelementptr inbounds double, ptr %30, i64 %index
  %42 = getelementptr inbounds i8, ptr %41, i64 16
  %wide.load12 = load <2 x double>, ptr %41, align 8, !tbaa !19, !alias.scope !25, !noalias !22
  %wide.load13 = load <2 x double>, ptr %42, align 8, !tbaa !19, !alias.scope !25, !noalias !22
  %43 = fsub <2 x double> %wide.load12, %wide.load
  %44 = fsub <2 x double> %wide.load13, %wide.load11
  store <2 x double> %43, ptr %41, align 8, !tbaa !19, !alias.scope !25, !noalias !22
  store <2 x double> %44, ptr %42, align 8, !tbaa !19, !alias.scope !25, !noalias !22
  %index.next = add nuw i64 %index, 4
  %45 = icmp eq i64 %index.next, %n.vec
  br i1 %45, label %middle.block, label %vector.body, !llvm.loop !27

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %._crit_edge, label %scalar.ph.preheader

._crit_edge:                                      ; preds = %scalar.ph.prol.loopexit, %scalar.ph, %middle.block, %23
  ret void

scalar.ph:                                        ; preds = %scalar.ph.prol.loopexit, %scalar.ph
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %scalar.ph ], [ %indvars.iv.unr, %scalar.ph.prol.loopexit ]
  %46 = getelementptr inbounds double, ptr %28, i64 %indvars.iv
  %47 = load double, ptr %46, align 8, !tbaa !19
  %48 = getelementptr inbounds double, ptr %30, i64 %indvars.iv
  %49 = load double, ptr %48, align 8, !tbaa !19
  %50 = fsub double %49, %47
  store double %50, ptr %48, align 8, !tbaa !19
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %51 = getelementptr inbounds double, ptr %28, i64 %indvars.iv.next
  %52 = load double, ptr %51, align 8, !tbaa !19
  %53 = getelementptr inbounds double, ptr %30, i64 %indvars.iv.next
  %54 = load double, ptr %53, align 8, !tbaa !19
  %55 = fsub double %54, %52
  store double %55, ptr %53, align 8, !tbaa !19
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %56 = getelementptr inbounds double, ptr %28, i64 %indvars.iv.next.1
  %57 = load double, ptr %56, align 8, !tbaa !19
  %58 = getelementptr inbounds double, ptr %30, i64 %indvars.iv.next.1
  %59 = load double, ptr %58, align 8, !tbaa !19
  %60 = fsub double %59, %57
  store double %60, ptr %58, align 8, !tbaa !19
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %61 = getelementptr inbounds double, ptr %28, i64 %indvars.iv.next.2
  %62 = load double, ptr %61, align 8, !tbaa !19
  %63 = getelementptr inbounds double, ptr %30, i64 %indvars.iv.next.2
  %64 = load double, ptr %63, align 8, !tbaa !19
  %65 = fsub double %64, %62
  store double %65, ptr %63, align 8, !tbaa !19
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, %wide.trip.count
  br i1 %exitcond.not.3, label %._crit_edge, label %scalar.ph, !llvm.loop !31
}

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

!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 588}
!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, !17, i64 560}
!19 = !{!16, !16, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.unroll.disable"}
!22 = !{!23}
!23 = distinct !{!23, !24}
!24 = distinct !{!24, !"LVerDomain"}
!25 = !{!26}
!26 = distinct !{!26, !24}
!27 = distinct !{!27, !28, !29, !30}
!28 = !{!"llvm.loop.mustprogress"}
!29 = !{!"llvm.loop.isvectorized", i32 1}
!30 = !{!"llvm.loop.unroll.runtime.disable"}
!31 = distinct !{!31, !28, !29}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass