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

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

@T = external dso_local global [5250000 x %struct.node], align 16
@sz = external dso_local global i32, align 4

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

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

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

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

24:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 0, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.node, ptr %27, i32 0, i32 2
  %29 = load i32, ptr %28, align 4, !tbaa !10
  %30 = load i32, ptr %6, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %31
  %33 = getelementptr inbounds %struct.node, ptr %32, i32 0, i32 2
  %34 = load i32, ptr %33, align 4, !tbaa !10
  %35 = sub nsw i32 %29, %34
  store i32 %35, ptr %11, align 4, !tbaa !5
  %36 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %10, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = load i32, ptr %9, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %39
  %41 = getelementptr inbounds %struct.node, ptr %40, i32 0, i32 2
  store i32 %37, ptr %41, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %121

42:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = add nsw i32 %43, %44
  %46 = sdiv i32 %45, 2
  store i32 %46, ptr %12, align 4, !tbaa !5
  %47 = load i32, ptr %6, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %48
  %50 = getelementptr inbounds %struct.node, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 4, !tbaa !12
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %71

53:                                               ; preds = %42
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %55
  %57 = getelementptr inbounds %struct.node, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 4, !tbaa !12
  %59 = load i32, ptr %6, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %60
  %62 = getelementptr inbounds %struct.node, ptr %61, i32 0, i32 0
  %63 = load i32, ptr %62, align 4, !tbaa !12
  %64 = load i32, ptr %7, align 4, !tbaa !5
  %65 = load i32, ptr %12, align 4, !tbaa !5
  %66 = call noundef i32 @_Z4diffiiii(i32 noundef %58, i32 noundef %63, i32 noundef %64, i32 noundef %65)
  %67 = load i32, ptr %9, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %68
  %70 = getelementptr inbounds %struct.node, ptr %69, i32 0, i32 0
  store i32 %66, ptr %70, align 4, !tbaa !12
  br label %71

71:                                               ; preds = %53, %42
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %73
  %75 = getelementptr inbounds %struct.node, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 4, !tbaa !13
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %78, label %97

78:                                               ; preds = %71
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %80
  %82 = getelementptr inbounds %struct.node, ptr %81, i32 0, i32 1
  %83 = load i32, ptr %82, align 4, !tbaa !13
  %84 = load i32, ptr %6, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %85
  %87 = getelementptr inbounds %struct.node, ptr %86, i32 0, i32 1
  %88 = load i32, ptr %87, align 4, !tbaa !13
  %89 = load i32, ptr %12, align 4, !tbaa !5
  %90 = add nsw i32 %89, 1
  %91 = load i32, ptr %8, align 4, !tbaa !5
  %92 = call noundef i32 @_Z4diffiiii(i32 noundef %83, i32 noundef %88, i32 noundef %90, i32 noundef %91)
  %93 = load i32, ptr %9, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %94
  %96 = getelementptr inbounds %struct.node, ptr %95, i32 0, i32 1
  store i32 %92, ptr %96, align 4, !tbaa !13
  br label %97

97:                                               ; preds = %78, %71
  %98 = load i32, ptr %9, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %99
  %101 = getelementptr inbounds %struct.node, ptr %100, i32 0, i32 0
  %102 = load i32, ptr %101, align 4, !tbaa !12
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %103
  %105 = getelementptr inbounds %struct.node, ptr %104, i32 0, i32 2
  %106 = load i32, ptr %105, align 4, !tbaa !10
  %107 = load i32, ptr %9, align 4, !tbaa !5
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %108
  %110 = getelementptr inbounds %struct.node, ptr %109, i32 0, i32 1
  %111 = load i32, ptr %110, align 4, !tbaa !13
  %112 = sext i32 %111 to i64
  %113 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %112
  %114 = getelementptr inbounds %struct.node, ptr %113, i32 0, i32 2
  %115 = load i32, ptr %114, align 4, !tbaa !10
  %116 = add nsw i32 %106, %115
  %117 = load i32, ptr %9, align 4, !tbaa !5
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %118
  %120 = getelementptr inbounds %struct.node, ptr %119, i32 0, i32 2
  store i32 %116, ptr %120, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %121

121:                                              ; preds = %97, %24
  %122 = load i32, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  ret i32 %122
}

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

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

@T = external dso_local local_unnamed_addr global [5250000 x %struct.node], align 16
@sz = 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 -2147483647, -2147483648) i32 @_Z4diffiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = load i32, ptr @sz, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @sz, align 4, !tbaa !5
  %9 = sext i32 %0 to i64
  %10 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %9
  %11 = sext i32 %8 to i64
  %12 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %11
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %12, ptr noundef nonnull align 4 dereferenceable(12) %10, i64 12, i1 false), !tbaa.struct !9
  %13 = icmp eq i32 %2, %3
  br i1 %13, label %14, label %24

14:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #4
  %15 = getelementptr inbounds i8, ptr %10, i64 8
  %16 = load i32, ptr %15, align 4, !tbaa !10
  %17 = sext i32 %1 to i64
  %18 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %17, i32 2
  %19 = load i32, ptr %18, align 4, !tbaa !10
  %20 = sub nsw i32 %16, %19
  store i32 %20, ptr %6, align 4, !tbaa !5
  %21 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %12, i64 8
  store i32 %22, ptr %23, align 4, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  br label %53

24:                                               ; preds = %4
  %25 = add nsw i32 %3, %2
  %26 = sdiv i32 %25, 2
  %27 = sext i32 %1 to i64
  %28 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !12
  %.not = icmp eq i32 %29, 0
  br i1 %.not, label %33, label %30

30:                                               ; preds = %24
  %31 = load i32, ptr %10, align 4, !tbaa !12
  %32 = tail call noundef i32 @_Z4diffiiii(i32 noundef %31, i32 noundef %29, i32 noundef %2, i32 noundef %26)
  store i32 %32, ptr %12, align 4, !tbaa !12
  br label %33

33:                                               ; preds = %30, %24
  %34 = getelementptr inbounds i8, ptr %28, i64 4
  %35 = load i32, ptr %34, align 4, !tbaa !13
  %.not28 = icmp eq i32 %35, 0
  br i1 %.not28, label %._crit_edge, label %36

._crit_edge:                                      ; preds = %33
  %.phi.trans.insert = getelementptr inbounds i8, ptr %12, i64 4
  %.pre = load i32, ptr %.phi.trans.insert, align 4, !tbaa !13
  br label %42

36:                                               ; preds = %33
  %37 = getelementptr inbounds i8, ptr %10, i64 4
  %38 = load i32, ptr %37, align 4, !tbaa !13
  %39 = add nsw i32 %26, 1
  %40 = tail call noundef i32 @_Z4diffiiii(i32 noundef %38, i32 noundef %35, i32 noundef %39, i32 noundef %3)
  %41 = getelementptr inbounds i8, ptr %12, i64 4
  store i32 %40, ptr %41, align 4, !tbaa !13
  br label %42

42:                                               ; preds = %._crit_edge, %36
  %43 = phi i32 [ %.pre, %._crit_edge ], [ %40, %36 ]
  %44 = load i32, ptr %12, align 4, !tbaa !12
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %45, i32 2
  %47 = load i32, ptr %46, align 4, !tbaa !10
  %48 = sext i32 %43 to i64
  %49 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %48, i32 2
  %50 = load i32, ptr %49, align 4, !tbaa !10
  %51 = add nsw i32 %50, %47
  %52 = getelementptr inbounds i8, ptr %12, i64 8
  store i32 %51, ptr %52, align 4, !tbaa !10
  br label %53

53:                                               ; preds = %42, %14
  ret i32 %8
}

; 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 #3

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


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