; LLVM IR from abeaumont/competitive-programming :: codechef/oct19a/jiit.ll (Z1biixi)

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

@invpow2 = external dso_local global [2001 x i64], align 16
@powq = external dso_local global [4002 x i64], align 16
@aa = external dso_local global [2 x [2001 x [2001 x i32]]], align 16

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z1biixi(i32 noundef %0, i32 noundef %1, i64 noundef %2, i32 noundef %3) #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  store i64 0, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %11 = load i32, ptr %6, align 4, !tbaa !5
  %12 = sub nsw i32 0, %11
  store i32 %12, ptr %10, align 4, !tbaa !5
  br label %13

13:                                               ; preds = %43, %4
  %14 = load i32, ptr %10, align 4, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = icmp sle i32 %14, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %13
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %46

18:                                               ; preds = %13
  %19 = load i32, ptr %10, align 4, !tbaa !5
  %20 = add nsw i32 %19, 2000
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [4002 x i64], ptr @powq, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !9
  %24 = load i32, ptr %8, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [2 x [2001 x [2001 x i32]]], ptr @aa, i64 0, i64 %25
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [2001 x [2001 x i32]], ptr %26, i64 0, i64 %28
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = load i32, ptr %10, align 4, !tbaa !5
  %32 = sub nsw i32 %30, %31
  %33 = sdiv i32 %32, 2
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [2001 x i32], ptr %29, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = mul nsw i64 %23, %37
  %39 = load i64, ptr %9, align 8, !tbaa !9
  %40 = add nsw i64 %39, %38
  store i64 %40, ptr %9, align 8, !tbaa !9
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = srem i64 %41, 998244353
  store i64 %42, ptr %9, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %18
  %44 = load i32, ptr %10, align 4, !tbaa !5
  %45 = add nsw i32 %44, 2
  store i32 %45, ptr %10, align 4, !tbaa !5
  br label %13, !llvm.loop !11

46:                                               ; preds = %17
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [2001 x i64], ptr @invpow2, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !9
  %51 = load i64, ptr %9, align 8, !tbaa !9
  %52 = mul nsw i64 %51, %50
  store i64 %52, ptr %9, align 8, !tbaa !9
  %53 = load i64, ptr %9, align 8, !tbaa !9
  %54 = srem i64 %53, 998244353
  store i64 %54, ptr %9, align 8, !tbaa !9
  %55 = load i64, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  ret i64 %55
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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"}


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

@invpow2 = external dso_local local_unnamed_addr global [2001 x i64], align 16
@powq = external dso_local local_unnamed_addr global [4002 x i64], align 16
@aa = external dso_local local_unnamed_addr global [2 x [2001 x [2001 x i32]]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef range(i64 -998244352, 998244353) i64 @_Z1biixi(i32 noundef %0, i32 noundef %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %.not17 = icmp slt i32 %1, 0
  br i1 %.not17, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %4
  %.pre = sext i32 %1 to i64
  br label %._crit_edge

.lr.ph:                                           ; preds = %4
  %5 = sub nsw i32 0, %1
  %6 = sext i32 %3 to i64
  %7 = sext i32 %0 to i64
  %8 = sext i32 %5 to i64
  %9 = zext nneg i32 %1 to i64
  br label %14

._crit_edge:                                      ; preds = %14, %.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %9, %14 ]
  %.015.lcssa = phi i64 [ 0, %.._crit_edge_crit_edge ], [ %27, %14 ]
  %10 = getelementptr inbounds [2001 x i64], ptr @invpow2, i64 0, i64 %.pre-phi
  %11 = load i64, ptr %10, align 8, !tbaa !5
  %12 = mul nsw i64 %11, %.015.lcssa
  %13 = srem i64 %12, 998244353
  ret i64 %13

14:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ %8, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %.01518 = phi i64 [ 0, %.lr.ph ], [ %27, %14 ]
  %15 = add nsw i64 %indvars.iv, 2000
  %16 = getelementptr inbounds [4002 x i64], ptr @powq, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = trunc i64 %indvars.iv to i32
  %19 = sub i32 %1, %18
  %20 = sdiv i32 %19, 2
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [2 x [2001 x [2001 x i32]]], ptr @aa, i64 0, i64 %6, i64 %7, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = mul nsw i64 %17, %24
  %26 = add nsw i64 %25, %.01518
  %27 = srem i64 %26, 998244353
  %indvars.iv.next = add nsw i64 %indvars.iv, 2
  %.not = icmp sgt i64 %indvars.iv.next, %9
  br i1 %.not, label %._crit_edge, label %14, !llvm.loop !11
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass