; LLVM IR from yourtion/LearningMasteringAlgorithms-C :: source (arclen)

; 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.SPoint_ = type { double, double, double }
%struct.Point_ = type { double, double, double }

; Function Attrs: nounwind uwtable
define dso_local void @arclen(ptr noundef byval(%struct.SPoint_) align 8 %0, ptr noundef byval(%struct.SPoint_) align 8 %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca %struct.Point_, align 8
  %6 = alloca %struct.Point_, align 8
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  store ptr %2, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 24, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %9 = getelementptr inbounds %struct.SPoint_, ptr %0, i32 0, i32 0
  %10 = load double, ptr %9, align 8, !tbaa !9
  %11 = getelementptr inbounds %struct.SPoint_, ptr %0, i32 0, i32 2
  %12 = load double, ptr %11, align 8, !tbaa !12
  %13 = call double @sin(double noundef %12) #4
  %14 = fmul double %10, %13
  %15 = getelementptr inbounds %struct.SPoint_, ptr %0, i32 0, i32 1
  %16 = load double, ptr %15, align 8, !tbaa !13
  %17 = call double @cos(double noundef %16) #4
  %18 = fmul double %14, %17
  %19 = getelementptr inbounds %struct.Point_, ptr %5, i32 0, i32 0
  store double %18, ptr %19, align 8, !tbaa !14
  %20 = getelementptr inbounds %struct.SPoint_, ptr %0, i32 0, i32 0
  %21 = load double, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds %struct.SPoint_, ptr %0, i32 0, i32 2
  %23 = load double, ptr %22, align 8, !tbaa !12
  %24 = call double @sin(double noundef %23) #4
  %25 = fmul double %21, %24
  %26 = getelementptr inbounds %struct.SPoint_, ptr %0, i32 0, i32 1
  %27 = load double, ptr %26, align 8, !tbaa !13
  %28 = call double @sin(double noundef %27) #4
  %29 = fmul double %25, %28
  %30 = getelementptr inbounds %struct.Point_, ptr %5, i32 0, i32 1
  store double %29, ptr %30, align 8, !tbaa !16
  %31 = getelementptr inbounds %struct.SPoint_, ptr %0, i32 0, i32 0
  %32 = load double, ptr %31, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.SPoint_, ptr %0, i32 0, i32 2
  %34 = load double, ptr %33, align 8, !tbaa !12
  %35 = call double @cos(double noundef %34) #4
  %36 = fmul double %32, %35
  %37 = getelementptr inbounds %struct.Point_, ptr %5, i32 0, i32 2
  store double %36, ptr %37, align 8, !tbaa !17
  %38 = getelementptr inbounds %struct.SPoint_, ptr %1, i32 0, i32 0
  %39 = load double, ptr %38, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.SPoint_, ptr %1, i32 0, i32 2
  %41 = load double, ptr %40, align 8, !tbaa !12
  %42 = call double @sin(double noundef %41) #4
  %43 = fmul double %39, %42
  %44 = getelementptr inbounds %struct.SPoint_, ptr %1, i32 0, i32 1
  %45 = load double, ptr %44, align 8, !tbaa !13
  %46 = call double @cos(double noundef %45) #4
  %47 = fmul double %43, %46
  %48 = getelementptr inbounds %struct.Point_, ptr %6, i32 0, i32 0
  store double %47, ptr %48, align 8, !tbaa !14
  %49 = getelementptr inbounds %struct.SPoint_, ptr %1, i32 0, i32 0
  %50 = load double, ptr %49, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.SPoint_, ptr %1, i32 0, i32 2
  %52 = load double, ptr %51, align 8, !tbaa !12
  %53 = call double @sin(double noundef %52) #4
  %54 = fmul double %50, %53
  %55 = getelementptr inbounds %struct.SPoint_, ptr %1, i32 0, i32 1
  %56 = load double, ptr %55, align 8, !tbaa !13
  %57 = call double @sin(double noundef %56) #4
  %58 = fmul double %54, %57
  %59 = getelementptr inbounds %struct.Point_, ptr %6, i32 0, i32 1
  store double %58, ptr %59, align 8, !tbaa !16
  %60 = getelementptr inbounds %struct.SPoint_, ptr %1, i32 0, i32 0
  %61 = load double, ptr %60, align 8, !tbaa !9
  %62 = getelementptr inbounds %struct.SPoint_, ptr %1, i32 0, i32 2
  %63 = load double, ptr %62, align 8, !tbaa !12
  %64 = call double @cos(double noundef %63) #4
  %65 = fmul double %61, %64
  %66 = getelementptr inbounds %struct.Point_, ptr %6, i32 0, i32 2
  store double %65, ptr %66, align 8, !tbaa !17
  %67 = getelementptr inbounds %struct.Point_, ptr %5, i32 0, i32 0
  %68 = load double, ptr %67, align 8, !tbaa !14
  %69 = getelementptr inbounds %struct.Point_, ptr %6, i32 0, i32 0
  %70 = load double, ptr %69, align 8, !tbaa !14
  %71 = getelementptr inbounds %struct.Point_, ptr %5, i32 0, i32 1
  %72 = load double, ptr %71, align 8, !tbaa !16
  %73 = getelementptr inbounds %struct.Point_, ptr %6, i32 0, i32 1
  %74 = load double, ptr %73, align 8, !tbaa !16
  %75 = fmul double %72, %74
  %76 = call double @llvm.fmuladd.f64(double %68, double %70, double %75)
  %77 = getelementptr inbounds %struct.Point_, ptr %5, i32 0, i32 2
  %78 = load double, ptr %77, align 8, !tbaa !17
  %79 = getelementptr inbounds %struct.Point_, ptr %6, i32 0, i32 2
  %80 = load double, ptr %79, align 8, !tbaa !17
  %81 = call double @llvm.fmuladd.f64(double %78, double %80, double %76)
  store double %81, ptr %8, align 8, !tbaa !18
  %82 = load double, ptr %8, align 8, !tbaa !18
  %83 = getelementptr inbounds %struct.SPoint_, ptr %0, i32 0, i32 0
  %84 = load double, ptr %83, align 8, !tbaa !9
  %85 = call double @pow(double noundef %84, double noundef 2.000000e+00) #4
  %86 = fdiv double %82, %85
  %87 = call double @acos(double noundef %86) #4
  store double %87, ptr %7, align 8, !tbaa !18
  %88 = load double, ptr %7, align 8, !tbaa !18
  %89 = getelementptr inbounds %struct.SPoint_, ptr %0, i32 0, i32 0
  %90 = load double, ptr %89, align 8, !tbaa !9
  %91 = fmul double %88, %90
  %92 = load ptr, ptr %4, align 8, !tbaa !5
  store double %91, ptr %92, align 8, !tbaa !18
  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 24, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 24, 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: nounwind
declare double @sin(double noundef) #2

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

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

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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"SPoint_", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"double", !7, i64 0}
!12 = !{!10, !11, i64 16}
!13 = !{!10, !11, i64 8}
!14 = !{!15, !11, i64 0}
!15 = !{!"Point_", !11, i64 0, !11, i64 8, !11, i64 16}
!16 = !{!15, !11, i64 8}
!17 = !{!15, !11, i64 16}
!18 = !{!11, !11, 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"

%struct.SPoint_ = type { double, double, double }

; Function Attrs: mustprogress nofree nounwind willreturn memory(write, argmem: readwrite) uwtable
define dso_local void @arclen(ptr nocapture noundef readonly byval(%struct.SPoint_) align 8 %0, ptr nocapture noundef readonly byval(%struct.SPoint_) align 8 %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = load double, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load double, ptr %5, align 8, !tbaa !10
  %7 = tail call double @sin(double noundef %6) #3
  %8 = fmul double %4, %7
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = load double, ptr %9, align 8, !tbaa !11
  %11 = tail call double @cos(double noundef %10) #3
  %12 = fmul double %8, %11
  %13 = tail call double @sin(double noundef %6) #3
  %14 = fmul double %4, %13
  %15 = tail call double @sin(double noundef %10) #3
  %16 = fmul double %14, %15
  %17 = tail call double @cos(double noundef %6) #3
  %18 = fmul double %4, %17
  %19 = load double, ptr %1, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %1, i64 16
  %21 = load double, ptr %20, align 8, !tbaa !10
  %22 = tail call double @sin(double noundef %21) #3
  %23 = fmul double %19, %22
  %24 = getelementptr inbounds i8, ptr %1, i64 8
  %25 = load double, ptr %24, align 8, !tbaa !11
  %26 = tail call double @cos(double noundef %25) #3
  %27 = fmul double %23, %26
  %28 = tail call double @sin(double noundef %21) #3
  %29 = fmul double %19, %28
  %30 = tail call double @sin(double noundef %25) #3
  %31 = fmul double %29, %30
  %32 = tail call double @cos(double noundef %21) #3
  %33 = fmul double %19, %32
  %34 = fmul double %16, %31
  %35 = tail call double @llvm.fmuladd.f64(double %12, double %27, double %34)
  %36 = tail call double @llvm.fmuladd.f64(double %18, double %33, double %35)
  %square = fmul double %4, %4
  %37 = fdiv double %36, %square
  %38 = tail call double @acos(double noundef %37) #3
  %39 = fmul double %4, %38
  store double %39, ptr %2, align 8, !tbaa !12
  ret void
}

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

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

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @acos(double noundef) local_unnamed_addr #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 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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"SPoint_", !7, i64 0, !7, i64 8, !7, i64 16}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 16}
!11 = !{!6, !7, i64 8}
!12 = !{!7, !7, i64 0}


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