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

; 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.32 = external hidden unnamed_addr constant [25 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

; Function Attrs: nounwind
declare double @sqrt(double noundef) #3

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK6R3Grid12WorldSpacingEi(ptr noundef nonnull align 8 dereferenceable(592) %0, i32 noundef %1) #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8
  %10 = load i32, ptr %4, align 4, !tbaa !9
  %11 = icmp sle i32 0, %10
  br i1 %11, label %12, label %15

12:                                               ; preds = %2
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = icmp sle i32 %13, 2
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %15, %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  %17 = getelementptr inbounds %class.R3Grid, ptr %9, i32 0, i32 0
  %18 = call noundef nonnull align 8 dereferenceable(128) ptr @_ZNK8R3Affine6MatrixEv(ptr noundef nonnull align 8 dereferenceable(272) %17)
  %19 = call noundef ptr @_ZNK8R4MatrixixEi(ptr noundef nonnull align 8 dereferenceable(128) %18, i32 noundef 0)
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds double, ptr %19, i64 %21
  %23 = load double, ptr %22, align 8, !tbaa !11
  store double %23, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %24 = getelementptr inbounds %class.R3Grid, ptr %9, i32 0, i32 0
  %25 = call noundef nonnull align 8 dereferenceable(128) ptr @_ZNK8R3Affine6MatrixEv(ptr noundef nonnull align 8 dereferenceable(272) %24)
  %26 = call noundef ptr @_ZNK8R4MatrixixEi(ptr noundef nonnull align 8 dereferenceable(128) %25, i32 noundef 1)
  %27 = load i32, ptr %4, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds double, ptr %26, i64 %28
  %30 = load double, ptr %29, align 8, !tbaa !11
  store double %30, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %31 = getelementptr inbounds %class.R3Grid, ptr %9, i32 0, i32 0
  %32 = call noundef nonnull align 8 dereferenceable(128) ptr @_ZNK8R3Affine6MatrixEv(ptr noundef nonnull align 8 dereferenceable(272) %31)
  %33 = call noundef ptr @_ZNK8R4MatrixixEi(ptr noundef nonnull align 8 dereferenceable(128) %32, i32 noundef 2)
  %34 = load i32, ptr %4, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds double, ptr %33, i64 %35
  %37 = load double, ptr %36, align 8, !tbaa !11
  store double %37, ptr %7, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %38 = load double, ptr %5, align 8, !tbaa !11
  %39 = load double, ptr %5, align 8, !tbaa !11
  %40 = load double, ptr %6, align 8, !tbaa !11
  %41 = load double, ptr %6, align 8, !tbaa !11
  %42 = fmul double %40, %41
  %43 = call double @llvm.fmuladd.f64(double %38, double %39, double %42)
  %44 = load double, ptr %7, align 8, !tbaa !11
  %45 = load double, ptr %7, align 8, !tbaa !11
  %46 = call double @llvm.fmuladd.f64(double %44, double %45, double %43)
  store double %46, ptr %8, align 8, !tbaa !11
  %47 = load double, ptr %8, align 8, !tbaa !11
  %48 = call double @sqrt(double noundef %47) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  ret double %48
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(128) ptr @_ZNK8R3Affine6MatrixEv(ptr noundef nonnull align 8 dereferenceable(272)) #5 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK8R4MatrixixEi(ptr noundef nonnull align 8 dereferenceable(128), i32 noundef) #6 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 willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #4 = { 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 #5 = { 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 #6 = { inlinehint 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 #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, !12, i64 0}
!12 = !{!"double", !7, i64 0}


; 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.32 = external hidden unnamed_addr constant [25 x i8], align 1

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_ZNK6R3Grid12WorldSpacingEi(ptr noundef nonnull align 8 dereferenceable(592) %0, i32 noundef %1) local_unnamed_addr #2 align 2 {
  %or.cond = icmp ult i32 %1, 3
  br i1 %or.cond, label %4, label %3

3:                                                ; preds = %2
  tail call void (ptr, ...) @_Z7RNAbortPKcz(ptr noundef nonnull @.str, ptr noundef nonnull @.str.32, i32 noundef 2903, ptr noundef nonnull @.str.2)
  br label %4

4:                                                ; preds = %2, %3
  %5 = tail call noundef nonnull align 8 dereferenceable(128) ptr @_ZNK8R3Affine6MatrixEv(ptr noundef nonnull align 8 dereferenceable(272) %0)
  %6 = tail call noundef ptr @_ZNK8R4MatrixixEi(ptr noundef nonnull align 8 dereferenceable(128) %5, i32 noundef 0)
  %7 = sext i32 %1 to i64
  %8 = getelementptr inbounds double, ptr %6, i64 %7
  %9 = load double, ptr %8, align 8, !tbaa !5
  %10 = tail call noundef nonnull align 8 dereferenceable(128) ptr @_ZNK8R3Affine6MatrixEv(ptr noundef nonnull align 8 dereferenceable(272) %0)
  %11 = tail call noundef ptr @_ZNK8R4MatrixixEi(ptr noundef nonnull align 8 dereferenceable(128) %10, i32 noundef 1)
  %12 = getelementptr inbounds double, ptr %11, i64 %7
  %13 = load double, ptr %12, align 8, !tbaa !5
  %14 = tail call noundef nonnull align 8 dereferenceable(128) ptr @_ZNK8R3Affine6MatrixEv(ptr noundef nonnull align 8 dereferenceable(272) %0)
  %15 = tail call noundef ptr @_ZNK8R4MatrixixEi(ptr noundef nonnull align 8 dereferenceable(128) %14, i32 noundef 2)
  %16 = getelementptr inbounds double, ptr %15, i64 %7
  %17 = load double, ptr %16, align 8, !tbaa !5
  %18 = fmul double %13, %13
  %19 = tail call double @llvm.fmuladd.f64(double %9, double %9, double %18)
  %20 = tail call double @llvm.fmuladd.f64(double %17, double %17, double %19)
  %sqrt = tail call double @llvm.sqrt.f64(double %20)
  ret double %sqrt
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(128) ptr @_ZNK8R3Affine6MatrixEv(ptr noundef nonnull align 8 dereferenceable(272)) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZNK8R4MatrixixEi(ptr noundef nonnull align 8 dereferenceable(128), i32 noundef) local_unnamed_addr #4 align 2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.sqrt.f64(double) #5

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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { inlinehint 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass