; LLVM IR from imteekay/algorithms :: competitive-programming/uri (dating_online)

; 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
@v = external dso_local global [100001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca double, align 8
  %4 = alloca double, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  br label %8

8:                                                ; preds = %79, %0
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @N)
  %10 = icmp ne i32 %9, -1
  br i1 %10, label %11, label %91

11:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %22, %11
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr @N, align 4, !tbaa !5
  %15 = icmp slt i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %25

17:                                               ; preds = %12
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100001 x i32], ptr @v, i64 0, i64 %19
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %20)
  br label %22

22:                                               ; preds = %17
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !9

25:                                               ; preds = %16
  %26 = load i32, ptr @N, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr @v, i64 %27
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @v, ptr noundef %28)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %29 = load i32, ptr @N, align 4, !tbaa !5
  %30 = sitofp i32 %29 to double
  %31 = fdiv double 0x401921FB54442D18, %30
  %32 = call double @sin(double noundef %31) #5
  store double %32, ptr %3, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store double 0.000000e+00, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  %33 = load i32, ptr @N, align 4, !tbaa !5
  %34 = sub nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100001 x i32], ptr @v, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = sitofp i32 %37 to double
  store double %38, ptr %5, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %39 = load i32, ptr @N, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 2
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100001 x i32], ptr @v, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sitofp i32 %43 to double
  store double %44, ptr %6, align 8, !tbaa !11
  %45 = load double, ptr %5, align 8, !tbaa !11
  %46 = load double, ptr %6, align 8, !tbaa !11
  %47 = fmul double %45, %46
  %48 = load double, ptr %3, align 8, !tbaa !11
  %49 = fmul double %47, %48
  %50 = fdiv double %49, 2.000000e+00
  %51 = load double, ptr %4, align 8, !tbaa !11
  %52 = fadd double %51, %50
  store double %52, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %53 = load i32, ptr @N, align 4, !tbaa !5
  %54 = sub nsw i32 %53, 3
  store i32 %54, ptr %7, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %76, %25
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = icmp sge i32 %56, 0
  br i1 %57, label %59, label %58

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

59:                                               ; preds = %55
  %60 = load i32, ptr %7, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [100001 x i32], ptr @v, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = add nsw i32 %64, 2
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [100001 x i32], ptr @v, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = mul nsw i32 %63, %68
  %70 = sitofp i32 %69 to double
  %71 = load double, ptr %3, align 8, !tbaa !11
  %72 = fmul double %70, %71
  %73 = fdiv double %72, 2.000000e+00
  %74 = load double, ptr %4, align 8, !tbaa !11
  %75 = fadd double %74, %73
  store double %75, ptr %4, align 8, !tbaa !11
  br label %76

76:                                               ; preds = %59
  %77 = load i32, ptr %7, align 4, !tbaa !5
  %78 = add nsw i32 %77, -1
  store i32 %78, ptr %7, align 4, !tbaa !5
  br label %55, !llvm.loop !13

79:                                               ; preds = %58
  %80 = load i32, ptr @v, align 16, !tbaa !5
  %81 = load i32, ptr getelementptr inbounds ([100001 x i32], ptr @v, i64 0, i64 1), align 4, !tbaa !5
  %82 = mul nsw i32 %80, %81
  %83 = sitofp i32 %82 to double
  %84 = load double, ptr %3, align 8, !tbaa !11
  %85 = fmul double %83, %84
  %86 = fdiv double %85, 2.000000e+00
  %87 = load double, ptr %4, align 8, !tbaa !11
  %88 = fadd double %87, %86
  store double %88, ptr %4, align 8, !tbaa !11
  %89 = load double, ptr %4, align 8, !tbaa !11
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %89)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  br label %8, !llvm.loop !14

91:                                               ; preds = %8
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) #3

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

declare i32 @printf(ptr noundef, ...) #1

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


; 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 global i32, align 4
@v = external dso_local global [100001 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @N)
  %.not25 = icmp eq i32 %1, -1
  br i1 %.not25, label %._crit_edge26, label %.preheader

.preheader:                                       ; preds = %0, %._crit_edge23
  %2 = load i32, ptr @N, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %.preheader.._crit_edge_crit_edge

.preheader.._crit_edge_crit_edge:                 ; preds = %.preheader
  %.pre = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.preheader.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.preheader.._crit_edge_crit_edge ], [ %38, %.lr.ph ]
  %4 = getelementptr inbounds i32, ptr @v, i64 %.pre-phi
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @v, ptr noundef nonnull %4)
  %5 = load i32, ptr @N, align 4, !tbaa !5
  %6 = sitofp i32 %5 to double
  %7 = fdiv double 0x401921FB54442D18, %6
  %8 = tail call double @sin(double noundef %7) #4
  %9 = load i32, ptr @N, align 4, !tbaa !5
  %10 = add nsw i32 %9, -2
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [100001 x i32], ptr @v, i64 0, i64 %11
  %13 = load <2 x i32>, ptr %12, align 4, !tbaa !5
  %14 = sitofp <2 x i32> %13 to <2 x double>
  %shift = shufflevector <2 x double> %14, <2 x double> poison, <2 x i32> <i32 1, i32 poison>
  %15 = fmul <2 x double> %shift, %14
  %16 = extractelement <2 x double> %15, i64 0
  %17 = fmul double %8, %16
  %18 = fmul double %17, 5.000000e-01
  %19 = fadd double %18, 0.000000e+00
  %20 = icmp sgt i32 %9, 2
  br i1 %20, label %.lr.ph22.preheader, label %._crit_edge23

.lr.ph22.preheader:                               ; preds = %._crit_edge
  %21 = add nsw i32 %9, -3
  %22 = zext i32 %21 to i64
  %23 = and i64 %22, 1
  %lcmp.mod.not.not = icmp eq i64 %23, 0
  br i1 %lcmp.mod.not.not, label %.lr.ph22.prol, label %.lr.ph22.prol.loopexit

.lr.ph22.prol:                                    ; preds = %.lr.ph22.preheader
  %24 = getelementptr inbounds [100001 x i32], ptr @v, i64 0, i64 %22
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = add nuw nsw i64 %22, 2
  %27 = getelementptr inbounds [100001 x i32], ptr @v, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = mul nsw i32 %28, %25
  %30 = sitofp i32 %29 to double
  %31 = fmul double %8, %30
  %32 = fmul double %31, 5.000000e-01
  %33 = fadd double %19, %32
  %indvars.iv.next31.prol = add nsw i64 %22, -1
  br label %.lr.ph22.prol.loopexit

.lr.ph22.prol.loopexit:                           ; preds = %.lr.ph22.prol, %.lr.ph22.preheader
  %.lcssa36.unr = phi double [ poison, %.lr.ph22.preheader ], [ %33, %.lr.ph22.prol ]
  %indvars.iv30.unr = phi i64 [ %22, %.lr.ph22.preheader ], [ %indvars.iv.next31.prol, %.lr.ph22.prol ]
  %.01619.unr = phi double [ %19, %.lr.ph22.preheader ], [ %33, %.lr.ph22.prol ]
  %34 = icmp eq i32 %21, 0
  br i1 %34, label %._crit_edge23, label %.lr.ph22

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %35 = getelementptr inbounds [100001 x i32], ptr @v, i64 0, i64 %indvars.iv
  %36 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %35)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = load i32, ptr @N, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = icmp slt i64 %indvars.iv.next, %38
  br i1 %39, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge23:                                    ; preds = %.lr.ph22.prol.loopexit, %.lr.ph22, %._crit_edge
  %.016.lcssa = phi double [ %19, %._crit_edge ], [ %.lcssa36.unr, %.lr.ph22.prol.loopexit ], [ %68, %.lr.ph22 ]
  %40 = load i32, ptr @v, align 16, !tbaa !5
  %41 = load i32, ptr getelementptr inbounds (i8, ptr @v, i64 4), align 4, !tbaa !5
  %42 = mul nsw i32 %41, %40
  %43 = sitofp i32 %42 to double
  %44 = fmul double %8, %43
  %45 = fmul double %44, 5.000000e-01
  %46 = fadd double %.016.lcssa, %45
  %47 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %46)
  %48 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @N)
  %.not = icmp eq i32 %48, -1
  br i1 %.not, label %._crit_edge26, label %.preheader, !llvm.loop !11

.lr.ph22:                                         ; preds = %.lr.ph22.prol.loopexit, %.lr.ph22
  %indvars.iv30 = phi i64 [ %indvars.iv.next31.1, %.lr.ph22 ], [ %indvars.iv30.unr, %.lr.ph22.prol.loopexit ]
  %.01619 = phi double [ %68, %.lr.ph22 ], [ %.01619.unr, %.lr.ph22.prol.loopexit ]
  %49 = getelementptr inbounds [100001 x i32], ptr @v, i64 0, i64 %indvars.iv30
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = add nuw nsw i64 %indvars.iv30, 2
  %52 = getelementptr inbounds [100001 x i32], ptr @v, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = mul nsw i32 %53, %50
  %55 = sitofp i32 %54 to double
  %56 = fmul double %8, %55
  %57 = fmul double %56, 5.000000e-01
  %58 = fadd double %.01619, %57
  %indvars.iv.next31 = add nsw i64 %indvars.iv30, -1
  %59 = getelementptr inbounds [100001 x i32], ptr @v, i64 0, i64 %indvars.iv.next31
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = add nsw i64 %indvars.iv30, 1
  %62 = getelementptr inbounds [100001 x i32], ptr @v, i64 0, i64 %61
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = mul nsw i32 %63, %60
  %65 = sitofp i32 %64 to double
  %66 = fmul double %8, %65
  %67 = fmul double %66, 5.000000e-01
  %68 = fadd double %58, %67
  %indvars.iv.next31.1 = add nsw i64 %indvars.iv30, -2
  %.not34.1 = icmp eq i64 %indvars.iv.next31, 0
  br i1 %.not34.1, label %._crit_edge23, label %.lr.ph22, !llvm.loop !12

._crit_edge26:                                    ; preds = %._crit_edge23, %0
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { mustprogress norecurse 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 = { nofree 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 #2 = { inlinehint 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 #3 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass