; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/174 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"

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@n = external dso_local global i32, align 4
@t = external dso_local global i32, align 4
@cur = external dso_local global i32, align 4
@a = external dso_local global i64, align 8
@sum = external dso_local global i64, align 8
@k = external dso_local global i64, align 8
@num = external dso_local global [200001 x i64], align 16
@d = external dso_local global [200001 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [8 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
  store i32 0, ptr %1, align 4
  %3 = call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %4 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %5 = getelementptr i8, ptr %4, i64 -24
  %6 = load i64, ptr %5, align 8
  %7 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %6
  %8 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %7, ptr noundef null)
  %9 = load ptr, ptr @_ZSt4cout, align 8, !tbaa !5
  %10 = getelementptr i8, ptr %9, i64 -24
  %11 = load i64, ptr %10, align 8
  %12 = getelementptr inbounds i8, ptr @_ZSt4cout, i64 %11
  %13 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %12, ptr noundef null)
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !8
  br label %15

15:                                               ; preds = %87, %0
  %16 = load i32, ptr %2, align 4, !tbaa !8
  %17 = load i32, ptr @n, align 4, !tbaa !8
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %20, label %19

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

20:                                               ; preds = %15
  %21 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @t)
  %22 = load i32, ptr @t, align 4, !tbaa !8
  %23 = icmp eq i32 %22, 1
  br i1 %23, label %24, label %37

24:                                               ; preds = %20
  %25 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @a)
  %26 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %25, ptr noundef nonnull align 8 dereferenceable(8) @k)
  %27 = load i64, ptr @a, align 8, !tbaa !11
  %28 = load i64, ptr @k, align 8, !tbaa !11
  %29 = mul nsw i64 %27, %28
  %30 = load i64, ptr @sum, align 8, !tbaa !11
  %31 = add nsw i64 %30, %29
  store i64 %31, ptr @sum, align 8, !tbaa !11
  %32 = load i64, ptr @k, align 8, !tbaa !11
  %33 = load i64, ptr @a, align 8, !tbaa !11
  %34 = getelementptr inbounds [200001 x i64], ptr @d, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = add nsw i64 %35, %32
  store i64 %36, ptr %34, align 8, !tbaa !11
  br label %79

37:                                               ; preds = %20
  %38 = load i32, ptr @t, align 4, !tbaa !8
  %39 = icmp eq i32 %38, 2
  br i1 %39, label %40, label %54

40:                                               ; preds = %37
  %41 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @k)
  %42 = load i64, ptr @k, align 8, !tbaa !11
  %43 = load i64, ptr @sum, align 8, !tbaa !11
  %44 = add nsw i64 %43, %42
  store i64 %44, ptr @sum, align 8, !tbaa !11
  %45 = load i64, ptr @k, align 8, !tbaa !11
  %46 = load i32, ptr @cur, align 4, !tbaa !8
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [200001 x i64], ptr @num, i64 0, i64 %47
  store i64 %45, ptr %48, align 8, !tbaa !11
  %49 = load i32, ptr @cur, align 4, !tbaa !8
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [200001 x i64], ptr @d, i64 0, i64 %50
  store i64 0, ptr %51, align 8, !tbaa !11
  %52 = load i32, ptr @cur, align 4, !tbaa !8
  %53 = add nsw i32 %52, 1
  store i32 %53, ptr @cur, align 4, !tbaa !8
  br label %78

54:                                               ; preds = %37
  %55 = load i32, ptr @cur, align 4, !tbaa !8
  %56 = add nsw i32 %55, -1
  store i32 %56, ptr @cur, align 4, !tbaa !8
  %57 = load i32, ptr @cur, align 4, !tbaa !8
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [200001 x i64], ptr @num, i64 0, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !11
  %61 = load i32, ptr @cur, align 4, !tbaa !8
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [200001 x i64], ptr @d, i64 0, i64 %62
  %64 = load i64, ptr %63, align 8, !tbaa !11
  %65 = add nsw i64 %60, %64
  %66 = load i64, ptr @sum, align 8, !tbaa !11
  %67 = sub nsw i64 %66, %65
  store i64 %67, ptr @sum, align 8, !tbaa !11
  %68 = load i32, ptr @cur, align 4, !tbaa !8
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [200001 x i64], ptr @d, i64 0, i64 %69
  %71 = load i64, ptr %70, align 8, !tbaa !11
  %72 = load i32, ptr @cur, align 4, !tbaa !8
  %73 = sub nsw i32 %72, 1
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [200001 x i64], ptr @d, i64 0, i64 %74
  %76 = load i64, ptr %75, align 8, !tbaa !11
  %77 = add nsw i64 %76, %71
  store i64 %77, ptr %75, align 8, !tbaa !11
  br label %78

78:                                               ; preds = %54, %40
  br label %79

79:                                               ; preds = %78, %24
  %80 = load i64, ptr @sum, align 8, !tbaa !11
  %81 = sitofp i64 %80 to double
  %82 = load i32, ptr @cur, align 4, !tbaa !8
  %83 = sub nsw i32 %82, 1
  %84 = sitofp i32 %83 to double
  %85 = fdiv double %81, %84
  %86 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %85)
  br label %87

87:                                               ; preds = %79
  %88 = load i32, ptr %2, align 4, !tbaa !8
  %89 = add nsw i32 %88, 1
  store i32 %89, ptr %2, align 4, !tbaa !8
  br label %15, !llvm.loop !13

90:                                               ; preds = %19
  ret i32 0
}

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) #1

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) #2 align 2

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) #1

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #4 align 2

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

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

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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@n = external dso_local global i32, align 4
@t = external dso_local global i32, align 4
@cur = external dso_local local_unnamed_addr global i32, align 4
@a = external dso_local global i64, align 8
@sum = external dso_local local_unnamed_addr global i64, align 8
@k = external dso_local global i64, align 8
@num = external dso_local local_unnamed_addr global [200001 x i64], align 16
@d = external dso_local local_unnamed_addr global [200001 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %2 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %3 = getelementptr i8, ptr %2, i64 -24
  %4 = load i64, ptr %3, align 8
  %5 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %4
  %6 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %5, ptr noundef null)
  %7 = load ptr, ptr @_ZSt4cout, align 8, !tbaa !5
  %8 = getelementptr i8, ptr %7, i64 -24
  %9 = load i64, ptr %8, align 8
  %10 = getelementptr inbounds i8, ptr @_ZSt4cout, i64 %9
  %11 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %10, ptr noundef null)
  %12 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %13 = load i32, ptr @n, align 4, !tbaa !8
  %14 = icmp sgt i32 %13, 0
  br i1 %14, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %54, %0
  ret i32 0

.lr.ph:                                           ; preds = %0, %54
  %.05 = phi i32 [ %62, %54 ], [ 0, %0 ]
  %15 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @t)
  %16 = load i32, ptr @t, align 4, !tbaa !8
  switch i32 %16, label %38 [
    i32 1, label %17
    i32 2, label %28
  ]

17:                                               ; preds = %.lr.ph
  %18 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @a)
  %19 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %18, ptr noundef nonnull align 8 dereferenceable(8) @k)
  %20 = load i64, ptr @a, align 8, !tbaa !11
  %21 = load i64, ptr @k, align 8, !tbaa !11
  %22 = mul nsw i64 %21, %20
  %23 = load i64, ptr @sum, align 8, !tbaa !11
  %24 = add nsw i64 %23, %22
  store i64 %24, ptr @sum, align 8, !tbaa !11
  %25 = getelementptr inbounds [200001 x i64], ptr @d, i64 0, i64 %20
  %26 = load i64, ptr %25, align 8, !tbaa !11
  %27 = add nsw i64 %26, %21
  store i64 %27, ptr %25, align 8, !tbaa !11
  %.pre = load i32, ptr @cur, align 4, !tbaa !8
  br label %54

28:                                               ; preds = %.lr.ph
  %29 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @k)
  %30 = load i64, ptr @k, align 8, !tbaa !11
  %31 = load i64, ptr @sum, align 8, !tbaa !11
  %32 = add nsw i64 %31, %30
  store i64 %32, ptr @sum, align 8, !tbaa !11
  %33 = load i32, ptr @cur, align 4, !tbaa !8
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [200001 x i64], ptr @num, i64 0, i64 %34
  store i64 %30, ptr %35, align 8, !tbaa !11
  %36 = getelementptr inbounds [200001 x i64], ptr @d, i64 0, i64 %34
  store i64 0, ptr %36, align 8, !tbaa !11
  %37 = add nsw i32 %33, 1
  store i32 %37, ptr @cur, align 4, !tbaa !8
  br label %54

38:                                               ; preds = %.lr.ph
  %39 = load i32, ptr @cur, align 4, !tbaa !8
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr @cur, align 4, !tbaa !8
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [200001 x i64], ptr @num, i64 0, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !11
  %44 = getelementptr inbounds [200001 x i64], ptr @d, i64 0, i64 %41
  %45 = load i64, ptr %44, align 8, !tbaa !11
  %46 = load i64, ptr @sum, align 8, !tbaa !11
  %47 = add i64 %45, %43
  %48 = sub i64 %46, %47
  store i64 %48, ptr @sum, align 8, !tbaa !11
  %49 = add nsw i32 %39, -2
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [200001 x i64], ptr @d, i64 0, i64 %50
  %52 = load i64, ptr %51, align 8, !tbaa !11
  %53 = add nsw i64 %52, %45
  store i64 %53, ptr %51, align 8, !tbaa !11
  br label %54

54:                                               ; preds = %28, %38, %17
  %55 = phi i32 [ %37, %28 ], [ %40, %38 ], [ %.pre, %17 ]
  %56 = phi i64 [ %32, %28 ], [ %48, %38 ], [ %24, %17 ]
  %57 = sitofp i64 %56 to double
  %58 = add nsw i32 %55, -1
  %59 = sitofp i32 %58 to double
  %60 = fdiv double %57, %59
  %61 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %60)
  %62 = add nuw nsw i32 %.05, 1
  %63 = load i32, ptr @n, align 4, !tbaa !8
  %64 = icmp slt i32 %62, %63
  br i1 %64, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) local_unnamed_addr #2 align 2

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3 align 2

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

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 = { 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 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 = { 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" }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass