; LLVM IR from tangjz/acm-icpc :: TDL_training/2015-12-02/upsolved/I - Goddess - lzy.ll (Z4calcd)

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

@n = external dso_local global i32, align 4
@o = external dso_local global [509 x i32], align 16
@dis = external dso_local global [509 x double], align 16
@the = external dso_local global [509 x double], align 16
@rad = external dso_local global [509 x double], align 16
@l = external dso_local global [509 x double], align 16
@r = external dso_local global [509 x double], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4dcmpd(double noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z3sqrd(double noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef double @_Z4calcd(double noundef %0) #1 {
  %2 = alloca double, align 8
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store double %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  store double 0.000000e+00, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  br label %7

7:                                                ; preds = %62, %1
  %8 = load i32, ptr %5, align 4, !tbaa !9
  %9 = load i32, ptr @n, align 4, !tbaa !9
  %10 = load i32, ptr @n, align 4, !tbaa !9
  %11 = add nsw i32 %9, %10
  %12 = icmp slt i32 %8, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %65

14:                                               ; preds = %7
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [509 x i32], ptr @o, i64 0, i64 %16
  %18 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %18, ptr %6, align 4, !tbaa !9
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [509 x double], ptr @l, i64 0, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !5
  %23 = load double, ptr %2, align 8, !tbaa !5
  %24 = fsub double %22, %23
  %25 = call noundef i32 @_Z4dcmpd(double noundef %24)
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %27, label %61

27:                                               ; preds = %14
  %28 = load double, ptr %2, align 8, !tbaa !5
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [509 x double], ptr @r, i64 0, i64 %30
  %32 = load double, ptr %31, align 8, !tbaa !5
  %33 = fsub double %28, %32
  %34 = call noundef i32 @_Z4dcmpd(double noundef %33)
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %36, label %61

36:                                               ; preds = %27
  %37 = load i32, ptr %6, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [509 x double], ptr @dis, i64 0, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !5
  %41 = load i32, ptr %6, align 4, !tbaa !9
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [509 x double], ptr @the, i64 0, i64 %42
  %44 = load double, ptr %43, align 8, !tbaa !5
  %45 = load double, ptr %2, align 8, !tbaa !5
  %46 = fsub double %44, %45
  %47 = call noundef double @_ZSt3absd(double noundef %46)
  %48 = call double @sin(double noundef %47) #6
  %49 = fmul double %40, %48
  store double %49, ptr %3, align 8, !tbaa !5
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [509 x double], ptr @rad, i64 0, i64 %51
  %53 = load double, ptr %52, align 8, !tbaa !5
  %54 = call noundef double @_Z3sqrd(double noundef %53)
  %55 = load double, ptr %3, align 8, !tbaa !5
  %56 = call noundef double @_Z3sqrd(double noundef %55)
  %57 = fsub double %54, %56
  %58 = call double @sqrt(double noundef %57) #6
  %59 = load double, ptr %4, align 8, !tbaa !5
  %60 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %58, double %59)
  store double %60, ptr %4, align 8, !tbaa !5
  br label %61

61:                                               ; preds = %36, %27, %14
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %5, align 4, !tbaa !9
  br label %7, !llvm.loop !11

65:                                               ; preds = %13
  %66 = load double, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  ret double %66
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3absd(double noundef) #4

; 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) #5

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

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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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"}


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

@n = external dso_local local_unnamed_addr global i32, align 4
@o = external dso_local local_unnamed_addr global [509 x i32], align 16
@dis = external dso_local local_unnamed_addr global [509 x double], align 16
@the = external dso_local local_unnamed_addr global [509 x double], align 16
@rad = external dso_local local_unnamed_addr global [509 x double], align 16
@l = external dso_local local_unnamed_addr global [509 x double], align 16
@r = external dso_local local_unnamed_addr global [509 x double], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z4dcmpd(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef double @_Z3sqrd(double noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef double @_Z4calcd(double noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %34, %1
  %.0.lcssa = phi double [ 0.000000e+00, %1 ], [ %.1, %34 ]
  ret double %.0.lcssa

.lr.ph:                                           ; preds = %1, %34
  %indvars.iv = phi i64 [ %indvars.iv.next, %34 ], [ 0, %1 ]
  %.015 = phi double [ %.1, %34 ], [ 0.000000e+00, %1 ]
  %4 = getelementptr inbounds [509 x i32], ptr @o, i64 0, i64 %indvars.iv
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [509 x double], ptr @l, i64 0, i64 %6
  %8 = load double, ptr %7, align 8, !tbaa !9
  %9 = fsub double %8, %0
  %10 = tail call noundef i32 @_Z4dcmpd(double noundef %9)
  %11 = icmp slt i32 %10, 0
  br i1 %11, label %12, label %34

12:                                               ; preds = %.lr.ph
  %13 = getelementptr inbounds [509 x double], ptr @r, i64 0, i64 %6
  %14 = load double, ptr %13, align 8, !tbaa !9
  %15 = fsub double %0, %14
  %16 = tail call noundef i32 @_Z4dcmpd(double noundef %15)
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %34

18:                                               ; preds = %12
  %19 = getelementptr inbounds [509 x double], ptr @dis, i64 0, i64 %6
  %20 = load double, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds [509 x double], ptr @the, i64 0, i64 %6
  %22 = load double, ptr %21, align 8, !tbaa !9
  %23 = fsub double %22, %0
  %24 = tail call noundef double @_ZSt3absd(double noundef %23)
  %25 = tail call double @sin(double noundef %24) #4
  %26 = fmul double %20, %25
  %27 = getelementptr inbounds [509 x double], ptr @rad, i64 0, i64 %6
  %28 = load double, ptr %27, align 8, !tbaa !9
  %29 = tail call noundef double @_Z3sqrd(double noundef %28)
  %30 = tail call noundef double @_Z3sqrd(double noundef %26)
  %31 = fsub double %29, %30
  %32 = tail call double @sqrt(double noundef %31) #4
  %33 = tail call double @llvm.fmuladd.f64(double %32, double 2.000000e+00, double %.015)
  br label %34

34:                                               ; preds = %.lr.ph, %12, %18
  %.1 = phi double [ %33, %18 ], [ %.015, %12 ], [ %.015, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = shl nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = icmp slt i64 %indvars.iv.next, %37
  br i1 %38, label %.lr.ph, label %._crit_edge, !llvm.loop !11
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt3absd(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(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) #3

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 = { 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 = { 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 #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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass