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

@n = external dso_local global i32, align 4
@t = external dso_local global i32, align 4
@s = external dso_local global i32, align 4
@cnt = external dso_local global i32, align 4
@mx = external dso_local global i32, align 4
@b = external dso_local global [100000 x i32], align 16
@j = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 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 i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @t)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %15, %0
  %6 = load i32, ptr %2, align 4, !tbaa !5
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %10, label %9

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

10:                                               ; preds = %5
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [100000 x i32], ptr @b, i64 0, i64 %12
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %13)
  br label %15

15:                                               ; preds = %10
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = add nsw i32 %16, 1
  store i32 %17, ptr %2, align 4, !tbaa !5
  br label %5, !llvm.loop !9

18:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %94, %18
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = icmp slt i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %97

24:                                               ; preds = %19
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [100000 x i32], ptr @b, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr @t, align 4, !tbaa !5
  %30 = icmp sle i32 %28, %29
  br i1 %30, label %31, label %90

31:                                               ; preds = %24
  %32 = load i32, ptr @s, align 4, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100000 x i32], ptr @b, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = add nsw i32 %32, %36
  %38 = load i32, ptr @t, align 4, !tbaa !5
  %39 = icmp sle i32 %37, %38
  br i1 %39, label %40, label %51

40:                                               ; preds = %31
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100000 x i32], ptr @b, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = load i32, ptr @s, align 4, !tbaa !5
  %46 = add nsw i32 %45, %44
  store i32 %46, ptr @s, align 4, !tbaa !5
  %47 = load i32, ptr @cnt, align 4, !tbaa !5
  %48 = add nsw i32 %47, 1
  store i32 %48, ptr @cnt, align 4, !tbaa !5
  %49 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @mx, ptr noundef nonnull align 4 dereferenceable(4) @cnt)
  %50 = load i32, ptr %49, align 4, !tbaa !5
  store i32 %50, ptr @mx, align 4, !tbaa !5
  br label %89

51:                                               ; preds = %31
  br label %52

52:                                               ; preds = %67, %51
  %53 = load i32, ptr @j, align 4, !tbaa !5
  %54 = load i32, ptr %3, align 4, !tbaa !5
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %56, label %65

56:                                               ; preds = %52
  %57 = load i32, ptr @s, align 4, !tbaa !5
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [100000 x i32], ptr @b, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = add nsw i32 %57, %61
  %63 = load i32, ptr @t, align 4, !tbaa !5
  %64 = icmp sgt i32 %62, %63
  br label %65

65:                                               ; preds = %56, %52
  %66 = phi i1 [ false, %52 ], [ %64, %56 ]
  br i1 %66, label %67, label %78

67:                                               ; preds = %65
  %68 = load i32, ptr @j, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [100000 x i32], ptr @b, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = load i32, ptr @s, align 4, !tbaa !5
  %73 = sub nsw i32 %72, %71
  store i32 %73, ptr @s, align 4, !tbaa !5
  %74 = load i32, ptr @j, align 4, !tbaa !5
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr @j, align 4, !tbaa !5
  %76 = load i32, ptr @cnt, align 4, !tbaa !5
  %77 = add nsw i32 %76, -1
  store i32 %77, ptr @cnt, align 4, !tbaa !5
  br label %52, !llvm.loop !11

78:                                               ; preds = %65
  %79 = load i32, ptr %3, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [100000 x i32], ptr @b, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = load i32, ptr @s, align 4, !tbaa !5
  %84 = add nsw i32 %83, %82
  store i32 %84, ptr @s, align 4, !tbaa !5
  %85 = load i32, ptr @cnt, align 4, !tbaa !5
  %86 = add nsw i32 %85, 1
  store i32 %86, ptr @cnt, align 4, !tbaa !5
  %87 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @mx, ptr noundef nonnull align 4 dereferenceable(4) @cnt)
  %88 = load i32, ptr %87, align 4, !tbaa !5
  store i32 %88, ptr @mx, align 4, !tbaa !5
  br label %89

89:                                               ; preds = %78, %40
  br label %93

90:                                               ; preds = %24
  store i32 0, ptr @s, align 4, !tbaa !5
  %91 = load i32, ptr %3, align 4, !tbaa !5
  %92 = add nsw i32 %91, 1
  store i32 %92, ptr @j, align 4, !tbaa !5
  store i32 0, ptr @cnt, align 4, !tbaa !5
  br label %93

93:                                               ; preds = %90, %89
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %3, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %3, align 4, !tbaa !5
  br label %19, !llvm.loop !12

97:                                               ; preds = %23
  %98 = load i32, ptr @mx, align 4, !tbaa !5
  %99 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %98)
  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 nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #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 = { inlinehint 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 #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}


; 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
@t = external dso_local global i32, align 4
@s = external dso_local local_unnamed_addr global i32, align 4
@cnt = external dso_local global i32, align 4
@mx = external dso_local global i32, align 4
@b = external dso_local global [100000 x i32], align 16
@j = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

.preheader18:                                     ; preds = %.lr.ph
  %4 = icmp sgt i32 %7, 0
  br i1 %4, label %.lr.ph24, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %5 = getelementptr inbounds [100000 x i32], ptr @b, i64 0, i64 %indvars.iv
  %6 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %5)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = icmp slt i64 %indvars.iv.next, %8
  br i1 %9, label %.lr.ph, label %.preheader18, !llvm.loop !9

._crit_edge:                                      ; preds = %43, %0, %.preheader18
  %10 = load i32, ptr @mx, align 4, !tbaa !5
  %11 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %10)
  ret i32 0

.lr.ph24:                                         ; preds = %.preheader18, %43
  %indvars.iv29 = phi i64 [ %indvars.iv.next30, %43 ], [ 0, %.preheader18 ]
  %12 = getelementptr inbounds [100000 x i32], ptr @b, i64 0, i64 %indvars.iv29
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %14 = load i32, ptr @t, align 4, !tbaa !5
  %.not = icmp sgt i32 %13, %14
  br i1 %.not, label %40, label %15

15:                                               ; preds = %.lr.ph24
  %16 = load i32, ptr @s, align 4, !tbaa !5
  %17 = add nsw i32 %16, %13
  %.not17 = icmp sgt i32 %17, %14
  br i1 %.not17, label %.preheader, label %20

.preheader:                                       ; preds = %15
  %j.promoted = load i32, ptr @j, align 4, !tbaa !5
  %cnt.promoted = load i32, ptr @cnt, align 4, !tbaa !5
  %18 = sext i32 %j.promoted to i64
  %19 = icmp sgt i64 %indvars.iv29, %18
  br i1 %19, label %.lr.ph20, label %.critedge

20:                                               ; preds = %15
  store i32 %17, ptr @s, align 4, !tbaa !5
  %21 = load i32, ptr @cnt, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr @cnt, align 4, !tbaa !5
  %23 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @mx, ptr noundef nonnull align 4 dereferenceable(4) @cnt)
  %24 = load i32, ptr %23, align 4, !tbaa !5
  store i32 %24, ptr @mx, align 4, !tbaa !5
  br label %43

.lr.ph20:                                         ; preds = %.preheader, %29
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %29 ], [ %18, %.preheader ]
  %25 = phi i32 [ %32, %29 ], [ %16, %.preheader ]
  %26 = phi i32 [ %34, %29 ], [ %cnt.promoted, %.preheader ]
  %27 = add nsw i32 %25, %13
  %28 = icmp sgt i32 %27, %14
  br i1 %28, label %29, label %.critedge

29:                                               ; preds = %.lr.ph20
  %30 = getelementptr inbounds [100000 x i32], ptr @b, i64 0, i64 %indvars.iv26
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sub nsw i32 %25, %31
  %indvars.iv.next27 = add nsw i64 %indvars.iv26, 1
  %33 = trunc i64 %indvars.iv.next27 to i32
  store i32 %33, ptr @j, align 4, !tbaa !5
  %34 = add nsw i32 %26, -1
  %35 = and i64 %indvars.iv.next27, 4294967295
  %exitcond.not = icmp eq i64 %35, %indvars.iv29
  br i1 %exitcond.not, label %..critedge.loopexit_crit_edge, label %.lr.ph20, !llvm.loop !11

..critedge.loopexit_crit_edge:                    ; preds = %29
  %.pre32 = add nsw i32 %32, %13
  br label %.critedge

.critedge:                                        ; preds = %.lr.ph20, %..critedge.loopexit_crit_edge, %.preheader
  %.pre-phi = phi i32 [ %17, %.preheader ], [ %.pre32, %..critedge.loopexit_crit_edge ], [ %27, %.lr.ph20 ]
  %36 = phi i32 [ %cnt.promoted, %.preheader ], [ %34, %..critedge.loopexit_crit_edge ], [ %26, %.lr.ph20 ]
  store i32 %.pre-phi, ptr @s, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr @cnt, align 4, !tbaa !5
  %38 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @mx, ptr noundef nonnull align 4 dereferenceable(4) @cnt)
  %39 = load i32, ptr %38, align 4, !tbaa !5
  store i32 %39, ptr @mx, align 4, !tbaa !5
  br label %43

40:                                               ; preds = %.lr.ph24
  store i32 0, ptr @s, align 4, !tbaa !5
  %41 = trunc i64 %indvars.iv29 to i32
  %42 = add i32 %41, 1
  store i32 %42, ptr @j, align 4, !tbaa !5
  store i32 0, ptr @cnt, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %40, %.critedge, %20
  %indvars.iv.next30 = add nuw nsw i64 %indvars.iv29, 1
  %44 = load i32, ptr @n, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = icmp slt i64 %indvars.iv.next30, %45
  br i1 %46, label %.lr.ph24, label %._crit_edge, !llvm.loop !12
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

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

!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,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass