; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p4451.ll (Z6insertiiii)

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

@idx = external dso_local global i32, align 4
@max_R = external dso_local global [15000250 x i32], align 16
@prefix_xor = external dso_local global [600010 x i32], align 16
@tr = external dso_local global [15000250 x [2 x i32]], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6insertiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  store i32 %3, ptr %8, align 4, !tbaa !5
  %10 = load i32, ptr %6, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 0
  br i1 %11, label %12, label %17

12:                                               ; preds = %4
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = load i32, ptr %8, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [15000250 x i32], ptr @max_R, i64 0, i64 %15
  store i32 %13, ptr %16, align 4, !tbaa !5
  br label %88

17:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [600010 x i32], ptr @prefix_xor, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !5
  %23 = ashr i32 %21, %22
  %24 = and i32 %23, 1
  store i32 %24, ptr %9, align 4, !tbaa !5
  %25 = load i32, ptr %7, align 4, !tbaa !5
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %43

27:                                               ; preds = %17
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [15000250 x [2 x i32]], ptr @tr, i64 0, i64 %29
  %31 = load i32, ptr %9, align 4, !tbaa !5
  %32 = xor i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [2 x i32], ptr %30, i64 0, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = load i32, ptr %8, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [15000250 x [2 x i32]], ptr @tr, i64 0, i64 %37
  %39 = load i32, ptr %9, align 4, !tbaa !5
  %40 = xor i32 %39, 1
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [2 x i32], ptr %38, i64 0, i64 %41
  store i32 %35, ptr %42, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %27, %17
  %44 = load i32, ptr @idx, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr @idx, align 4, !tbaa !5
  %46 = load i32, ptr %8, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [15000250 x [2 x i32]], ptr @tr, i64 0, i64 %47
  %49 = load i32, ptr %9, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [2 x i32], ptr %48, i64 0, i64 %50
  store i32 %45, ptr %51, align 4, !tbaa !5
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = sub nsw i32 %53, 1
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [15000250 x [2 x i32]], ptr @tr, i64 0, i64 %56
  %58 = load i32, ptr %9, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2 x i32], ptr %57, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [15000250 x [2 x i32]], ptr @tr, i64 0, i64 %63
  %65 = load i32, ptr %9, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [2 x i32], ptr %64, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  call void @_Z6insertiiii(i32 noundef %52, i32 noundef %54, i32 noundef %61, i32 noundef %68)
  %69 = load i32, ptr %8, align 4, !tbaa !5
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [15000250 x [2 x i32]], ptr @tr, i64 0, i64 %70
  %72 = getelementptr inbounds [2 x i32], ptr %71, i64 0, i64 0
  %73 = load i32, ptr %72, align 8, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [15000250 x i32], ptr @max_R, i64 0, i64 %74
  %76 = load i32, ptr %8, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [15000250 x [2 x i32]], ptr @tr, i64 0, i64 %77
  %79 = getelementptr inbounds [2 x i32], ptr %78, i64 0, i64 1
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [15000250 x i32], ptr @max_R, i64 0, i64 %81
  %83 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %75, ptr noundef nonnull align 4 dereferenceable(4) %82)
  %84 = load i32, ptr %83, align 4, !tbaa !5
  %85 = load i32, ptr %8, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [15000250 x i32], ptr @max_R, i64 0, i64 %86
  store i32 %84, ptr %87, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %88

88:                                               ; preds = %43, %12
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

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

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 = { inlinehint 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 = { 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"}


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

@idx = external dso_local local_unnamed_addr global i32, align 4
@max_R = external dso_local global [15000250 x i32], align 16
@prefix_xor = external dso_local local_unnamed_addr global [600010 x i32], align 16
@tr = external dso_local local_unnamed_addr global [15000250 x [2 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z6insertiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp slt i32 %1, 0
  br i1 %5, label %6, label %8

6:                                                ; preds = %4
  %7 = sext i32 %3 to i64
  br label %common.ret

8:                                                ; preds = %4
  %9 = sext i32 %0 to i64
  %10 = getelementptr inbounds [600010 x i32], ptr @prefix_xor, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = lshr i32 %11, %1
  %13 = and i32 %12, 1
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %._crit_edge, label %14

._crit_edge:                                      ; preds = %8
  %.pre = sext i32 %3 to i64
  br label %23

14:                                               ; preds = %8
  %15 = sext i32 %2 to i64
  %16 = xor i32 %13, 1
  %17 = zext nneg i32 %16 to i64
  %18 = getelementptr inbounds [15000250 x [2 x i32]], ptr @tr, i64 0, i64 %15, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = sext i32 %3 to i64
  %21 = getelementptr inbounds [15000250 x [2 x i32]], ptr @tr, i64 0, i64 %20, i64 %17
  store i32 %19, ptr %21, align 4, !tbaa !5
  br label %23

common.ret:                                       ; preds = %6, %23
  %.sink25 = phi i64 [ %7, %6 ], [ %.pre-phi, %23 ]
  %.sink = phi i32 [ %0, %6 ], [ %40, %23 ]
  %22 = getelementptr inbounds [15000250 x i32], ptr @max_R, i64 0, i64 %.sink25
  store i32 %.sink, ptr %22, align 4, !tbaa !5
  ret void

23:                                               ; preds = %._crit_edge, %14
  %.pre-phi23 = phi i64 [ 0, %._crit_edge ], [ %15, %14 ]
  %.pre-phi = phi i64 [ %.pre, %._crit_edge ], [ %20, %14 ]
  %24 = load i32, ptr @idx, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @idx, align 4, !tbaa !5
  %26 = getelementptr inbounds [15000250 x [2 x i32]], ptr @tr, i64 0, i64 %.pre-phi
  %27 = zext nneg i32 %13 to i64
  %28 = getelementptr inbounds [15000250 x [2 x i32]], ptr @tr, i64 0, i64 %.pre-phi, i64 %27
  store i32 %25, ptr %28, align 4, !tbaa !5
  %29 = add nsw i32 %1, -1
  %30 = getelementptr inbounds [15000250 x [2 x i32]], ptr @tr, i64 0, i64 %.pre-phi23, i64 %27
  %31 = load i32, ptr %30, align 4, !tbaa !5
  tail call void @_Z6insertiiii(i32 noundef %0, i32 noundef %29, i32 noundef %31, i32 noundef %25)
  %32 = load i32, ptr %26, align 8, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [15000250 x i32], ptr @max_R, i64 0, i64 %33
  %35 = getelementptr inbounds i8, ptr %26, i64 4
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [15000250 x i32], ptr @max_R, i64 0, i64 %37
  %39 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %34, ptr noundef nonnull align 4 dereferenceable(4) %38)
  %40 = load i32, ptr %39, align 4, !tbaa !5
  br label %common.ret
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

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 = { inlinehint 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"}


; Effective O3 passes: ADCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass