; LLVM IR from Aryansh-S/USACO :: algo_ds/DP/atcoder (n-slimes)

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

@n = external dso_local global i64, align 8
@a = external dso_local global [405 x i64], align 16
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external global ptr, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5solveii(i32 noundef, i32 noundef) #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 i64, align 8
  store i32 0, ptr %1, align 4
  %4 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.2)
  %5 = icmp ne ptr %4, null
  br i1 %5, label %6, label %11

6:                                                ; preds = %0
  %7 = load ptr, ptr @stdin, align 8, !tbaa !5
  %8 = call ptr @freopen(ptr noundef @.str, ptr noundef @.str.2, ptr noundef %7)
  %9 = load ptr, ptr @stdout, align 8, !tbaa !5
  %10 = call ptr @freopen(ptr noundef @.str.3, ptr noundef @.str.4, ptr noundef %9)
  br label %11

11:                                               ; preds = %6, %0
  %12 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !9
  %13 = getelementptr i8, ptr %12, i64 -24
  %14 = load i64, ptr %13, align 8
  %15 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %14
  %16 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %15, ptr noundef null)
  %17 = call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  call void @_Z2reIRxJEEvOT_DpOT0_(ptr noundef nonnull align 8 dereferenceable(8) @n)
  %18 = load i64, ptr @n, align 8, !tbaa !11
  %19 = getelementptr inbounds i64, ptr @a, i64 %18
  call void @_Z2inIPxEvT_S1_(ptr noundef @a, ptr noundef %19)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !13
  br label %20

20:                                               ; preds = %37, %11
  %21 = load i32, ptr %2, align 4, !tbaa !13
  %22 = sext i32 %21 to i64
  %23 = load i64, ptr @n, align 8, !tbaa !11
  %24 = icmp slt i64 %22, %23
  br i1 %24, label %26, label %25

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

26:                                               ; preds = %20
  %27 = load i32, ptr %2, align 4, !tbaa !13
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [405 x i64], ptr @a, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !11
  %31 = load i32, ptr %2, align 4, !tbaa !13
  %32 = add nsw i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [405 x i64], ptr @a, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = add nsw i64 %35, %30
  store i64 %36, ptr %34, align 8, !tbaa !11
  br label %37

37:                                               ; preds = %26
  %38 = load i32, ptr %2, align 4, !tbaa !13
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %2, align 4, !tbaa !13
  br label %20, !llvm.loop !15

40:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %41 = load i64, ptr @n, align 8, !tbaa !11
  %42 = sub nsw i64 %41, 1
  %43 = trunc i64 %42 to i32
  %44 = call noundef i64 @_Z5solveii(i32 noundef 0, i32 noundef %43)
  store i64 %44, ptr %3, align 8, !tbaa !11
  call void @_Z2prIxJEEvOT_DpOT0_(ptr noundef nonnull align 8 dereferenceable(8) %3)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  %45 = load i32, ptr %1, align 4
  ret i32 %45
}

declare noalias ptr @fopen(ptr noundef, ptr noundef) #3

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #3

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2reIRxJEEvOT_DpOT0_(ptr noundef nonnull align 8 dereferenceable(8)) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2inIPxEvT_S1_(ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2prIxJEEvOT_DpOT0_(ptr noundef nonnull align 8 dereferenceable(8)) #0

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 = { "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 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

@n = external dso_local global i64, align 8
@a = external dso_local global [405 x i64], align 16
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@stdin = external local_unnamed_addr global ptr, align 8
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1
@stdout = external local_unnamed_addr global ptr, align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5solveii(i32 noundef, i32 noundef) local_unnamed_addr #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: mustprogress 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() local_unnamed_addr #2 {
  %1 = alloca i64, align 8
  %2 = tail call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.2)
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %8, label %3

3:                                                ; preds = %0
  %4 = load ptr, ptr @stdin, align 8, !tbaa !5
  %5 = tail call ptr @freopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.2, ptr noundef %4)
  %6 = load ptr, ptr @stdout, align 8, !tbaa !5
  %7 = tail call ptr @freopen(ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, ptr noundef %6)
  br label %8

8:                                                ; preds = %3, %0
  %9 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !9
  %10 = getelementptr i8, ptr %9, i64 -24
  %11 = load i64, ptr %10, align 8
  %12 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %11
  %13 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %12, ptr noundef null)
  %14 = tail call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  tail call void @_Z2reIRxJEEvOT_DpOT0_(ptr noundef nonnull align 8 dereferenceable(8) @n)
  %15 = load i64, ptr @n, align 8, !tbaa !11
  %16 = getelementptr inbounds i64, ptr @a, i64 %15
  tail call void @_Z2inIPxEvT_S1_(ptr noundef nonnull @a, ptr noundef nonnull %16)
  %17 = load i64, ptr @n, align 8, !tbaa !11
  %18 = icmp sgt i64 %17, 0
  br i1 %18, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %8
  %.pre = load i64, ptr @a, align 16, !tbaa !11
  %xtraiter = and i64 %17, 3
  %19 = icmp ult i64 %17, 4
  br i1 %19, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

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

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

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %20 = phi i64 [ %23, %.lr.ph.epil ], [ %.unr, %._crit_edge.loopexit.unr-lcssa ]
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.lr.ph.epil ], [ %indvars.iv.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %21 = getelementptr inbounds [405 x i64], ptr @a, i64 0, i64 %indvars.iv.next.epil
  %22 = load i64, ptr %21, align 8, !tbaa !11
  %23 = add nsw i64 %22, %20
  store i64 %23, ptr %21, align 8, !tbaa !11
  %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_edge, label %.lr.ph.epil, !llvm.loop !13

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #6
  %24 = trunc i64 %17 to i32
  %25 = add i32 %24, -1
  %26 = tail call noundef i64 @_Z5solveii(i32 noundef 0, i32 noundef %25)
  store i64 %26, ptr %1, align 8, !tbaa !11
  call void @_Z2prIxJEEvOT_DpOT0_(ptr noundef nonnull align 8 dereferenceable(8) %1)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #6
  ret i32 0

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %27 = phi i64 [ %.pre, %.lr.ph.preheader.new ], [ %39, %.lr.ph ]
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader.new ], [ %indvars.iv.next.3, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %28 = getelementptr inbounds [405 x i64], ptr @a, i64 0, i64 %indvars.iv.next
  %29 = load i64, ptr %28, align 8, !tbaa !11
  %30 = add nsw i64 %29, %27
  store i64 %30, ptr %28, align 8, !tbaa !11
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %31 = getelementptr inbounds [405 x i64], ptr @a, i64 0, i64 %indvars.iv.next.1
  %32 = load i64, ptr %31, align 16, !tbaa !11
  %33 = add nsw i64 %32, %30
  store i64 %33, ptr %31, align 16, !tbaa !11
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %34 = getelementptr inbounds [405 x i64], ptr @a, i64 0, i64 %indvars.iv.next.2
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = add nsw i64 %35, %33
  store i64 %36, ptr %34, align 8, !tbaa !11
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %37 = getelementptr inbounds [405 x i64], ptr @a, i64 0, i64 %indvars.iv.next.3
  %38 = load i64, ptr %37, align 16, !tbaa !11
  %39 = add nsw i64 %38, %36
  store i64 %39, ptr %37, align 16, !tbaa !11
  %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_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !15
}

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #3

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #4

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2reIRxJEEvOT_DpOT0_(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2inIPxEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z2prIxJEEvOT_DpOT0_(ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0

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 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 = { 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 #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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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