; LLVM IR from tangjz/acm-icpc :: self_training/2015-02-01/D.ll (Z5checkd)

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

@_ZL2pi = external hidden global double, align 8
@n = external dso_local global i32, align 4
@a = external dso_local global [10010 x double], align 16

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

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

9:                                                ; preds = %57, %1
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = load i32, ptr @n, align 4, !tbaa !9
  %12 = icmp slt i32 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  store i32 2, ptr %7, align 4
  br label %60

14:                                               ; preds = %9
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [10010 x double], ptr @a, i64 0, i64 %16
  %18 = load double, ptr %17, align 8, !tbaa !5
  %19 = load double, ptr %3, align 8, !tbaa !5
  %20 = fmul double 2.000000e+00, %19
  %21 = fcmp ogt double %18, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %14
  store i32 1, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %60

23:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10010 x double], ptr @a, i64 0, i64 %25
  %27 = load double, ptr %26, align 8, !tbaa !5
  %28 = load double, ptr %3, align 8, !tbaa !5
  %29 = fdiv double %27, %28
  %30 = call noundef double @_Z3sqrd(double noundef %29)
  %31 = fdiv double %30, 2.000000e+00
  %32 = fsub double 1.000000e+00, %31
  %33 = call double @acos(double noundef %32) #4
  store double %33, ptr %8, align 8, !tbaa !5
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = add nsw i32 %34, 1
  %36 = load i32, ptr @n, align 4, !tbaa !9
  %37 = icmp eq i32 %35, %36
  br i1 %37, label %38, label %52

38:                                               ; preds = %23
  %39 = load double, ptr %4, align 8, !tbaa !5
  %40 = load double, ptr @_ZL2pi, align 8, !tbaa !5
  %41 = fcmp olt double %39, %40
  br i1 %41, label %42, label %45

42:                                               ; preds = %38
  %43 = load double, ptr %4, align 8, !tbaa !5
  store double %43, ptr %5, align 8, !tbaa !5
  %44 = load double, ptr %8, align 8, !tbaa !5
  store double %44, ptr %4, align 8, !tbaa !5
  br label %51

45:                                               ; preds = %38
  %46 = load double, ptr @_ZL2pi, align 8, !tbaa !5
  %47 = fmul double 2.000000e+00, %46
  store double %47, ptr %5, align 8, !tbaa !5
  %48 = load double, ptr %8, align 8, !tbaa !5
  %49 = load double, ptr %4, align 8, !tbaa !5
  %50 = fadd double %49, %48
  store double %50, ptr %4, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %45, %42
  br label %56

52:                                               ; preds = %23
  %53 = load double, ptr %8, align 8, !tbaa !5
  %54 = load double, ptr %4, align 8, !tbaa !5
  %55 = fadd double %54, %53
  store double %55, ptr %4, align 8, !tbaa !5
  br label %56

56:                                               ; preds = %52, %51
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %6, align 4, !tbaa !9
  br label %9, !llvm.loop !11

60:                                               ; preds = %22, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %61 = load i32, ptr %7, align 4
  switch i32 %61, label %75 [
    i32 2, label %62
  ]

62:                                               ; preds = %60
  %63 = load double, ptr %4, align 8, !tbaa !5
  %64 = load double, ptr %5, align 8, !tbaa !5
  %65 = fsub double %63, %64
  %66 = call double @llvm.fabs.f64(double %65)
  %67 = fcmp olt double %66, 1.000000e-08
  br i1 %67, label %68, label %69

68:                                               ; preds = %62
  store i32 0, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %75

69:                                               ; preds = %62
  %70 = load double, ptr %4, align 8, !tbaa !5
  %71 = load double, ptr %5, align 8, !tbaa !5
  %72 = fcmp olt double %70, %71
  %73 = zext i1 %72 to i64
  %74 = select i1 %72, i32 -1, i32 1
  store i32 %74, ptr %2, align 4
  store i32 1, ptr %7, align 4
  br label %75

75:                                               ; preds = %69, %68, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %76 = load i32, ptr %2, align 4
  ret i32 %76
}

; 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 @acos(double noundef) #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(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 = { 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 = !{!"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"

@_ZL2pi = external hidden local_unnamed_addr global double, align 8
@n = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local local_unnamed_addr global [10010 x double], align 16

; 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 range(i32 -1, 2) i32 @_Z5checkd(double noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not28 = icmp sgt i32 %2, 0
  br i1 %.not28, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %1
  %3 = fmul double %0, 2.000000e+00
  br label %4

4:                                                ; preds = %.lr.ph, %25
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %25 ]
  %.02130 = phi double [ undef, %.lr.ph ], [ %.122, %25 ]
  %.02329 = phi double [ 0.000000e+00, %.lr.ph ], [ %.124, %25 ]
  %5 = getelementptr inbounds [10010 x double], ptr @a, i64 0, i64 %indvars.iv
  %6 = load double, ptr %5, align 8, !tbaa !9
  %7 = fcmp ogt double %6, %3
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %4
  %9 = fdiv double %6, %0
  %10 = tail call noundef double @_Z3sqrd(double noundef %9)
  %11 = fmul double %10, 5.000000e-01
  %12 = fsub double 1.000000e+00, %11
  %13 = tail call double @acos(double noundef %12) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = zext i32 %14 to i64
  %16 = icmp eq i64 %indvars.iv.next, %15
  br i1 %16, label %17, label %23

17:                                               ; preds = %8
  %18 = load double, ptr @_ZL2pi, align 8, !tbaa !9
  %19 = fcmp olt double %.02329, %18
  br i1 %19, label %25, label %20

20:                                               ; preds = %17
  %21 = fmul double %18, 2.000000e+00
  %22 = fadd double %.02329, %13
  br label %25

23:                                               ; preds = %8
  %24 = fadd double %.02329, %13
  br label %25

25:                                               ; preds = %17, %20, %23
  %.124 = phi double [ %22, %20 ], [ %24, %23 ], [ %13, %17 ]
  %.122 = phi double [ %21, %20 ], [ %.02130, %23 ], [ %.02329, %17 ]
  %26 = sext i32 %14 to i64
  %.not = icmp slt i64 %indvars.iv.next, %26
  br i1 %.not, label %4, label %.critedge, !llvm.loop !11

.critedge:                                        ; preds = %25, %1
  %.023.lcssa = phi double [ 0.000000e+00, %1 ], [ %.124, %25 ]
  %.021.lcssa = phi double [ undef, %1 ], [ %.122, %25 ]
  %27 = fsub double %.023.lcssa, %.021.lcssa
  %28 = tail call double @llvm.fabs.f64(double %27)
  %29 = fcmp olt double %28, 1.000000e-08
  br i1 %29, label %.loopexit, label %30

30:                                               ; preds = %.critedge
  %31 = fcmp olt double %.023.lcssa, %.021.lcssa
  %32 = select i1 %31, i32 -1, i32 1
  br label %.loopexit

.loopexit:                                        ; preds = %4, %.critedge, %30
  %.1 = phi i32 [ %32, %30 ], [ 0, %.critedge ], [ 1, %4 ]
  ret i32 %.1
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fabs.f64(double) #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 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, !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,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass