; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/29 Beta Division 2/Problem B (B)

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

@l = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@v = external dso_local global i32, align 4
@g = external dso_local global i32, align 4
@r = external dso_local global i32, align 4
@t = external dso_local global [10000 x i32], align 16
@cur = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@.str = 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 i32, align 4
  store i32 0, ptr %1, align 4
  %4 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @l)
  %5 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 4 dereferenceable(4) @d)
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 4 dereferenceable(4) @v)
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 4 dereferenceable(4) @g)
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 4 dereferenceable(4) @r)
  store i32 1, ptr @t, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %43, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp sle i32 %10, 10000
  br i1 %11, label %13, label %12

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

13:                                               ; preds = %9
  %14 = load i32, ptr @cur, align 4, !tbaa !5
  %15 = icmp eq i32 %14, 0
  br i1 %15, label %16, label %29

16:                                               ; preds = %13
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [10000 x i32], ptr @t, i64 0, i64 %18
  store i32 1, ptr %19, align 4, !tbaa !5
  %20 = load i32, ptr @cnt, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @cnt, align 4, !tbaa !5
  %22 = load i32, ptr @cnt, align 4, !tbaa !5
  %23 = load i32, ptr @g, align 4, !tbaa !5
  %24 = icmp eq i32 %22, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %16
  store i32 0, ptr @cnt, align 4, !tbaa !5
  %26 = load i32, ptr @cur, align 4, !tbaa !5
  %27 = sub nsw i32 1, %26
  store i32 %27, ptr @cur, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %25, %16
  br label %42

29:                                               ; preds = %13
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [10000 x i32], ptr @t, i64 0, i64 %31
  store i32 2, ptr %32, align 4, !tbaa !5
  %33 = load i32, ptr @cnt, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  store i32 %34, ptr @cnt, align 4, !tbaa !5
  %35 = load i32, ptr @cnt, align 4, !tbaa !5
  %36 = load i32, ptr @r, align 4, !tbaa !5
  %37 = icmp eq i32 %35, %36
  br i1 %37, label %38, label %41

38:                                               ; preds = %29
  store i32 0, ptr @cnt, align 4, !tbaa !5
  %39 = load i32, ptr @cur, align 4, !tbaa !5
  %40 = sub nsw i32 1, %39
  store i32 %40, ptr @cur, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %38, %29
  br label %42

42:                                               ; preds = %41, %28
  br label %43

43:                                               ; preds = %42
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !9

46:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  %47 = load i32, ptr @d, align 4, !tbaa !5
  %48 = sitofp i32 %47 to double
  %49 = load i32, ptr @v, align 4, !tbaa !5
  %50 = sitofp i32 %49 to double
  %51 = fdiv double %48, %50
  %52 = call double @llvm.floor.f64(double %51)
  %53 = fadd double %52, 1.000000e+00
  %54 = fptosi double %53 to i32
  store i32 %54, ptr %3, align 4, !tbaa !5
  %55 = load i32, ptr %3, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [10000 x i32], ptr @t, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = icmp eq i32 %58, 1
  br i1 %59, label %60, label %67

60:                                               ; preds = %46
  %61 = load i32, ptr @l, align 4, !tbaa !5
  %62 = sitofp i32 %61 to double
  %63 = load i32, ptr @v, align 4, !tbaa !5
  %64 = sitofp i32 %63 to double
  %65 = fdiv double %62, %64
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %65)
  br label %91

67:                                               ; preds = %46
  br label %68

68:                                               ; preds = %74, %67
  %69 = load i32, ptr %3, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [10000 x i32], ptr @t, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = icmp eq i32 %72, 2
  br i1 %73, label %74, label %77

74:                                               ; preds = %68
  %75 = load i32, ptr %3, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %3, align 4, !tbaa !5
  br label %68, !llvm.loop !11

77:                                               ; preds = %68
  %78 = load i32, ptr %3, align 4, !tbaa !5
  %79 = add nsw i32 %78, -1
  store i32 %79, ptr %3, align 4, !tbaa !5
  %80 = load i32, ptr %3, align 4, !tbaa !5
  %81 = sitofp i32 %80 to double
  %82 = load i32, ptr @l, align 4, !tbaa !5
  %83 = load i32, ptr @d, align 4, !tbaa !5
  %84 = sub nsw i32 %82, %83
  %85 = sitofp i32 %84 to double
  %86 = load i32, ptr @v, align 4, !tbaa !5
  %87 = sitofp i32 %86 to double
  %88 = fdiv double %85, %87
  %89 = fadd double %81, %88
  %90 = call i32 (ptr, ...) @printf(ptr noundef @.str, double noundef %89)
  br label %91

91:                                               ; preds = %77, %60
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  ret i32 0
}

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) #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 double @llvm.floor.f64(double) #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 = distinct !{!11, !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"

%"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 }

@l = external dso_local global i32, align 4
@d = external dso_local global i32, align 4
@v = external dso_local global i32, align 4
@g = external dso_local global i32, align 4
@r = external dso_local global i32, align 4
@t = external dso_local local_unnamed_addr global [10000 x i32], align 16
@cur = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local local_unnamed_addr global i32, align 4
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@.str = 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 noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @l)
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 4 dereferenceable(4) @d)
  %3 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 4 dereferenceable(4) @v)
  %4 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 4 dereferenceable(4) @g)
  %5 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 4 dereferenceable(4) @r)
  store i32 1, ptr @t, align 16, !tbaa !5
  %cur.promoted = load i32, ptr @cur, align 4, !tbaa !5
  %cnt.promoted = load i32, ptr @cnt, align 4, !tbaa !5
  %6 = load i32, ptr @r, align 4
  %7 = load i32, ptr @g, align 4
  br label %21

8:                                                ; preds = %34
  %9 = load i32, ptr @d, align 4, !tbaa !5
  %10 = sitofp i32 %9 to double
  %11 = load i32, ptr @v, align 4, !tbaa !5
  %12 = sitofp i32 %11 to double
  %13 = fdiv double %10, %12
  %14 = tail call double @llvm.floor.f64(double %13)
  %15 = fadd double %14, 1.000000e+00
  %16 = fptosi double %15 to i32
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [10000 x i32], ptr @t, i64 0, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = icmp eq i32 %19, 1
  br i1 %20, label %37, label %.preheader

21:                                               ; preds = %0, %34
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next, %34 ]
  %22 = phi i32 [ %cur.promoted, %0 ], [ %36, %34 ]
  %23 = phi i32 [ %cnt.promoted, %0 ], [ %35, %34 ]
  %24 = icmp eq i32 %22, 0
  %25 = getelementptr inbounds [10000 x i32], ptr @t, i64 0, i64 %indvars.iv
  %26 = add nsw i32 %23, 1
  br i1 %24, label %27, label %30

27:                                               ; preds = %21
  store i32 1, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr @cnt, align 4, !tbaa !5
  %28 = icmp eq i32 %26, %7
  br i1 %28, label %29, label %34

29:                                               ; preds = %27
  store i32 0, ptr @cnt, align 4, !tbaa !5
  br label %.sink.split

30:                                               ; preds = %21
  store i32 2, ptr %25, align 4, !tbaa !5
  store i32 %26, ptr @cnt, align 4, !tbaa !5
  %31 = icmp eq i32 %26, %6
  br i1 %31, label %32, label %34

32:                                               ; preds = %30
  store i32 0, ptr @cnt, align 4, !tbaa !5
  %33 = sub nsw i32 1, %22
  br label %.sink.split

.sink.split:                                      ; preds = %32, %29
  %.sink = phi i32 [ 1, %29 ], [ %33, %32 ]
  store i32 %.sink, ptr @cur, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %.sink.split, %27, %30
  %35 = phi i32 [ %26, %27 ], [ %26, %30 ], [ 0, %.sink.split ]
  %36 = phi i32 [ 0, %27 ], [ %22, %30 ], [ %.sink, %.sink.split ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 10001
  br i1 %exitcond.not, label %8, label %21, !llvm.loop !9

37:                                               ; preds = %8
  %38 = load i32, ptr @l, align 4, !tbaa !5
  %39 = sitofp i32 %38 to double
  %40 = fdiv double %39, %12
  br label %53

.preheader:                                       ; preds = %8, %.preheader
  %indvars.iv12 = phi i64 [ %indvars.iv.next13, %.preheader ], [ %17, %8 ]
  %41 = getelementptr inbounds [10000 x i32], ptr @t, i64 0, i64 %indvars.iv12
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = icmp eq i32 %42, 2
  %indvars.iv.next13 = add nsw i64 %indvars.iv12, 1
  br i1 %43, label %.preheader, label %44, !llvm.loop !11

44:                                               ; preds = %.preheader
  %45 = trunc nsw i64 %indvars.iv12 to i32
  %46 = add nsw i32 %45, -1
  %47 = sitofp i32 %46 to double
  %48 = load i32, ptr @l, align 4, !tbaa !5
  %49 = sub nsw i32 %48, %9
  %50 = sitofp i32 %49 to double
  %51 = fdiv double %50, %12
  %52 = fadd double %51, %47
  br label %53

53:                                               ; preds = %44, %37
  %.sink15 = phi double [ %52, %44 ], [ %40, %37 ]
  %54 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, double noundef %.sink15)
  ret i32 0
}

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 nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 = !{!"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: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass