; LLVM IR from acm-clan/algorithm-stone :: user/codeforces/1607C.Minimum Extraction (main)

; 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 i64, align 8
@a = external dso_local global [200001 x i64], align 16
@sum = external dso_local global i64, align 8
@mx = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  br label %6

6:                                                ; preds = %50, %0
  %7 = load i64, ptr %2, align 8, !tbaa !5
  %8 = add nsw i64 %7, -1
  store i64 %8, ptr %2, align 8, !tbaa !5
  %9 = icmp ne i64 %7, 0
  br i1 %9, label %10, label %53

10:                                               ; preds = %6
  store i64 0, ptr @sum, align 8, !tbaa !5
  store i64 -4557430888798830399, ptr @mx, align 8, !tbaa !5
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  store i64 1, ptr %3, align 8, !tbaa !5
  br label %12

12:                                               ; preds = %21, %10
  %13 = load i64, ptr %3, align 8, !tbaa !5
  %14 = load i64, ptr @n, align 8, !tbaa !5
  %15 = icmp sle i64 %13, %14
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %12
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds [200001 x i64], ptr @a, i64 0, i64 %18
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %19)
  br label %21

21:                                               ; preds = %17
  %22 = load i64, ptr %3, align 8, !tbaa !5
  %23 = add nsw i64 %22, 1
  store i64 %23, ptr %3, align 8, !tbaa !5
  br label %12, !llvm.loop !9

24:                                               ; preds = %16
  %25 = load i64, ptr @n, align 8, !tbaa !5
  %26 = getelementptr inbounds i64, ptr getelementptr inbounds (i64, ptr @a, i64 1), i64 %25
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef getelementptr inbounds (i64, ptr @a, i64 1), ptr noundef %26)
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  store i64 1, ptr %4, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %47, %24
  %28 = load i64, ptr %4, align 8, !tbaa !5
  %29 = load i64, ptr @n, align 8, !tbaa !5
  %30 = icmp sle i64 %28, %29
  br i1 %30, label %32, label %31

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

32:                                               ; preds = %27
  %33 = load i64, ptr @sum, align 8, !tbaa !5
  %34 = load i64, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds [200001 x i64], ptr @a, i64 0, i64 %34
  %36 = load i64, ptr %35, align 8, !tbaa !5
  %37 = sub nsw i64 %36, %33
  store i64 %37, ptr %35, align 8, !tbaa !5
  %38 = load i64, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds [200001 x i64], ptr @a, i64 0, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = load i64, ptr @sum, align 8, !tbaa !5
  %42 = add nsw i64 %41, %40
  store i64 %42, ptr @sum, align 8, !tbaa !5
  %43 = load i64, ptr %4, align 8, !tbaa !5
  %44 = getelementptr inbounds [200001 x i64], ptr @a, i64 0, i64 %43
  %45 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %44, ptr noundef nonnull align 8 dereferenceable(8) @mx)
  %46 = load i64, ptr %45, align 8, !tbaa !5
  store i64 %46, ptr @mx, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %32
  %48 = load i64, ptr %4, align 8, !tbaa !5
  %49 = add nsw i64 %48, 1
  store i64 %49, ptr %4, align 8, !tbaa !5
  br label %27, !llvm.loop !11

50:                                               ; preds = %31
  %51 = load i64, ptr @mx, align 8, !tbaa !5
  %52 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %51)
  br label %6, !llvm.loop !12

53:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 8, 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 uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) #3

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

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

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 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 = { 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 #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 = !{!"long long", !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 i64, align 8
@a = external dso_local global [200001 x i64], align 16
@sum = external dso_local local_unnamed_addr global i64, align 8
@mx = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i64, ptr %1, align 8, !tbaa !5
  %4 = add nsw i64 %3, -1
  store i64 %4, ptr %1, align 8, !tbaa !5
  %.not19 = icmp eq i64 %3, 0
  br i1 %.not19, label %._crit_edge22, label %.lr.ph21

.lr.ph21:                                         ; preds = %0, %._crit_edge18
  store i64 0, ptr @sum, align 8, !tbaa !5
  store i64 -4557430888798830399, ptr @mx, align 8, !tbaa !5
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %6 = load i64, ptr @n, align 8, !tbaa !5
  %.not1012 = icmp slt i64 %6, 1
  br i1 %.not1012, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph21
  %.lcssa = phi i64 [ %6, %.lr.ph21 ], [ %12, %.lr.ph ]
  %7 = getelementptr inbounds i64, ptr getelementptr inbounds (i8, ptr @a, i64 8), i64 %.lcssa
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef nonnull getelementptr inbounds (i8, ptr @a, i64 8), ptr noundef nonnull %7)
  %8 = load i64, ptr @n, align 8, !tbaa !5
  %.not1114 = icmp slt i64 %8, 1
  br i1 %.not1114, label %._crit_edge.._crit_edge18_crit_edge, label %.lr.ph17

._crit_edge.._crit_edge18_crit_edge:              ; preds = %._crit_edge
  %.pre = load i64, ptr @mx, align 8, !tbaa !5
  br label %._crit_edge18

.lr.ph:                                           ; preds = %.lr.ph21, %.lr.ph
  %.0813 = phi i64 [ %11, %.lr.ph ], [ 1, %.lr.ph21 ]
  %9 = getelementptr inbounds [200001 x i64], ptr @a, i64 0, i64 %.0813
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %9)
  %11 = add nuw nsw i64 %.0813, 1
  %12 = load i64, ptr @n, align 8, !tbaa !5
  %.not10.not = icmp slt i64 %.0813, %12
  br i1 %.not10.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge18:                                    ; preds = %.lr.ph17, %._crit_edge.._crit_edge18_crit_edge
  %13 = phi i64 [ %.pre, %._crit_edge.._crit_edge18_crit_edge ], [ %22, %.lr.ph17 ]
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %13)
  %15 = load i64, ptr %1, align 8, !tbaa !5
  %16 = add nsw i64 %15, -1
  store i64 %16, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %15, 0
  br i1 %.not, label %._crit_edge22, label %.lr.ph21, !llvm.loop !11

.lr.ph17:                                         ; preds = %._crit_edge, %.lr.ph17
  %.015 = phi i64 [ %23, %.lr.ph17 ], [ 1, %._crit_edge ]
  %17 = load i64, ptr @sum, align 8, !tbaa !5
  %18 = getelementptr inbounds [200001 x i64], ptr @a, i64 0, i64 %.015
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = sub nsw i64 %19, %17
  store i64 %20, ptr %18, align 8, !tbaa !5
  store i64 %19, ptr @sum, align 8, !tbaa !5
  %21 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %18, ptr noundef nonnull align 8 dereferenceable(8) @mx)
  %22 = load i64, ptr %21, align 8, !tbaa !5
  store i64 %22, ptr @mx, align 8, !tbaa !5
  %23 = add nuw nsw i64 %.015, 1
  %24 = load i64, ptr @n, align 8, !tbaa !5
  %.not11.not = icmp slt i64 %.015, %24
  br i1 %.not11.not, label %.lr.ph17, label %._crit_edge18, !llvm.loop !12

._crit_edge22:                                    ; preds = %._crit_edge18, %0
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  ret i32 0
}

; 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 uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

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 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 = { 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 #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 = !{!"long long", !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: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass