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

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

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

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

13:                                               ; preds = %8
  %14 = load i32, ptr %3, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %15
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %16)
  br label %18

18:                                               ; preds = %13
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %3, align 4, !tbaa !5
  br label %8, !llvm.loop !9

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

22:                                               ; preds = %117, %21
  %23 = load i32, ptr %6, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %120

27:                                               ; preds = %22
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = load i32, ptr %6, align 4, !tbaa !5
  %33 = sub nsw i32 %32, 1
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = icmp sle i32 %31, %36
  br i1 %37, label %38, label %52

38:                                               ; preds = %27
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = sub nsw i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sub nsw i32 %43, %47
  %49 = sext i32 %48 to i64
  %50 = load i64, ptr %4, align 8, !tbaa !11
  %51 = add nsw i64 %50, %49
  store i64 %51, ptr %4, align 8, !tbaa !11
  br label %116

52:                                               ; preds = %27
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = sub nsw i32 %53, 1
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = load i64, ptr %4, align 8, !tbaa !11
  %60 = add nsw i64 %58, %59
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = icmp slt i64 %60, %65
  br i1 %66, label %67, label %102

67:                                               ; preds = %52
  %68 = load i32, ptr %6, align 4, !tbaa !5
  %69 = sub nsw i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = load i64, ptr %4, align 8, !tbaa !11
  %75 = add nsw i64 %73, %74
  %76 = load i32, ptr %6, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = sub nsw i64 %75, %80
  %82 = call noundef i64 @_ZSt3absx(i64 noundef %81)
  %83 = load i64, ptr %5, align 8, !tbaa !11
  %84 = add nsw i64 %83, %82
  store i64 %84, ptr %5, align 8, !tbaa !11
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = sub nsw i32 %85, 1
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %87
  %89 = load i32, ptr %88, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = load i64, ptr %4, align 8, !tbaa !11
  %92 = add nsw i64 %90, %91
  %93 = load i32, ptr %6, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = sub nsw i64 %92, %97
  %99 = call noundef i64 @_ZSt3absx(i64 noundef %98)
  %100 = load i64, ptr %4, align 8, !tbaa !11
  %101 = add nsw i64 %100, %99
  store i64 %101, ptr %4, align 8, !tbaa !11
  br label %102

102:                                              ; preds = %67, %52
  %103 = load i32, ptr %6, align 4, !tbaa !5
  %104 = sub nsw i32 %103, 1
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %105
  %107 = load i32, ptr %106, align 4, !tbaa !5
  %108 = load i32, ptr %6, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %109
  %111 = load i32, ptr %110, align 4, !tbaa !5
  %112 = sub nsw i32 %107, %111
  %113 = sext i32 %112 to i64
  %114 = load i64, ptr %4, align 8, !tbaa !11
  %115 = add nsw i64 %114, %113
  store i64 %115, ptr %4, align 8, !tbaa !11
  br label %116

116:                                              ; preds = %102, %38
  br label %117

117:                                              ; preds = %116
  %118 = load i32, ptr %6, align 4, !tbaa !5
  %119 = add nsw i32 %118, 1
  store i32 %119, ptr %6, align 4, !tbaa !5
  br label %22, !llvm.loop !13

120:                                              ; preds = %26
  %121 = load i64, ptr %5, align 8, !tbaa !11
  call void @_Z2trIxJEEvT_DpRKT0_(i64 noundef %121)
  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 4, ptr %2) #5
  ret i32 0
}

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2trIxJEEvT_DpRKT0_(i64 noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { 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 = { 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 = !{!"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 long", !7, i64 0}
!13 = distinct !{!13, !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"

@h = external dso_local global [100100 x i32], align 16
@.str = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %.not38 = icmp slt i32 %3, 1
  br i1 %.not38, label %._crit_edge, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph
  %.not3640 = icmp slt i32 %6, 1
  br i1 %.not3640, label %._crit_edge, label %.lr.ph44.preheader

.lr.ph44.preheader:                               ; preds = %.preheader
  %.pre = load i32, ptr @h, align 16, !tbaa !5
  br label %.lr.ph44

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

._crit_edge:                                      ; preds = %37, %0, %.preheader
  %.025.lcssa = phi i64 [ 0, %.preheader ], [ 0, %0 ], [ %.2, %37 ]
  call void @_Z2trIxJEEvT_DpRKT0_(i64 noundef %.025.lcssa)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 0

.lr.ph44:                                         ; preds = %.lr.ph44.preheader, %37
  %.pre5051 = phi i32 [ %6, %.lr.ph44.preheader ], [ %.pre5052, %37 ]
  %8 = phi i32 [ %6, %.lr.ph44.preheader ], [ %38, %37 ]
  %9 = phi i32 [ %.pre, %.lr.ph44.preheader ], [ %39, %37 ]
  %indvars.iv46 = phi i64 [ 1, %.lr.ph44.preheader ], [ %indvars.iv.next47, %37 ]
  %.02542 = phi i64 [ 0, %.lr.ph44.preheader ], [ %.2, %37 ]
  %.02641 = phi i64 [ 0, %.lr.ph44.preheader ], [ %41, %37 ]
  %10 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %indvars.iv46
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = add nsw i64 %indvars.iv46, -1
  %13 = getelementptr inbounds [100100 x i32], ptr @h, i64 0, i64 %12
  %.not37 = icmp sgt i32 %11, %9
  br i1 %.not37, label %16, label %14

14:                                               ; preds = %.lr.ph44
  %15 = sub nsw i32 %9, %11
  br label %37

16:                                               ; preds = %.lr.ph44
  %17 = sext i32 %9 to i64
  %18 = add nsw i64 %.02641, %17
  %19 = sext i32 %11 to i64
  %20 = icmp slt i64 %18, %19
  br i1 %20, label %21, label %33

21:                                               ; preds = %16
  %22 = sub nsw i64 %18, %19
  %23 = call noundef i64 @_ZSt3absx(i64 noundef %22)
  %24 = add nsw i64 %23, %.02542
  %25 = load i32, ptr %13, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = add nsw i64 %.02641, %26
  %28 = load i32, ptr %10, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = sub i64 %27, %29
  %31 = call noundef i64 @_ZSt3absx(i64 noundef %30)
  %32 = add nsw i64 %31, %.02641
  %.pre49 = load i32, ptr %10, align 4, !tbaa !5
  %.pre50.pre = load i32, ptr %1, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %21, %16
  %.pre50 = phi i32 [ %.pre50.pre, %21 ], [ %.pre5051, %16 ]
  %34 = phi i32 [ %.pre49, %21 ], [ %11, %16 ]
  %.127 = phi i64 [ %32, %21 ], [ %.02641, %16 ]
  %.1 = phi i64 [ %24, %21 ], [ %.02542, %16 ]
  %35 = load i32, ptr %13, align 4, !tbaa !5
  %36 = sub nsw i32 %35, %34
  br label %37

37:                                               ; preds = %14, %33
  %.sink55 = phi i32 [ %15, %14 ], [ %36, %33 ]
  %.02641.sink = phi i64 [ %.02641, %14 ], [ %.127, %33 ]
  %.pre5052 = phi i32 [ %.pre5051, %14 ], [ %.pre50, %33 ]
  %38 = phi i32 [ %8, %14 ], [ %.pre50, %33 ]
  %39 = phi i32 [ %11, %14 ], [ %34, %33 ]
  %.2 = phi i64 [ %.02542, %14 ], [ %.1, %33 ]
  %40 = sext i32 %.sink55 to i64
  %41 = add nsw i64 %.02641.sink, %40
  %indvars.iv.next47 = add nuw nsw i64 %indvars.iv46, 1
  %42 = sext i32 %38 to i64
  %.not36.not = icmp slt i64 %indvars.iv46, %42
  br i1 %.not36.not, label %.lr.ph44, label %._crit_edge, !llvm.loop !11
}

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2trIxJEEvT_DpRKT0_(i64 noundef) 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { 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 = !{!"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,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass