; LLVM IR from sunkafei/xcpc-algorithm-templates :: 算法/数据结构/可持久化并查集.ll (Z6updateiiiii)

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

@t = external dso_local global [8400000 x %struct.node], align 16
@cur = 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: 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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z6updateiiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %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
  store i32 %0, ptr %6, align 4, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %13 = load i32, ptr @cur, align 4, !tbaa !5
  %14 = add nsw i32 %13, 1
  store i32 %14, ptr @cur, align 4, !tbaa !5
  store i32 %14, ptr %11, align 4, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [8400000 x %struct.node], ptr @t, i64 0, i64 %16
  %18 = load i32, ptr %11, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [8400000 x %struct.node], ptr @t, i64 0, i64 %19
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %20, ptr align 16 %17, i64 16, i1 false), !tbaa.struct !9
  %21 = load i32, ptr %9, align 4, !tbaa !5
  %22 = load i32, ptr %10, align 4, !tbaa !5
  %23 = icmp eq i32 %21, %22
  br i1 %23, label %24, label %32

24:                                               ; preds = %5
  %25 = load i32, ptr %8, align 4, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [8400000 x %struct.node], ptr @t, i64 0, i64 %27
  %29 = getelementptr inbounds %struct.node, ptr %28, i32 0, i32 3
  %30 = load i32, ptr %29, align 4, !tbaa !10
  %31 = add nsw i32 %30, %25
  store i32 %31, ptr %29, align 4, !tbaa !10
  br label %72

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

40:                                               ; preds = %32
  %41 = load i32, ptr %11, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [8400000 x %struct.node], ptr @t, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.node, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %44, align 16, !tbaa !12
  %46 = load i32, ptr %7, align 4, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !5
  %48 = load i32, ptr %9, align 4, !tbaa !5
  %49 = load i32, ptr %12, align 4, !tbaa !5
  %50 = call noundef i32 @_Z6updateiiiii(i32 noundef %45, i32 noundef %46, i32 noundef %47, i32 noundef %48, i32 noundef %49)
  %51 = load i32, ptr %11, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [8400000 x %struct.node], ptr @t, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.node, ptr %53, i32 0, i32 0
  store i32 %50, ptr %54, align 16, !tbaa !12
  br label %71

55:                                               ; preds = %32
  %56 = load i32, ptr %11, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [8400000 x %struct.node], ptr @t, i64 0, i64 %57
  %59 = getelementptr inbounds %struct.node, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !13
  %61 = load i32, ptr %7, align 4, !tbaa !5
  %62 = load i32, ptr %8, align 4, !tbaa !5
  %63 = load i32, ptr %12, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  %65 = load i32, ptr %10, align 4, !tbaa !5
  %66 = call noundef i32 @_Z6updateiiiii(i32 noundef %60, i32 noundef %61, i32 noundef %62, i32 noundef %64, i32 noundef %65)
  %67 = load i32, ptr %11, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [8400000 x %struct.node], ptr @t, i64 0, i64 %68
  %70 = getelementptr inbounds %struct.node, ptr %69, i32 0, i32 1
  store i32 %66, ptr %70, align 4, !tbaa !13
  br label %71

71:                                               ; preds = %55, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  br label %72

72:                                               ; preds = %71, %24
  %73 = load i32, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret i32 %73
}

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

@t = external dso_local local_unnamed_addr global [8400000 x %struct.node], align 16
@cur = external dso_local local_unnamed_addr global i32, align 4

; 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) #0

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

common.ret:                                       ; preds = %5
  %13 = getelementptr inbounds i8, ptr %11, i64 12
  %14 = load i32, ptr %13, align 4, !tbaa !10
  %15 = add nsw i32 %14, %2
  store i32 %15, ptr %13, align 4, !tbaa !10
  br label %common.ret27

16:                                               ; preds = %5
  %17 = add nsw i32 %4, %3
  %18 = ashr i32 %17, 1
  %.not = icmp slt i32 %18, %1
  br i1 %.not, label %22, label %19

common.ret27:                                     ; preds = %22, %19, %common.ret
  %common.ret27.op = phi i32 [ %7, %common.ret ], [ %7, %19 ], [ %7, %22 ]
  ret i32 %common.ret27.op

19:                                               ; preds = %16
  %20 = load i32, ptr %11, align 16, !tbaa !12
  %21 = tail call noundef i32 @_Z6updateiiiii(i32 noundef %20, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %18)
  store i32 %21, ptr %11, align 16, !tbaa !12
  br label %common.ret27

22:                                               ; preds = %16
  %23 = getelementptr inbounds i8, ptr %11, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !13
  %25 = add nsw i32 %18, 1
  %26 = tail call noundef i32 @_Z6updateiiiii(i32 noundef %24, i32 noundef %1, i32 noundef %2, i32 noundef %25, i32 noundef %4)
  store i32 %26, ptr %23, align 4, !tbaa !13
  br label %common.ret27
}

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

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


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