; 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

; 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 @_Z4diffiiii(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %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
  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
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = load i32, ptr %8, align 4, !tbaa !5
  %14 = icmp eq i32 %12, %13
  br i1 %14, label %15, label %33

15:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.node, ptr %18, i32 0, i32 2
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %22
  %24 = getelementptr inbounds %struct.node, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !9
  %26 = sub nsw i32 %20, %25
  store i32 %26, ptr %10, align 4, !tbaa !5
  %27 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %30
  %32 = getelementptr inbounds %struct.node, ptr %31, i32 0, i32 2
  store i32 %28, ptr %32, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %112

33:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = add nsw i32 %34, %35
  %37 = sdiv i32 %36, 2
  store i32 %37, ptr %11, align 4, !tbaa !5
  %38 = load i32, ptr %6, 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 0
  %42 = load i32, ptr %41, align 4, !tbaa !11
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %62

44:                                               ; preds = %33
  %45 = load i32, ptr %5, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %46
  %48 = getelementptr inbounds %struct.node, ptr %47, i32 0, i32 0
  %49 = load i32, ptr %48, align 4, !tbaa !11
  %50 = load i32, ptr %6, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %51
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %53, align 4, !tbaa !11
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = load i32, ptr %11, align 4, !tbaa !5
  %57 = call noundef i32 @_Z4diffiiii(i32 noundef %49, i32 noundef %54, i32 noundef %55, i32 noundef %56)
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %59
  %61 = getelementptr inbounds %struct.node, ptr %60, i32 0, i32 0
  store i32 %57, ptr %61, align 4, !tbaa !11
  br label %62

62:                                               ; preds = %44, %33
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %64
  %66 = getelementptr inbounds %struct.node, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 4, !tbaa !12
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %88

69:                                               ; preds = %62
  %70 = load i32, ptr %5, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %71
  %73 = getelementptr inbounds %struct.node, ptr %72, i32 0, i32 1
  %74 = load i32, ptr %73, align 4, !tbaa !12
  %75 = load i32, ptr %6, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %76
  %78 = getelementptr inbounds %struct.node, ptr %77, i32 0, i32 1
  %79 = load i32, ptr %78, align 4, !tbaa !12
  %80 = load i32, ptr %11, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  %82 = load i32, ptr %8, align 4, !tbaa !5
  %83 = call noundef i32 @_Z4diffiiii(i32 noundef %74, i32 noundef %79, i32 noundef %81, i32 noundef %82)
  %84 = load i32, ptr %5, 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
  store i32 %83, ptr %87, align 4, !tbaa !12
  br label %88

88:                                               ; preds = %69, %62
  %89 = load i32, ptr %5, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %90
  %92 = getelementptr inbounds %struct.node, ptr %91, i32 0, i32 0
  %93 = load i32, ptr %92, align 4, !tbaa !11
  %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 2
  %97 = load i32, ptr %96, align 4, !tbaa !9
  %98 = load i32, ptr %5, 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 1
  %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 !9
  %107 = add nsw i32 %97, %106
  %108 = load i32, ptr %5, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %109
  %111 = getelementptr inbounds %struct.node, ptr %110, i32 0, i32 2
  store i32 %107, ptr %111, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %112

112:                                              ; preds = %88, %15
  %113 = load i32, ptr %5, align 4, !tbaa !5
  ret i32 %113
}

; 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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z4diffiiii(i32 noundef returned %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = icmp eq i32 %2, %3
  br i1 %7, label %8, label %18

8:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  %9 = sext i32 %0 to i64
  %10 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %9, i32 2
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = sext i32 %1 to i64
  %13 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %12, i32 2
  %14 = load i32, ptr %13, align 4, !tbaa !9
  %15 = sub nsw i32 %11, %14
  store i32 %15, ptr %6, align 4, !tbaa !5
  %16 = 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)
  %17 = load i32, ptr %16, align 4, !tbaa !5
  store i32 %17, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  br label %45

18:                                               ; preds = %4
  %19 = add nsw i32 %3, %2
  %20 = sdiv i32 %19, 2
  %21 = sext i32 %1 to i64
  %22 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %21
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %.not = icmp eq i32 %23, 0
  br i1 %.not, label %29, label %24

24:                                               ; preds = %18
  %25 = sext i32 %0 to i64
  %26 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = tail call noundef i32 @_Z4diffiiii(i32 noundef %27, i32 noundef %23, i32 noundef %2, i32 noundef %20)
  store i32 %27, ptr %26, align 4, !tbaa !11
  br label %29

29:                                               ; preds = %24, %18
  %30 = getelementptr inbounds i8, ptr %22, i64 4
  %31 = load i32, ptr %30, align 4, !tbaa !12
  %.not26 = icmp eq i32 %31, 0
  %.phi.trans.insert = sext i32 %0 to i64
  %.phi.trans.insert28 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %.phi.trans.insert, i32 1
  %.pre = load i32, ptr %.phi.trans.insert28, align 4, !tbaa !12
  br i1 %.not26, label %._crit_edge, label %32

32:                                               ; preds = %29
  %33 = add nsw i32 %20, 1
  %34 = tail call noundef i32 @_Z4diffiiii(i32 noundef %.pre, i32 noundef %31, i32 noundef %33, i32 noundef %3)
  store i32 %.pre, ptr %.phi.trans.insert28, align 4, !tbaa !12
  br label %._crit_edge

._crit_edge:                                      ; preds = %29, %32
  %35 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %.phi.trans.insert
  %36 = load i32, ptr %35, align 4, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %37, i32 2
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = sext i32 %.pre to i64
  %41 = getelementptr inbounds [5250000 x %struct.node], ptr @T, i64 0, i64 %40, i32 2
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = add nsw i32 %42, %39
  %44 = getelementptr inbounds i8, ptr %35, i64 8
  store i32 %43, ptr %44, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %._crit_edge, %8
  ret i32 %0
}

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

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


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