; LLVM IR from ahr9n/psolving-paradigms :: 2.greedy (Kattis shopaholic - Shopaholic)

; 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 }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@n = external dso_local global i64, align 8
@a = external dso_local global [200005 x i64], align 16
@ans = external dso_local global i64, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; 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 zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %5 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %6 = getelementptr i8, ptr %5, i64 -24
  %7 = load i64, ptr %6, align 8
  %8 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %7
  %9 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %8, ptr noundef null)
  %10 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 0, ptr %2, align 4, !tbaa !8
  br label %11

11:                                               ; preds = %18, %0
  %12 = load i32, ptr %2, align 4, !tbaa !8
  %13 = sext i32 %12 to i64
  %14 = load i64, ptr @n, align 8, !tbaa !11
  %15 = icmp slt i64 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %24

17:                                               ; preds = %11
  br label %18

18:                                               ; preds = %17
  %19 = load i32, ptr %2, align 4, !tbaa !8
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %2, align 4, !tbaa !8
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %21
  %23 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %22)
  br label %11, !llvm.loop !13

24:                                               ; preds = %16
  %25 = load i64, ptr @n, align 8, !tbaa !11
  %26 = getelementptr inbounds i64, ptr @a, i64 %25
  call void @_ZSt4sortIPxEvT_S1_(ptr noundef @a, ptr noundef %26)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  %27 = load i64, ptr @n, align 8, !tbaa !11
  %28 = sub nsw i64 %27, 3
  %29 = trunc i64 %28 to i32
  store i32 %29, ptr %3, align 4, !tbaa !8
  br label %30

30:                                               ; preds = %41, %24
  %31 = load i32, ptr %3, align 4, !tbaa !8
  %32 = icmp sge i32 %31, 0
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %44

34:                                               ; preds = %30
  %35 = load i32, ptr %3, align 4, !tbaa !8
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !11
  %39 = load i64, ptr @ans, align 8, !tbaa !11
  %40 = add nsw i64 %39, %38
  store i64 %40, ptr @ans, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %34
  %42 = load i32, ptr %3, align 4, !tbaa !8
  %43 = sub nsw i32 %42, 3
  store i32 %43, ptr %3, align 4, !tbaa !8
  br label %30, !llvm.loop !15

44:                                               ; preds = %33
  %45 = load i64, ptr @ans, align 8, !tbaa !11
  %46 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %45)
  ret i32 0
}

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) #1

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) #2 align 2

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

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

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

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #3 align 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 = { "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 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 #3 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


; 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 }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@n = external dso_local global i64, align 8
@a = external dso_local global [200005 x i64], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %2 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %3 = getelementptr i8, ptr %2, i64 -24
  %4 = load i64, ptr %3, align 8
  %5 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %4
  %6 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %5, ptr noundef null)
  %7 = 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) @n)
  %8 = load i64, ptr @n, align 8, !tbaa !8
  %9 = icmp sgt i64 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i64 [ %8, %0 ], [ %24, %.lr.ph ]
  %10 = getelementptr inbounds i64, ptr @a, i64 %.lcssa
  tail call void @_ZSt4sortIPxEvT_S1_(ptr noundef nonnull @a, ptr noundef nonnull %10)
  %11 = load i64, ptr @n, align 8, !tbaa !8
  %12 = trunc i64 %11 to i32
  %ans.promoted = load i64, ptr @ans, align 8, !tbaa !8
  %.09 = add i32 %12, -3
  %13 = icmp sgt i32 %.09, -1
  br i1 %13, label %.lr.ph12.preheader, label %26

.lr.ph12.preheader:                               ; preds = %._crit_edge
  %14 = zext nneg i32 %.09 to i64
  %15 = udiv i64 %14, 3
  %16 = add nuw nsw i64 %15, 1
  %xtraiter = and i64 %16, 7
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.lr.ph12.prol.loopexit, label %.lr.ph12.prol

.lr.ph12.prol:                                    ; preds = %.lr.ph12.preheader, %.lr.ph12.prol
  %indvars.iv18.prol = phi i64 [ %indvars.iv.next19.prol, %.lr.ph12.prol ], [ %14, %.lr.ph12.preheader ]
  %17 = phi i64 [ %20, %.lr.ph12.prol ], [ %ans.promoted, %.lr.ph12.preheader ]
  %prol.iter = phi i64 [ %prol.iter.next, %.lr.ph12.prol ], [ 0, %.lr.ph12.preheader ]
  %18 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %indvars.iv18.prol
  %19 = load i64, ptr %18, align 8, !tbaa !8
  %20 = add nsw i64 %17, %19
  %indvars.iv.next19.prol = add nsw i64 %indvars.iv18.prol, -3
  %prol.iter.next = add i64 %prol.iter, 1
  %prol.iter.cmp.not = icmp eq i64 %prol.iter.next, %xtraiter
  br i1 %prol.iter.cmp.not, label %.lr.ph12.prol.loopexit, label %.lr.ph12.prol, !llvm.loop !11

.lr.ph12.prol.loopexit:                           ; preds = %.lr.ph12.prol, %.lr.ph12.preheader
  %indvars.iv18.unr = phi i64 [ %14, %.lr.ph12.preheader ], [ %indvars.iv.next19.prol, %.lr.ph12.prol ]
  %.unr = phi i64 [ %ans.promoted, %.lr.ph12.preheader ], [ %20, %.lr.ph12.prol ]
  %.lcssa25.unr = phi i64 [ poison, %.lr.ph12.preheader ], [ %20, %.lr.ph12.prol ]
  %21 = icmp ult i32 %.09, 21
  br i1 %21, label %._crit_edge13, label %.lr.ph12

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %22 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %indvars.iv
  %23 = 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) %22)
  %24 = load i64, ptr @n, align 8, !tbaa !8
  %25 = icmp sgt i64 %24, %indvars.iv.next
  br i1 %25, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge13:                                    ; preds = %.lr.ph12, %.lr.ph12.prol.loopexit
  %.lcssa25 = phi i64 [ %.lcssa25.unr, %.lr.ph12.prol.loopexit ], [ %53, %.lr.ph12 ]
  store i64 %.lcssa25, ptr @ans, align 8, !tbaa !8
  br label %26

26:                                               ; preds = %._crit_edge13, %._crit_edge
  %27 = phi i64 [ %.lcssa25, %._crit_edge13 ], [ %ans.promoted, %._crit_edge ]
  %28 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %27)
  ret i32 0

.lr.ph12:                                         ; preds = %.lr.ph12.prol.loopexit, %.lr.ph12
  %indvars.iv18 = phi i64 [ %indvars.iv.next19.7, %.lr.ph12 ], [ %indvars.iv18.unr, %.lr.ph12.prol.loopexit ]
  %29 = phi i64 [ %53, %.lr.ph12 ], [ %.unr, %.lr.ph12.prol.loopexit ]
  %30 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %indvars.iv18
  %31 = load i64, ptr %30, align 8, !tbaa !8
  %32 = add nsw i64 %29, %31
  %indvars.iv.next19 = add nsw i64 %indvars.iv18, -3
  %33 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %indvars.iv.next19
  %34 = load i64, ptr %33, align 8, !tbaa !8
  %35 = add nsw i64 %32, %34
  %indvars.iv.next19.1 = add nsw i64 %indvars.iv18, -6
  %36 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %indvars.iv.next19.1
  %37 = load i64, ptr %36, align 8, !tbaa !8
  %38 = add nsw i64 %35, %37
  %indvars.iv.next19.2 = add nsw i64 %indvars.iv18, -9
  %39 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %indvars.iv.next19.2
  %40 = load i64, ptr %39, align 8, !tbaa !8
  %41 = add nsw i64 %38, %40
  %indvars.iv.next19.3 = add nsw i64 %indvars.iv18, -12
  %42 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %indvars.iv.next19.3
  %43 = load i64, ptr %42, align 8, !tbaa !8
  %44 = add nsw i64 %41, %43
  %indvars.iv.next19.4 = add nsw i64 %indvars.iv18, -15
  %45 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %indvars.iv.next19.4
  %46 = load i64, ptr %45, align 8, !tbaa !8
  %47 = add nsw i64 %44, %46
  %indvars.iv.next19.5 = add nsw i64 %indvars.iv18, -18
  %48 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %indvars.iv.next19.5
  %49 = load i64, ptr %48, align 8, !tbaa !8
  %50 = add nsw i64 %47, %49
  %indvars.iv.next19.6 = add nsw i64 %indvars.iv18, -21
  %51 = getelementptr inbounds [200005 x i64], ptr @a, i64 0, i64 %indvars.iv.next19.6
  %52 = load i64, ptr %51, align 8, !tbaa !8
  %53 = add nsw i64 %50, %52
  %indvars.iv.next19.7 = add nsw i64 %indvars.iv18, -24
  %54 = icmp ugt i64 %indvars.iv.next19.6, 2
  br i1 %54, label %.lr.ph12, label %._crit_edge13, !llvm.loop !15
}

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) local_unnamed_addr #2 align 2

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

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #3 align 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 = { "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 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 #3 = { 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 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.unroll.disable"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}


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