; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/341 Division 2/Problem C (C)

; 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
@p = external dso_local global i32, align 4
@l = external dso_local global [100100 x i32], align 16
@r = external dso_local global [100100 x i32], align 16
@.str = external hidden unnamed_addr constant [5 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 x86_fp80, align 16
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca x86_fp80, align 16
  store i32 0, ptr %1, align 4
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @p)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %25, %0
  %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) #4
  br label %28

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

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

28:                                               ; preds = %16
  %29 = load i32, ptr @l, align 16, !tbaa !5
  %30 = load i32, ptr @n, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100100 x i32], ptr @l, i64 0, i64 %31
  store i32 %29, ptr %32, align 4, !tbaa !5
  %33 = load i32, ptr @r, align 16, !tbaa !5
  %34 = load i32, ptr @n, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [100100 x i32], ptr @r, i64 0, i64 %35
  store i32 %33, ptr %36, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #4
  store x86_fp80 0xK00000000000000000000, ptr %3, align 16, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %118, %28
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = load i32, ptr @n, align 4, !tbaa !5
  %40 = icmp sle i32 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %121

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %43 = load i32, ptr %4, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [100100 x i32], ptr @r, i64 0, i64 %44
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = load i32, ptr @p, align 4, !tbaa !5
  %48 = sdiv i32 %46, %47
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [100100 x i32], ptr @l, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = sub nsw i32 %52, 1
  %54 = load i32, ptr @p, align 4, !tbaa !5
  %55 = sdiv i32 %53, %54
  %56 = sub nsw i32 %48, %55
  %57 = sext i32 %56 to i64
  store i64 %57, ptr %5, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sub nsw i32 %58, 1
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [100100 x i32], ptr @r, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = load i32, ptr @p, align 4, !tbaa !5
  %64 = sdiv i32 %62, %63
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sub nsw i32 %65, 1
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [100100 x i32], ptr @l, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = sub nsw i32 %69, 1
  %71 = load i32, ptr @p, align 4, !tbaa !5
  %72 = sdiv i32 %70, %71
  %73 = sub nsw i32 %64, %72
  %74 = sext i32 %73 to i64
  store i64 %74, ptr %6, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %75 = load i32, ptr %4, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [100100 x i32], ptr @r, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = load i32, ptr %4, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [100100 x i32], ptr @l, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = sub nsw i32 %78, %82
  %84 = add nsw i32 %83, 1
  %85 = sext i32 %84 to i64
  store i64 %85, ptr %7, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %86 = load i32, ptr %4, align 4, !tbaa !5
  %87 = sub nsw i32 %86, 1
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds [100100 x i32], ptr @r, i64 0, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !5
  %91 = load i32, ptr %4, align 4, !tbaa !5
  %92 = sub nsw i32 %91, 1
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [100100 x i32], ptr @l, i64 0, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !5
  %96 = sub nsw i32 %90, %95
  %97 = add nsw i32 %96, 1
  %98 = sext i32 %97 to i64
  store i64 %98, ptr %8, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %99 = load i64, ptr %7, align 8, !tbaa !13
  %100 = load i64, ptr %5, align 8, !tbaa !13
  %101 = sub nsw i64 %99, %100
  %102 = load i64, ptr %8, align 8, !tbaa !13
  %103 = load i64, ptr %6, align 8, !tbaa !13
  %104 = sub nsw i64 %102, %103
  %105 = mul nsw i64 %101, %104
  store i64 %105, ptr %9, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  %106 = load i64, ptr %9, align 8, !tbaa !13
  %107 = sitofp i64 %106 to x86_fp80
  %108 = load i64, ptr %7, align 8, !tbaa !13
  %109 = load i64, ptr %8, align 8, !tbaa !13
  %110 = mul nsw i64 %108, %109
  %111 = sitofp i64 %110 to x86_fp80
  %112 = fdiv x86_fp80 %107, %111
  store x86_fp80 %112, ptr %10, align 16, !tbaa !11
  %113 = load x86_fp80, ptr %10, align 16, !tbaa !11
  %114 = fsub x86_fp80 0xK3FFF8000000000000000, %113
  store x86_fp80 %114, ptr %10, align 16, !tbaa !11
  %115 = load x86_fp80, ptr %10, align 16, !tbaa !11
  %116 = load x86_fp80, ptr %3, align 16, !tbaa !11
  %117 = call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %115, x86_fp80 0xK4009FA00000000000000, x86_fp80 %116)
  store x86_fp80 %117, ptr %3, align 16, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  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 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %118

118:                                              ; preds = %42
  %119 = load i32, ptr %4, align 4, !tbaa !5
  %120 = add nsw i32 %119, 1
  store i32 %120, ptr %4, align 4, !tbaa !5
  br label %37, !llvm.loop !15

121:                                              ; preds = %41
  %122 = load x86_fp80, ptr %3, align 16, !tbaa !11
  %123 = fptrunc x86_fp80 %122 to double
  %124 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, double noundef %123)
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #4
  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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare x86_fp80 @llvm.fmuladd.f80(x86_fp80, x86_fp80, x86_fp80) #3

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long double", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !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
@p = external dso_local global i32, align 4
@l = external dso_local global [100100 x i32], align 16
@r = external dso_local global [100100 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind 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, ptr noundef nonnull @p)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 0
  br i1 %3, label %.lr.ph, label %._crit_edge.thread

._crit_edge.thread:                               ; preds = %0
  %.pre = sext i32 %2 to i64
  %4 = load i32, ptr @l, align 16, !tbaa !5
  %5 = getelementptr inbounds [100100 x i32], ptr @l, i64 0, i64 %.pre
  store i32 %4, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr @r, align 16, !tbaa !5
  %7 = getelementptr inbounds [100100 x i32], ptr @r, i64 0, i64 %.pre
  store i32 %6, ptr %7, align 4, !tbaa !5
  br label %._crit_edge35

._crit_edge:                                      ; preds = %.lr.ph
  %8 = load i32, ptr @l, align 16, !tbaa !5
  %9 = getelementptr inbounds [100100 x i32], ptr @l, i64 0, i64 %18
  store i32 %8, ptr %9, align 4, !tbaa !5
  %10 = load i32, ptr @r, align 16, !tbaa !5
  %11 = getelementptr inbounds [100100 x i32], ptr @r, i64 0, i64 %18
  store i32 %10, ptr %11, align 4, !tbaa !5
  %.not30 = icmp slt i32 %17, 1
  br i1 %.not30, label %._crit_edge35, label %.lr.ph34

.lr.ph34:                                         ; preds = %._crit_edge
  %12 = load i32, ptr @p, align 4, !tbaa !5
  %13 = add nuw i32 %17, 1
  %wide.trip.count = zext i32 %13 to i64
  br label %22

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %14 = getelementptr inbounds [100100 x i32], ptr @l, i64 0, i64 %indvars.iv
  %15 = getelementptr inbounds [100100 x i32], ptr @r, i64 0, i64 %indvars.iv
  %16 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %14, ptr noundef nonnull %15)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = icmp slt i64 %indvars.iv.next, %18
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge35.loopexit:                           ; preds = %22
  %20 = fptrunc x86_fp80 %53 to double
  br label %._crit_edge35

._crit_edge35:                                    ; preds = %._crit_edge.thread, %._crit_edge35.loopexit, %._crit_edge
  %.025.lcssa = phi double [ 0.000000e+00, %._crit_edge ], [ %20, %._crit_edge35.loopexit ], [ 0.000000e+00, %._crit_edge.thread ]
  %21 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, double noundef %.025.lcssa)
  ret i32 0

22:                                               ; preds = %.lr.ph34, %22
  %23 = phi i32 [ %8, %.lr.ph34 ], [ %29, %22 ]
  %24 = phi i32 [ %10, %.lr.ph34 ], [ %26, %22 ]
  %indvars.iv40 = phi i64 [ 1, %.lr.ph34 ], [ %indvars.iv.next41, %22 ]
  %.02532 = phi x86_fp80 [ 0xK00000000000000000000, %.lr.ph34 ], [ %53, %22 ]
  %25 = getelementptr inbounds [100100 x i32], ptr @r, i64 0, i64 %indvars.iv40
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = sdiv i32 %26, %12
  %28 = getelementptr inbounds [100100 x i32], ptr @l, i64 0, i64 %indvars.iv40
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = add nsw i32 %29, -1
  %31 = sdiv i32 %30, %12
  %32 = sub nsw i32 %27, %31
  %33 = sext i32 %32 to i64
  %34 = sdiv i32 %24, %12
  %35 = add nsw i32 %23, -1
  %36 = sdiv i32 %35, %12
  %37 = sub nsw i32 %34, %36
  %38 = sext i32 %37 to i64
  %39 = add i32 %26, 1
  %40 = sub i32 %39, %29
  %41 = sext i32 %40 to i64
  %42 = add i32 %24, 1
  %43 = sub i32 %42, %23
  %44 = sext i32 %43 to i64
  %45 = sub nsw i64 %41, %33
  %46 = sub nsw i64 %44, %38
  %47 = mul nsw i64 %46, %45
  %48 = sitofp i64 %47 to x86_fp80
  %49 = mul nsw i64 %44, %41
  %50 = sitofp i64 %49 to x86_fp80
  %51 = fdiv x86_fp80 %48, %50
  %52 = fsub x86_fp80 0xK3FFF8000000000000000, %51
  %53 = tail call x86_fp80 @llvm.fmuladd.f80(x86_fp80 %52, x86_fp80 0xK4009FA00000000000000, x86_fp80 %.02532)
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next41, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge35.loopexit, label %22, !llvm.loop !11
}

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

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

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

attributes #0 = { mustprogress nofree norecurse 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 = { 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 = { mustprogress 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 = !{!"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}


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