; LLVM IR from tangjz/acm-icpc :: codeforces/complete/2C.ll (Z1fdd)

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

@x = external dso_local global [3 x double], align 16
@y = external dso_local global [3 x double], align 16
@r = external dso_local global [3 x double], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z1fdd(double noundef %0, double noundef %1) #0 {
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca [3 x double], align 16
  %7 = alloca double, align 8
  store double %0, ptr %3, align 8, !tbaa !5
  store double %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr %6) #5
  call void @llvm.memset.p0.i64(ptr align 16 %6, i8 0, i64 24, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  store double 0.000000e+00, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %8

8:                                                ; preds = %47, %2
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 3
  br i1 %10, label %11, label %50

11:                                               ; preds = %8
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [3 x double], ptr @x, i64 0, i64 %13
  %15 = load double, ptr %14, align 8, !tbaa !5
  %16 = load double, ptr %3, align 8, !tbaa !5
  %17 = fsub double %15, %16
  %18 = load i32, ptr %5, align 4, !tbaa !9
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [3 x double], ptr @x, i64 0, i64 %19
  %21 = load double, ptr %20, align 8, !tbaa !5
  %22 = load double, ptr %3, align 8, !tbaa !5
  %23 = fsub double %21, %22
  %24 = load i32, ptr %5, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [3 x double], ptr @y, i64 0, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = load double, ptr %4, align 8, !tbaa !5
  %29 = fsub double %27, %28
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [3 x double], ptr @y, i64 0, i64 %31
  %33 = load double, ptr %32, align 8, !tbaa !5
  %34 = load double, ptr %4, align 8, !tbaa !5
  %35 = fsub double %33, %34
  %36 = fmul double %29, %35
  %37 = call double @llvm.fmuladd.f64(double %17, double %23, double %36)
  %38 = call double @sqrt(double noundef %37) #5
  %39 = load i32, ptr %5, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [3 x double], ptr @r, i64 0, i64 %40
  %42 = load double, ptr %41, align 8, !tbaa !5
  %43 = fdiv double %38, %42
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 %45
  store double %43, ptr %46, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %11
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = add nsw i32 %48, 1
  store i32 %49, ptr %5, align 4, !tbaa !9
  br label %8, !llvm.loop !11

50:                                               ; preds = %8
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %79, %50
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = icmp slt i32 %52, 3
  br i1 %53, label %54, label %82

54:                                               ; preds = %51
  %55 = load i32, ptr %5, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 %56
  %58 = load double, ptr %57, align 8, !tbaa !5
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  %61 = srem i32 %60, 3
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 %62
  %64 = load double, ptr %63, align 8, !tbaa !5
  %65 = fsub double %58, %64
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 %67
  %69 = load double, ptr %68, align 8, !tbaa !5
  %70 = load i32, ptr %5, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  %72 = srem i32 %71, 3
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [3 x double], ptr %6, i64 0, i64 %73
  %75 = load double, ptr %74, align 8, !tbaa !5
  %76 = fsub double %69, %75
  %77 = load double, ptr %7, align 8, !tbaa !5
  %78 = call double @llvm.fmuladd.f64(double %65, double %76, double %77)
  store double %78, ptr %7, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %54
  %80 = load i32, ptr %5, align 4, !tbaa !9
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %5, align 4, !tbaa !9
  br label %51, !llvm.loop !13

82:                                               ; preds = %51
  %83 = load double, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  ret double %83
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

; 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 nounwind willreturn memory(argmem: write) }
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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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

@x = external dso_local local_unnamed_addr global [3 x double], align 16
@y = external dso_local local_unnamed_addr global [3 x double], align 16
@r = external dso_local local_unnamed_addr global [3 x double], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef double @_Z1fdd(double noundef %0, double noundef %1) local_unnamed_addr #0 {
.preheader.preheader:
  %2 = load double, ptr @x, align 16, !tbaa !5
  %3 = load double, ptr @y, align 16, !tbaa !5
  %4 = load double, ptr @r, align 16, !tbaa !5
  %5 = load double, ptr getelementptr inbounds (i8, ptr @x, i64 8), align 8, !tbaa !5
  %6 = fsub double %5, %0
  %7 = load double, ptr getelementptr inbounds (i8, ptr @y, i64 8), align 8, !tbaa !5
  %8 = fsub double %7, %1
  %9 = fmul double %8, %8
  %10 = tail call double @llvm.fmuladd.f64(double %6, double %6, double %9)
  %sqrt.1 = tail call double @llvm.sqrt.f64(double %10)
  %11 = load double, ptr getelementptr inbounds (i8, ptr @r, i64 8), align 8, !tbaa !5
  %12 = fdiv double %sqrt.1, %11
  %13 = load double, ptr getelementptr inbounds (i8, ptr @x, i64 16), align 16, !tbaa !5
  %14 = load double, ptr getelementptr inbounds (i8, ptr @y, i64 16), align 16, !tbaa !5
  %15 = load double, ptr getelementptr inbounds (i8, ptr @r, i64 16), align 16, !tbaa !5
  %16 = insertelement <2 x double> poison, double %13, i64 0
  %17 = insertelement <2 x double> %16, double %2, i64 1
  %18 = insertelement <2 x double> poison, double %0, i64 0
  %19 = shufflevector <2 x double> %18, <2 x double> poison, <2 x i32> zeroinitializer
  %20 = fsub <2 x double> %17, %19
  %21 = insertelement <2 x double> poison, double %14, i64 0
  %22 = insertelement <2 x double> %21, double %3, i64 1
  %23 = insertelement <2 x double> poison, double %1, i64 0
  %24 = shufflevector <2 x double> %23, <2 x double> poison, <2 x i32> zeroinitializer
  %25 = fsub <2 x double> %22, %24
  %26 = fmul <2 x double> %25, %25
  %27 = tail call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %20, <2 x double> %20, <2 x double> %26)
  %28 = tail call <2 x double> @llvm.sqrt.v2f64(<2 x double> %27)
  %29 = insertelement <2 x double> poison, double %15, i64 0
  %30 = insertelement <2 x double> %29, double %4, i64 1
  %31 = fdiv <2 x double> %28, %30
  %32 = extractelement <2 x double> %31, i64 1
  %33 = fsub double %32, %12
  %34 = tail call double @llvm.fmuladd.f64(double %33, double %33, double 0.000000e+00)
  %35 = extractelement <2 x double> %31, i64 0
  %36 = fsub double %12, %35
  %37 = tail call double @llvm.fmuladd.f64(double %36, double %36, double %34)
  %38 = fsub double %35, %32
  %39 = tail call double @llvm.fmuladd.f64(double %38, double %38, double %37)
  ret double %39
}

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <2 x double> @llvm.sqrt.v2f64(<2 x double>) #2

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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 = { 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,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass