; LLVM IR from alexzheng42/sDMD :: src (CG)

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

%struct.CGMatrixStr = type { [5 x double], [32 x %struct.CGBeadStr] }
%struct.CGBeadStr = type { double, double, double, double }

@CGMatrix = external global %struct.CGMatrixStr, align 8

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

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

; Function Attrs: nounwind uwtable
define dso_local double @CalculateSurPoten(ptr noundef byval(%struct.CGBeadStr) align 8 %0, ptr noundef byval(%struct.CGBeadStr) align 8 %1, double noundef %2) #1 {
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca double, align 8
  store double %2, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %8 = getelementptr inbounds %struct.CGBeadStr, ptr %0, i32 0, i32 1
  %9 = load double, ptr %8, align 8, !tbaa !9
  %10 = getelementptr inbounds %struct.CGBeadStr, ptr %1, i32 0, i32 1
  %11 = load double, ptr %10, align 8, !tbaa !9
  %12 = fmul double %9, %11
  store double %12, ptr %6, align 8, !tbaa !5
  %13 = load double, ptr %6, align 8, !tbaa !5
  %14 = fcmp olt double %13, 0.000000e+00
  br i1 %14, label %15, label %19

15:                                               ; preds = %3
  %16 = load double, ptr %6, align 8, !tbaa !5
  %17 = fmul double %16, -1.000000e+00
  %18 = call double @sqrt(double noundef %17) #5
  store double %18, ptr %6, align 8, !tbaa !5
  br label %22

19:                                               ; preds = %3
  %20 = load double, ptr %6, align 8, !tbaa !5
  %21 = call double @sqrt(double noundef %20) #5
  store double %21, ptr %6, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %19, %15
  %23 = getelementptr inbounds %struct.CGBeadStr, ptr %0, i32 0, i32 2
  %24 = load double, ptr %23, align 8, !tbaa !11
  %25 = getelementptr inbounds %struct.CGBeadStr, ptr %1, i32 0, i32 2
  %26 = load double, ptr %25, align 8, !tbaa !11
  %27 = fadd double %24, %26
  %28 = fmul double %27, 5.000000e-01
  store double %28, ptr %5, align 8, !tbaa !5
  %29 = load double, ptr %5, align 8, !tbaa !5
  %30 = load double, ptr %4, align 8, !tbaa !5
  %31 = fdiv double %29, %30
  store double %31, ptr %7, align 8, !tbaa !5
  %32 = load double, ptr %5, align 8, !tbaa !5
  %33 = call double @CalExponential(double noundef %32, i32 noundef 3)
  %34 = fmul double 0x400921FB54442D18, %33
  %35 = load double, ptr %6, align 8, !tbaa !5
  %36 = fmul double %34, %35
  %37 = load double, ptr @CGMatrix, align 8, !tbaa !5
  %38 = load double, ptr %7, align 8, !tbaa !5
  %39 = call double @CalExponential(double noundef %38, i32 noundef 9)
  %40 = load double, ptr getelementptr inbounds ([5 x double], ptr @CGMatrix, i64 0, i64 1), align 8, !tbaa !5
  %41 = load double, ptr %7, align 8, !tbaa !5
  %42 = call double @CalExponential(double noundef %41, i32 noundef 7)
  %43 = fmul double %40, %42
  %44 = fneg double %43
  %45 = call double @llvm.fmuladd.f64(double %37, double %39, double %44)
  %46 = load double, ptr getelementptr inbounds ([5 x double], ptr @CGMatrix, i64 0, i64 2), align 8, !tbaa !5
  %47 = load double, ptr %7, align 8, !tbaa !5
  %48 = call double @CalExponential(double noundef %47, i32 noundef 3)
  %49 = call double @llvm.fmuladd.f64(double %46, double %48, double %45)
  %50 = load double, ptr getelementptr inbounds ([5 x double], ptr @CGMatrix, i64 0, i64 3), align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.CGBeadStr, ptr %0, i32 0, i32 0
  %52 = load double, ptr %51, align 8, !tbaa !12
  %53 = load double, ptr getelementptr inbounds ([5 x double], ptr @CGMatrix, i64 0, i64 4), align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.CGBeadStr, ptr %1, i32 0, i32 0
  %55 = load double, ptr %54, align 8, !tbaa !12
  %56 = getelementptr inbounds %struct.CGBeadStr, ptr %1, i32 0, i32 3
  %57 = load double, ptr %56, align 8, !tbaa !13
  %58 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %57, double %55)
  %59 = fmul double %53, %58
  %60 = call double @llvm.fmuladd.f64(double %50, double %52, double %59)
  %61 = load double, ptr %7, align 8, !tbaa !5
  %62 = call double @CalExponential(double noundef %61, i32 noundef 3)
  %63 = fneg double %60
  %64 = call double @llvm.fmuladd.f64(double %63, double %62, double %49)
  %65 = fmul double %36, %64
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  ret double %65
}

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

declare double @CalExponential(double noundef, i32 noundef) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { "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 nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 8}
!10 = !{!"CGBeadStr", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24}
!11 = !{!10, !6, i64 16}
!12 = !{!10, !6, i64 0}
!13 = !{!10, !6, i64 24}


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

%struct.CGMatrixStr = type { [5 x double], [32 x %struct.CGBeadStr] }
%struct.CGBeadStr = type { double, double, double, double }

@CGMatrix = external local_unnamed_addr global %struct.CGMatrixStr, align 8

; Function Attrs: nounwind uwtable
define dso_local double @CalculateSurPoten(ptr nocapture noundef readonly byval(%struct.CGBeadStr) align 8 %0, ptr nocapture noundef readonly byval(%struct.CGBeadStr) align 8 %1, double noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load double, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %1, i64 8
  %7 = load double, ptr %6, align 8, !tbaa !5
  %8 = fmul double %5, %7
  %9 = fcmp olt double %8, 0.000000e+00
  %10 = fneg double %8
  %.sink = select i1 %9, double %10, double %8
  %11 = tail call double @sqrt(double noundef %.sink) #4
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  %13 = load double, ptr %12, align 8, !tbaa !10
  %14 = getelementptr inbounds i8, ptr %1, i64 16
  %15 = load double, ptr %14, align 8, !tbaa !10
  %16 = fadd double %13, %15
  %17 = fmul double %16, 5.000000e-01
  %18 = fdiv double %17, %2
  %19 = tail call double @CalExponential(double noundef %17, i32 noundef 3) #4
  %20 = fmul double %19, 0x400921FB54442D18
  %21 = fmul double %11, %20
  %22 = load double, ptr @CGMatrix, align 8, !tbaa !11
  %23 = tail call double @CalExponential(double noundef %18, i32 noundef 9) #4
  %24 = load double, ptr getelementptr inbounds (i8, ptr @CGMatrix, i64 8), align 8, !tbaa !11
  %25 = tail call double @CalExponential(double noundef %18, i32 noundef 7) #4
  %26 = fneg double %24
  %27 = fmul double %25, %26
  %28 = tail call double @llvm.fmuladd.f64(double %22, double %23, double %27)
  %29 = load double, ptr getelementptr inbounds (i8, ptr @CGMatrix, i64 16), align 8, !tbaa !11
  %30 = tail call double @CalExponential(double noundef %18, i32 noundef 3) #4
  %31 = tail call double @llvm.fmuladd.f64(double %29, double %30, double %28)
  %32 = load double, ptr getelementptr inbounds (i8, ptr @CGMatrix, i64 24), align 8, !tbaa !11
  %33 = load double, ptr %0, align 8, !tbaa !12
  %34 = load double, ptr getelementptr inbounds (i8, ptr @CGMatrix, i64 32), align 8, !tbaa !11
  %35 = load double, ptr %1, align 8, !tbaa !12
  %36 = getelementptr inbounds i8, ptr %1, i64 24
  %37 = load double, ptr %36, align 8, !tbaa !13
  %38 = tail call double @llvm.fmuladd.f64(double %37, double 2.000000e+00, double %35)
  %39 = fmul double %34, %38
  %40 = tail call double @llvm.fmuladd.f64(double %32, double %33, double %39)
  %41 = tail call double @CalExponential(double noundef %18, i32 noundef 3) #4
  %42 = fneg double %40
  %43 = tail call double @llvm.fmuladd.f64(double %42, double %41, double %31)
  %44 = fmul double %21, %43
  ret double %44
}

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

declare double @CalExponential(double noundef, i32 noundef) local_unnamed_addr #2

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

attributes #0 = { 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 = { 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 #2 = { "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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 8}
!6 = !{!"CGBeadStr", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 16}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !7, i64 24}


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