; LLVM IR from emathew1/3DCompactSolver :: AeroOptics.ll (ZN10AeroOptics20generateBaseBeamDiffEi)

; 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.AeroOptics = type { ptr, ptr, i32, i32, i32, i32, double, double, double, double, i32, double, double, double, ptr, ptr, ptr, i32, double, double, double, double, double, double, ptr }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN10AeroOptics20generateBaseBeamDiffEi(ptr noundef nonnull align 8 dereferenceable(184) %0, i32 noundef %1) #0 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
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %10 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 19
  %11 = load double, ptr %10, align 8, !tbaa !11
  store double %11, ptr %5, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %12 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 20
  %13 = load double, ptr %12, align 8, !tbaa !15
  store double %13, ptr %6, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store double 0.000000e+00, ptr %7, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %14 = load double, ptr %7, align 8, !tbaa !14
  %15 = load i32, ptr %4, align 4, !tbaa !9
  %16 = sitofp i32 %15 to double
  %17 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 17
  %18 = load i32, ptr %17, align 8, !tbaa !16
  %19 = sub nsw i32 %18, 1
  %20 = sitofp i32 %19 to double
  %21 = fdiv double %16, %20
  %22 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 18
  %23 = load double, ptr %22, align 8, !tbaa !17
  %24 = load double, ptr %7, align 8, !tbaa !14
  %25 = fsub double %23, %24
  %26 = call double @llvm.fmuladd.f64(double %21, double %25, double %14)
  store double %26, ptr %8, align 8, !tbaa !14
  %27 = load double, ptr %8, align 8, !tbaa !14
  %28 = fmul double %27, 0x3F91DF46A2529D39
  store double %28, ptr %8, align 8, !tbaa !14
  %29 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 22
  %30 = load double, ptr %29, align 8, !tbaa !18
  %31 = load double, ptr %8, align 8, !tbaa !14
  %32 = call double @cos(double noundef %31) #4
  %33 = fdiv double %30, %32
  %34 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 23
  store double %33, ptr %34, align 8, !tbaa !19
  %35 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 23
  %36 = load double, ptr %35, align 8, !tbaa !19
  %37 = load double, ptr %8, align 8, !tbaa !14
  %38 = call double @sin(double noundef %37) #4
  %39 = fmul double %36, %38
  %40 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 21
  store double %39, ptr %40, align 8, !tbaa !20
  %41 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 23
  %42 = load double, ptr %41, align 8, !tbaa !19
  %43 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 9
  %44 = load double, ptr %43, align 8, !tbaa !21
  %45 = fdiv double %42, %44
  %46 = call double @llvm.ceil.f64(double %45)
  %47 = fadd double %46, 1.000000e+00
  %48 = fptosi double %47 to i32
  %49 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 10
  store i32 %48, ptr %49, align 8, !tbaa !22
  %50 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 23
  %51 = load double, ptr %50, align 8, !tbaa !19
  %52 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 10
  %53 = load i32, ptr %52, align 8, !tbaa !22
  %54 = sub nsw i32 %53, 1
  %55 = sitofp i32 %54 to double
  %56 = fdiv double %51, %55
  %57 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 13
  store double %56, ptr %57, align 8, !tbaa !23
  %58 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 21
  %59 = load double, ptr %58, align 8, !tbaa !20
  %60 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 10
  %61 = load i32, ptr %60, align 8, !tbaa !22
  %62 = sub nsw i32 %61, 1
  %63 = sitofp i32 %62 to double
  %64 = fdiv double %59, %63
  %65 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 11
  store double %64, ptr %65, align 8, !tbaa !24
  %66 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 22
  %67 = load double, ptr %66, align 8, !tbaa !18
  %68 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 10
  %69 = load i32, ptr %68, align 8, !tbaa !22
  %70 = sub nsw i32 %69, 1
  %71 = sitofp i32 %70 to double
  %72 = fdiv double %67, %71
  %73 = getelementptr inbounds %class.AeroOptics, ptr %9, i32 0, i32 12
  store double %72, ptr %73, align 8, !tbaa !25
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret void
}

; 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 speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #2

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

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

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

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

attributes #0 = { 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 #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 = { 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, !13, i64 136}
!12 = !{!"_ZTS10AeroOptics", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !10, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !10, i64 120, !13, i64 128, !13, i64 136, !13, i64 144, !13, i64 152, !13, i64 160, !13, i64 168, !6, i64 176}
!13 = !{!"double", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 144}
!16 = !{!12, !10, i64 120}
!17 = !{!12, !13, i64 128}
!18 = !{!12, !13, i64 160}
!19 = !{!12, !13, i64 168}
!20 = !{!12, !13, i64 152}
!21 = !{!12, !13, i64 56}
!22 = !{!12, !10, i64 64}
!23 = !{!12, !13, i64 88}
!24 = !{!12, !13, i64 72}
!25 = !{!12, !13, i64 80}


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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, argmem: readwrite) uwtable
define dso_local void @_ZN10AeroOptics20generateBaseBeamDiffEi(ptr nocapture noundef nonnull align 8 dereferenceable(184) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = sitofp i32 %1 to double
  %4 = getelementptr inbounds i8, ptr %0, i64 120
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %6 = add nsw i32 %5, -1
  %7 = sitofp i32 %6 to double
  %8 = fdiv double %3, %7
  %9 = getelementptr inbounds i8, ptr %0, i64 128
  %10 = load double, ptr %9, align 8, !tbaa !12
  %11 = tail call double @llvm.fmuladd.f64(double %8, double %10, double 0.000000e+00)
  %12 = fmul double %11, 0x3F91DF46A2529D39
  %13 = getelementptr inbounds i8, ptr %0, i64 160
  %14 = load double, ptr %13, align 8, !tbaa !13
  %15 = tail call double @cos(double noundef %12) #3
  %16 = fdiv double %14, %15
  %17 = getelementptr inbounds i8, ptr %0, i64 168
  store double %16, ptr %17, align 8, !tbaa !14
  %18 = tail call double @sin(double noundef %12) #3
  %19 = fmul double %16, %18
  %20 = getelementptr inbounds i8, ptr %0, i64 152
  store double %19, ptr %20, align 8, !tbaa !15
  %21 = load double, ptr %17, align 8, !tbaa !14
  %22 = getelementptr inbounds i8, ptr %0, i64 56
  %23 = load double, ptr %22, align 8, !tbaa !16
  %24 = fdiv double %21, %23
  %25 = tail call double @llvm.ceil.f64(double %24)
  %26 = fadd double %25, 1.000000e+00
  %27 = fptosi double %26 to i32
  %28 = getelementptr inbounds i8, ptr %0, i64 64
  store i32 %27, ptr %28, align 8, !tbaa !17
  %29 = add nsw i32 %27, -1
  %30 = sitofp i32 %29 to double
  %31 = fdiv double %21, %30
  %32 = getelementptr inbounds i8, ptr %0, i64 88
  store double %31, ptr %32, align 8, !tbaa !18
  %33 = getelementptr inbounds i8, ptr %0, i64 72
  %34 = load double, ptr %13, align 8, !tbaa !13
  %35 = insertelement <2 x double> poison, double %19, i64 0
  %36 = insertelement <2 x double> %35, double %34, i64 1
  %37 = insertelement <2 x double> poison, double %30, i64 0
  %38 = shufflevector <2 x double> %37, <2 x double> poison, <2 x i32> zeroinitializer
  %39 = fdiv <2 x double> %36, %38
  store <2 x double> %39, ptr %33, align 8, !tbaa !19
  ret void
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @cos(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sin(double noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nofree nounwind willreturn memory(write, argmem: readwrite) 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 #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(write) "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, !10, i64 120}
!6 = !{!"_ZTS10AeroOptics", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !11, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !10, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !10, i64 120, !11, i64 128, !11, i64 136, !11, i64 144, !11, i64 152, !11, i64 160, !11, i64 168, !7, i64 176}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!6, !11, i64 128}
!13 = !{!6, !11, i64 160}
!14 = !{!6, !11, i64 168}
!15 = !{!6, !11, i64 152}
!16 = !{!6, !11, i64 56}
!17 = !{!6, !10, i64 64}
!18 = !{!6, !11, i64 88}
!19 = !{!11, !11, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,TailCallElimPass