; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p3919.ll (Z6modifyiiiii)

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

%struct.Node = type { i32, i32, i32 }

@tr = external dso_local global [24000240 x %struct.Node], align 16
@idx = external dso_local global i32, align 4

; 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 uwtable
define dso_local noundef i32 @_Z6modifyiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %15 = load i32, ptr @idx, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr @idx, align 4, !tbaa !5
  store i32 %16, ptr %12, align 4, !tbaa !5
  %17 = load i32, ptr %7, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [24000240 x %struct.Node], ptr @tr, i64 0, i64 %18
  %20 = load i32, ptr %12, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [24000240 x %struct.Node], ptr @tr, i64 0, i64 %21
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %22, ptr align 4 %19, i64 12, i1 false), !tbaa.struct !9
  %23 = load i32, ptr %8, align 4, !tbaa !5
  %24 = load i32, ptr %9, align 4, !tbaa !5
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %33

26:                                               ; preds = %5
  %27 = load i32, ptr %11, align 4, !tbaa !5
  %28 = load i32, ptr %12, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds [24000240 x %struct.Node], ptr @tr, i64 0, i64 %29
  %31 = getelementptr inbounds %struct.Node, ptr %30, i32 0, i32 2
  store i32 %27, ptr %31, align 4, !tbaa !10
  %32 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %32, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %74

33:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = load i32, ptr %9, align 4, !tbaa !5
  %36 = add nsw i32 %34, %35
  %37 = ashr i32 %36, 1
  store i32 %37, ptr %14, align 4, !tbaa !5
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = load i32, ptr %14, align 4, !tbaa !5
  %40 = icmp sle i32 %38, %39
  br i1 %40, label %41, label %56

41:                                               ; preds = %33
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [24000240 x %struct.Node], ptr @tr, i64 0, i64 %43
  %45 = getelementptr inbounds %struct.Node, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !12
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = load i32, ptr %14, align 4, !tbaa !5
  %49 = load i32, ptr %10, align 4, !tbaa !5
  %50 = load i32, ptr %11, align 4, !tbaa !5
  %51 = call noundef i32 @_Z6modifyiiiii(i32 noundef %46, i32 noundef %47, i32 noundef %48, i32 noundef %49, i32 noundef %50)
  %52 = load i32, ptr %12, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [24000240 x %struct.Node], ptr @tr, i64 0, i64 %53
  %55 = getelementptr inbounds %struct.Node, ptr %54, i32 0, i32 0
  store i32 %51, ptr %55, align 4, !tbaa !12
  br label %72

56:                                               ; preds = %33
  %57 = load i32, ptr %7, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [24000240 x %struct.Node], ptr @tr, i64 0, i64 %58
  %60 = getelementptr inbounds %struct.Node, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 4, !tbaa !13
  %62 = load i32, ptr %14, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  %64 = load i32, ptr %9, align 4, !tbaa !5
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = load i32, ptr %11, align 4, !tbaa !5
  %67 = call noundef i32 @_Z6modifyiiiii(i32 noundef %61, i32 noundef %63, i32 noundef %64, i32 noundef %65, i32 noundef %66)
  %68 = load i32, ptr %12, align 4, !tbaa !5
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [24000240 x %struct.Node], ptr @tr, i64 0, i64 %69
  %71 = getelementptr inbounds %struct.Node, ptr %70, i32 0, i32 1
  store i32 %67, ptr %71, align 4, !tbaa !13
  br label %72

72:                                               ; preds = %56, %41
  %73 = load i32, ptr %12, align 4, !tbaa !5
  store i32 %73, ptr %6, align 4
  store i32 1, ptr %13, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %74

74:                                               ; preds = %72, %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  %75 = load i32, ptr %6, align 4
  ret i32 %75
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5}
!10 = !{!11, !6, i64 8}
!11 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8}
!12 = !{!11, !6, i64 0}
!13 = !{!11, !6, i64 4}


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

%struct.Node = type { i32, i32, i32 }

@tr = external dso_local local_unnamed_addr global [24000240 x %struct.Node], align 16
@idx = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree nosync nounwind memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef range(i32 -2147483647, -2147483648) i32 @_Z6modifyiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = load i32, ptr @idx, align 4, !tbaa !5
  %7 = add nsw i32 %6, 1
  store i32 %7, ptr @idx, align 4, !tbaa !5
  %8 = sext i32 %0 to i64
  %9 = getelementptr inbounds [24000240 x %struct.Node], ptr @tr, i64 0, i64 %8
  %10 = sext i32 %7 to i64
  %11 = getelementptr inbounds [24000240 x %struct.Node], ptr @tr, i64 0, i64 %10
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %11, ptr noundef nonnull align 4 dereferenceable(12) %9, i64 12, i1 false), !tbaa.struct !9
  %12 = icmp eq i32 %1, %2
  br i1 %12, label %common.ret, label %14

common.ret:                                       ; preds = %5
  %13 = getelementptr inbounds i8, ptr %11, i64 8
  store i32 %4, ptr %13, align 4, !tbaa !10
  br label %common.ret29

14:                                               ; preds = %5
  %15 = add nsw i32 %2, %1
  %16 = ashr i32 %15, 1
  %.not = icmp slt i32 %16, %3
  br i1 %.not, label %20, label %17

common.ret29:                                     ; preds = %20, %17, %common.ret
  %common.ret29.op = phi i32 [ %7, %common.ret ], [ %7, %17 ], [ %7, %20 ]
  ret i32 %common.ret29.op

17:                                               ; preds = %14
  %18 = load i32, ptr %9, align 4, !tbaa !12
  %19 = tail call noundef i32 @_Z6modifyiiiii(i32 noundef %18, i32 noundef %1, i32 noundef %16, i32 noundef %3, i32 noundef %4)
  store i32 %19, ptr %11, align 4, !tbaa !12
  br label %common.ret29

20:                                               ; preds = %14
  %21 = getelementptr inbounds i8, ptr %9, i64 4
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = add nsw i32 %16, 1
  %24 = tail call noundef i32 @_Z6modifyiiiii(i32 noundef %22, i32 noundef %23, i32 noundef %2, i32 noundef %3, i32 noundef %4)
  %25 = getelementptr inbounds i8, ptr %11, i64 4
  store i32 %24, ptr %25, align 4, !tbaa !13
  br label %common.ret29
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

!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 = !{i64 0, i64 4, !5, i64 4, i64 4, !5, i64 8, i64 4, !5}
!10 = !{!11, !6, i64 8}
!11 = !{!"_ZTS4Node", !6, i64 0, !6, i64 4, !6, i64 8}
!12 = !{!11, !6, i64 0}
!13 = !{!11, !6, i64 4}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass