; LLVM IR from upupming/algorithm :: kick-start/2020 (2020G-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 }

@t = external dso_local global i64, align 8
@w = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@x = external dso_local global [100010 x i64], align 16
@sum = external dso_local global [100010 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@.str = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5solvev() #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @t)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %60, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = load i64, ptr @t, align 8, !tbaa !9
  %11 = icmp sle i64 %9, %10
  br i1 %11, label %13, label %12

12:                                               ; preds = %7
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %63

13:                                               ; preds = %7
  %14 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @w)
  %15 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %14, ptr noundef nonnull align 8 dereferenceable(8) @n)
  store i64 0, ptr @sum, align 16, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %27, %13
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = load i64, ptr @w, align 8, !tbaa !9
  %20 = icmp slt i64 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %30

22:                                               ; preds = %16
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [100010 x i64], ptr @x, i64 0, i64 %24
  %26 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %25)
  br label %27

27:                                               ; preds = %22
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %4, align 4, !tbaa !5
  br label %16, !llvm.loop !11

30:                                               ; preds = %21
  %31 = load i64, ptr @w, align 8, !tbaa !9
  %32 = getelementptr inbounds i64, ptr @x, i64 %31
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef @x, ptr noundef %32)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %53, %30
  %34 = load i32, ptr %5, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = load i64, ptr @w, align 8, !tbaa !9
  %37 = icmp slt i64 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %33
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  br label %56

39:                                               ; preds = %33
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [100010 x i64], ptr @sum, i64 0, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !9
  %44 = load i32, ptr %5, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100010 x i64], ptr @x, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !9
  %48 = add nsw i64 %43, %47
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [100010 x i64], ptr @sum, i64 0, i64 %51
  store i64 %48, ptr %52, align 8, !tbaa !9
  br label %53

53:                                               ; preds = %39
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %5, align 4, !tbaa !5
  br label %33, !llvm.loop !13

56:                                               ; preds = %38
  %57 = load i32, ptr %2, align 4, !tbaa !5
  %58 = call noundef i64 @_Z5solvev()
  %59 = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %57, i64 noundef %58)
  br label %60

60:                                               ; preds = %56
  %61 = load i32, ptr %2, align 4, !tbaa !5
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !14

63:                                               ; preds = %12
  ret i32 0
}

; 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)) #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) #3

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = { "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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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

@t = external dso_local global i64, align 8
@w = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@x = external dso_local global [100010 x i64], align 16
@sum = external dso_local local_unnamed_addr global [100010 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@.str = external hidden unnamed_addr constant [16 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5solvev() local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = 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) @t)
  %2 = load i64, ptr @t, align 8, !tbaa !5
  %.not21 = icmp slt i64 %2, 1
  br i1 %.not21, label %._crit_edge25, label %.lr.ph24

._crit_edge25:                                    ; preds = %._crit_edge20, %0
  ret i32 0

.lr.ph24:                                         ; preds = %0, %._crit_edge20
  %indvars.iv31 = phi i64 [ %indvars.iv.next32, %._crit_edge20 ], [ 1, %0 ]
  %3 = 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) @w)
  %4 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %3, ptr noundef nonnull align 8 dereferenceable(8) @n)
  store i64 0, ptr @sum, align 16, !tbaa !5
  %5 = load i64, ptr @w, align 8, !tbaa !5
  %6 = icmp sgt i64 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph24
  %.lcssa = phi i64 [ %5, %.lr.ph24 ], [ %13, %.lr.ph ]
  %7 = getelementptr inbounds i64, ptr @x, i64 %.lcssa
  tail call void @_ZSt4sortIPxEvT_S1_(ptr noundef nonnull @x, ptr noundef nonnull %7)
  %8 = load i64, ptr @w, align 8, !tbaa !5
  %9 = icmp sgt i64 %8, 0
  br i1 %9, label %.lr.ph19.preheader, label %._crit_edge20

.lr.ph19.preheader:                               ; preds = %._crit_edge
  %.pre = load i64, ptr @sum, align 16, !tbaa !5
  %xtraiter = and i64 %8, 3
  %10 = icmp ult i64 %8, 4
  br i1 %10, label %._crit_edge20.loopexit.unr-lcssa, label %.lr.ph19.preheader.new

.lr.ph19.preheader.new:                           ; preds = %.lr.ph19.preheader
  %unroll_iter = and i64 %8, 9223372036854775804
  br label %.lr.ph19

.lr.ph:                                           ; preds = %.lr.ph24, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph24 ]
  %11 = getelementptr inbounds [100010 x i64], ptr @x, i64 0, i64 %indvars.iv
  %12 = 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) %11)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = load i64, ptr @w, align 8, !tbaa !5
  %14 = icmp sgt i64 %13, %indvars.iv.next
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge20.loopexit.unr-lcssa:                 ; preds = %.lr.ph19, %.lr.ph19.preheader
  %.unr = phi i64 [ %.pre, %.lr.ph19.preheader ], [ %39, %.lr.ph19 ]
  %indvars.iv28.unr = phi i64 [ 0, %.lr.ph19.preheader ], [ %indvars.iv.next29.3, %.lr.ph19 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge20, label %.lr.ph19.epil

.lr.ph19.epil:                                    ; preds = %._crit_edge20.loopexit.unr-lcssa, %.lr.ph19.epil
  %15 = phi i64 [ %18, %.lr.ph19.epil ], [ %.unr, %._crit_edge20.loopexit.unr-lcssa ]
  %indvars.iv28.epil = phi i64 [ %indvars.iv.next29.epil, %.lr.ph19.epil ], [ %indvars.iv28.unr, %._crit_edge20.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph19.epil ], [ 0, %._crit_edge20.loopexit.unr-lcssa ]
  %16 = getelementptr inbounds [100010 x i64], ptr @x, i64 0, i64 %indvars.iv28.epil
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = add nsw i64 %17, %15
  %indvars.iv.next29.epil = add nuw nsw i64 %indvars.iv28.epil, 1
  %19 = getelementptr inbounds [100010 x i64], ptr @sum, i64 0, i64 %indvars.iv.next29.epil
  store i64 %18, ptr %19, align 8, !tbaa !5
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge20, label %.lr.ph19.epil, !llvm.loop !11

._crit_edge20:                                    ; preds = %._crit_edge20.loopexit.unr-lcssa, %.lr.ph19.epil, %._crit_edge
  %20 = tail call noundef i64 @_Z5solvev()
  %21 = trunc nuw nsw i64 %indvars.iv31 to i32
  %22 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %21, i64 noundef %20)
  %indvars.iv.next32 = add nuw nsw i64 %indvars.iv31, 1
  %23 = load i64, ptr @t, align 8, !tbaa !5
  %.not.not = icmp sgt i64 %23, %indvars.iv31
  br i1 %.not.not, label %.lr.ph24, label %._crit_edge25, !llvm.loop !13

.lr.ph19:                                         ; preds = %.lr.ph19, %.lr.ph19.preheader.new
  %24 = phi i64 [ %.pre, %.lr.ph19.preheader.new ], [ %39, %.lr.ph19 ]
  %indvars.iv28 = phi i64 [ 0, %.lr.ph19.preheader.new ], [ %indvars.iv.next29.3, %.lr.ph19 ]
  %niter = phi i64 [ 0, %.lr.ph19.preheader.new ], [ %niter.next.3, %.lr.ph19 ]
  %25 = getelementptr inbounds [100010 x i64], ptr @x, i64 0, i64 %indvars.iv28
  %26 = load i64, ptr %25, align 16, !tbaa !5
  %27 = add nsw i64 %26, %24
  %indvars.iv.next29 = or disjoint i64 %indvars.iv28, 1
  %28 = getelementptr inbounds [100010 x i64], ptr @sum, i64 0, i64 %indvars.iv.next29
  store i64 %27, ptr %28, align 8, !tbaa !5
  %29 = getelementptr inbounds [100010 x i64], ptr @x, i64 0, i64 %indvars.iv.next29
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = add nsw i64 %30, %27
  %indvars.iv.next29.1 = or disjoint i64 %indvars.iv28, 2
  %32 = getelementptr inbounds [100010 x i64], ptr @sum, i64 0, i64 %indvars.iv.next29.1
  store i64 %31, ptr %32, align 16, !tbaa !5
  %33 = getelementptr inbounds [100010 x i64], ptr @x, i64 0, i64 %indvars.iv.next29.1
  %34 = load i64, ptr %33, align 16, !tbaa !5
  %35 = add nsw i64 %34, %31
  %indvars.iv.next29.2 = or disjoint i64 %indvars.iv28, 3
  %36 = getelementptr inbounds [100010 x i64], ptr @sum, i64 0, i64 %indvars.iv.next29.2
  store i64 %35, ptr %36, align 8, !tbaa !5
  %37 = getelementptr inbounds [100010 x i64], ptr @x, i64 0, i64 %indvars.iv.next29.2
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = add nsw i64 %38, %35
  %indvars.iv.next29.3 = add nuw nsw i64 %indvars.iv28, 4
  %40 = getelementptr inbounds [100010 x i64], ptr @sum, i64 0, i64 %indvars.iv.next29.3
  store i64 %39, ptr %40, align 16, !tbaa !5
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge20.loopexit.unr-lcssa, label %.lr.ph19, !llvm.loop !14
}

; 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 #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPxEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #2

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

attributes #0 = { 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 #1 = { 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 #2 = { 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 #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 = !{!"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, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass