; LLVM IR from lzyrapx/Competitive-Programming :: LibreOJ/6094（DP）（好题）.ll (Z2goii)

; 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 i32, align 4
@ways = external dso_local global [501 x [501 x [501 x i32]]], align 16
@sum2 = external dso_local global [501 x i32], align 16
@sum3 = external dso_local global [501 x i32], align 16
@mem = external dso_local global [500 x [501 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7add_modRix(ptr noundef nonnull align 4 dereferenceable(4), i64 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z2goii(i32 noundef %0, i32 noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [500 x [501 x i32]], ptr @mem, i64 0, i64 %11
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [501 x i32], ptr %12, i64 0, i64 %14
  store ptr %15, ptr %5, align 8, !tbaa !9
  %16 = load ptr, ptr %5, align 8, !tbaa !9
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %19, label %88

19:                                               ; preds = %2
  %20 = load ptr, ptr %5, align 8, !tbaa !9
  store i32 0, ptr %20, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [501 x i32], ptr @sum2, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [501 x i32], ptr @sum2, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = sub nsw i32 %24, %28
  store i32 %29, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [501 x i32], ptr @sum3, i64 0, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !5
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [501 x i32], ptr @sum3, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = sub nsw i32 %33, %37
  store i32 %38, ptr %7, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = load i32, ptr @n, align 4, !tbaa !5
  %41 = icmp eq i32 %39, %40
  br i1 %41, label %42, label %53

42:                                               ; preds = %19
  %43 = load ptr, ptr %5, align 8, !tbaa !9
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [501 x [501 x [501 x i32]]], ptr @ways, i64 0, i64 %45
  %47 = load i32, ptr %7, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [501 x [501 x i32]], ptr %46, i64 0, i64 %48
  %50 = getelementptr inbounds [501 x i32], ptr %49, i64 0, i64 0
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  call void @_Z7add_modRix(ptr noundef nonnull align 4 dereferenceable(4) %43, i64 noundef %52)
  br label %87

53:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %54 = load i32, ptr %4, align 4, !tbaa !5
  %55 = add nsw i32 %54, 1
  store i32 %55, ptr %8, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %83, %53
  %57 = load i32, ptr %8, align 4, !tbaa !5
  %58 = load i32, ptr @n, align 4, !tbaa !5
  %59 = icmp sle i32 %57, %58
  br i1 %59, label %61, label %60

60:                                               ; preds = %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %86

61:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = load i32, ptr %4, align 4, !tbaa !5
  %64 = sub nsw i32 %62, %63
  store i32 %64, ptr %9, align 4, !tbaa !5
  %65 = load ptr, ptr %5, align 8, !tbaa !9
  %66 = load i32, ptr %6, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [501 x [501 x [501 x i32]]], ptr @ways, i64 0, i64 %67
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [501 x [501 x i32]], ptr %68, i64 0, i64 %70
  %72 = load i32, ptr %9, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [501 x i32], ptr %71, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = mul nsw i64 1, %76
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = load i32, ptr %8, align 4, !tbaa !5
  %80 = call noundef i32 @_Z2goii(i32 noundef %78, i32 noundef %79)
  %81 = sext i32 %80 to i64
  %82 = mul nsw i64 %77, %81
  call void @_Z7add_modRix(ptr noundef nonnull align 4 dereferenceable(4) %65, i64 noundef %82)
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %83

83:                                               ; preds = %61
  %84 = load i32, ptr %8, align 4, !tbaa !5
  %85 = add nsw i32 %84, 1
  store i32 %85, ptr %8, align 4, !tbaa !5
  br label %56, !llvm.loop !11

86:                                               ; preds = %60
  br label %87

87:                                               ; preds = %86, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %88

88:                                               ; preds = %87, %2
  %89 = load ptr, ptr %5, align 8, !tbaa !9
  %90 = load i32, ptr %89, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i32 %90
}

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

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

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

@n = external dso_local local_unnamed_addr global i32, align 4
@ways = external dso_local local_unnamed_addr global [501 x [501 x [501 x i32]]], align 16
@sum2 = external dso_local local_unnamed_addr global [501 x i32], align 16
@sum3 = external dso_local local_unnamed_addr global [501 x i32], align 16
@mem = external dso_local global [500 x [501 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z7add_modRix(ptr noundef nonnull align 4 dereferenceable(4), i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z2goii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = sext i32 %0 to i64
  %4 = sext i32 %1 to i64
  %5 = getelementptr inbounds [500 x [501 x i32]], ptr @mem, i64 0, i64 %3, i64 %4
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %7 = icmp eq i32 %6, -1
  br i1 %7, label %8, label %.loopexit

8:                                                ; preds = %2
  store i32 0, ptr %5, align 4, !tbaa !5
  %9 = getelementptr inbounds [501 x i32], ptr @sum2, i64 0, i64 %4
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = getelementptr inbounds [501 x i32], ptr @sum2, i64 0, i64 %3
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = sub nsw i32 %10, %12
  %14 = getelementptr inbounds [501 x i32], ptr @sum3, i64 0, i64 %4
  %15 = load i32, ptr %14, align 4, !tbaa !5
  %16 = getelementptr inbounds [501 x i32], ptr @sum3, i64 0, i64 %3
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = sub nsw i32 %15, %17
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = icmp eq i32 %19, %1
  br i1 %20, label %23, label %.preheader

.preheader:                                       ; preds = %8
  %.not.not24 = icmp sgt i32 %19, %1
  br i1 %.not.not24, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %21 = sext i32 %13 to i64
  %22 = sext i32 %18 to i64
  br label %29

23:                                               ; preds = %8
  %24 = sext i32 %13 to i64
  %25 = sext i32 %18 to i64
  %26 = getelementptr inbounds [501 x [501 x [501 x i32]]], ptr @ways, i64 0, i64 %24, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  tail call void @_Z7add_modRix(ptr noundef nonnull align 4 dereferenceable(4) %5, i64 noundef %28)
  br label %.loopexit

29:                                               ; preds = %.lr.ph, %29
  %indvars.iv = phi i64 [ %4, %.lr.ph ], [ %indvars.iv.next, %29 ]
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %30 = sub nsw i64 %indvars.iv.next, %4
  %31 = getelementptr inbounds [501 x [501 x [501 x i32]]], ptr @ways, i64 0, i64 %21, i64 %22, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = trunc nsw i64 %indvars.iv.next to i32
  %35 = tail call noundef i32 @_Z2goii(i32 noundef %1, i32 noundef %34)
  %36 = sext i32 %35 to i64
  %37 = mul nsw i64 %36, %33
  tail call void @_Z7add_modRix(ptr noundef nonnull align 4 dereferenceable(4) %5, i64 noundef %37)
  %38 = load i32, ptr @n, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %.not.not = icmp slt i64 %indvars.iv.next, %39
  br i1 %.not.not, label %29, label %.loopexit, !llvm.loop !9

.loopexit:                                        ; preds = %29, %.preheader, %23, %2
  %40 = load i32, ptr %5, align 4, !tbaa !5
  ret i32 %40
}

attributes #0 = { 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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