; LLVM IR from PaddlePaddle/Paddle :: paddle/fluid/distributed/ps/table/graph (graph_weighted_sampler)

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

%"class.paddle::distributed::WeightedSampler" = type { %"class.paddle::distributed::Sampler", ptr, ptr, float, i32, i32, ptr }
%"class.paddle::distributed::Sampler" = type { ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6paddle11distributed15WeightedSampler9build_oneEPNS0_21WeightedGraphEdgeBlobEii(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8
  %12 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 4
  store i32 0, ptr %12, align 4, !tbaa !11
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 6
  store ptr %13, ptr %14, align 8, !tbaa !15
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = add nsw i32 %15, 1
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = icmp eq i32 %16, %17
  br i1 %18, label %19, label %33

19:                                               ; preds = %4
  %20 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 2
  store ptr null, ptr %20, align 8, !tbaa !16
  %21 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 1
  store ptr null, ptr %21, align 8, !tbaa !17
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 5
  store i32 %22, ptr %23, align 8, !tbaa !18
  %24 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 4
  store i32 1, ptr %24, align 4, !tbaa !11
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 5
  %27 = load i32, ptr %26, align 8, !tbaa !18
  %28 = load ptr, ptr %25, align 8, !tbaa !19
  %29 = getelementptr inbounds ptr, ptr %28, i64 3
  %30 = load ptr, ptr %29, align 8
  %31 = call noundef float %30(ptr noundef nonnull align 8 dereferenceable(56) %25, i32 noundef %27)
  %32 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 3
  store float %31, ptr %32, align 8, !tbaa !21
  br label %94

33:                                               ; preds = %4
  %34 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 48) #3
  invoke void @_ZN6paddle11distributed15WeightedSamplerC1Ev(ptr noundef nonnull align 8 dereferenceable(48) %34)
          to label %35 unwind label %86

35:                                               ; preds = %33
  %36 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 1
  store ptr %34, ptr %36, align 8, !tbaa !17
  %37 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 48) #3
  invoke void @_ZN6paddle11distributed15WeightedSamplerC1Ev(ptr noundef nonnull align 8 dereferenceable(48) %37)
          to label %38 unwind label %90

38:                                               ; preds = %35
  %39 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 2
  store ptr %37, ptr %39, align 8, !tbaa !16
  %40 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !17
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = load i32, ptr %8, align 4, !tbaa !9
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = sub nsw i32 %45, %46
  %48 = sdiv i32 %47, 2
  %49 = add nsw i32 %44, %48
  %50 = load ptr, ptr %41, align 8, !tbaa !19
  %51 = getelementptr inbounds ptr, ptr %50, i64 4
  %52 = load ptr, ptr %51, align 8
  call void %52(ptr noundef nonnull align 8 dereferenceable(48) %41, ptr noundef %42, i32 noundef %43, i32 noundef %49)
  %53 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 2
  %54 = load ptr, ptr %53, align 8, !tbaa !16
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = load i32, ptr %7, align 4, !tbaa !9
  %59 = sub nsw i32 %57, %58
  %60 = sdiv i32 %59, 2
  %61 = add nsw i32 %56, %60
  %62 = load i32, ptr %8, align 4, !tbaa !9
  %63 = load ptr, ptr %54, align 8, !tbaa !19
  %64 = getelementptr inbounds ptr, ptr %63, i64 4
  %65 = load ptr, ptr %64, align 8
  call void %65(ptr noundef nonnull align 8 dereferenceable(48) %54, ptr noundef %55, i32 noundef %61, i32 noundef %62)
  %66 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 1
  %67 = load ptr, ptr %66, align 8, !tbaa !17
  %68 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %67, i32 0, i32 3
  %69 = load float, ptr %68, align 8, !tbaa !21
  %70 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !16
  %72 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %71, i32 0, i32 3
  %73 = load float, ptr %72, align 8, !tbaa !21
  %74 = fadd float %69, %73
  %75 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 3
  store float %74, ptr %75, align 8, !tbaa !21
  %76 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 1
  %77 = load ptr, ptr %76, align 8, !tbaa !17
  %78 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %77, i32 0, i32 4
  %79 = load i32, ptr %78, align 4, !tbaa !11
  %80 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 2
  %81 = load ptr, ptr %80, align 8, !tbaa !16
  %82 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %81, i32 0, i32 4
  %83 = load i32, ptr %82, align 4, !tbaa !11
  %84 = add nsw i32 %79, %83
  %85 = getelementptr inbounds %"class.paddle::distributed::WeightedSampler", ptr %11, i32 0, i32 4
  store i32 %84, ptr %85, align 4, !tbaa !11
  br label %94

86:                                               ; preds = %33
  %87 = landingpad { ptr, i32 }
          cleanup
  %88 = extractvalue { ptr, i32 } %87, 0
  store ptr %88, ptr %9, align 8
  %89 = extractvalue { ptr, i32 } %87, 1
  store i32 %89, ptr %10, align 4
  call void @_ZdlPvm(ptr noundef %34, i64 noundef 48) #4
  br label %95

90:                                               ; preds = %35
  %91 = landingpad { ptr, i32 }
          cleanup
  %92 = extractvalue { ptr, i32 } %91, 0
  store ptr %92, ptr %9, align 8
  %93 = extractvalue { ptr, i32 } %91, 1
  store i32 %93, ptr %10, align 4
  call void @_ZdlPvm(ptr noundef %37, i64 noundef 48) #4
  br label %95

94:                                               ; preds = %38, %19
  ret void

95:                                               ; preds = %90, %86
  %96 = load ptr, ptr %9, align 8
  %97 = load i32, ptr %10, align 4
  %98 = insertvalue { ptr, i32 } poison, ptr %96, 0
  %99 = insertvalue { ptr, i32 } %98, i32 %97, 1
  resume { ptr, i32 } %99
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

declare void @_ZN6paddle11distributed15WeightedSamplerC1Ev(ptr)

attributes #0 = { nobuiltin nounwind "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 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 = { nobuiltin allocsize(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 = { builtin allocsize(0) }
attributes #4 = { builtin 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 28}
!12 = !{!"_ZTSN6paddle11distributed15WeightedSamplerE", !13, i64 0, !6, i64 8, !6, i64 16, !14, i64 24, !10, i64 28, !10, i64 32, !6, i64 40}
!13 = !{!"_ZTSN6paddle11distributed7SamplerE"}
!14 = !{!"float", !7, i64 0}
!15 = !{!12, !6, i64 40}
!16 = !{!12, !6, i64 16}
!17 = !{!12, !6, i64 8}
!18 = !{!12, !10, i64 32}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !8, i64 0}
!21 = !{!12, !14, i64 24}


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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6paddle11distributed15WeightedSampler9build_oneEPNS0_21WeightedGraphEdgeBlobEii(ptr nocapture noundef nonnull align 8 dereferenceable(48) %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %5 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 0, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr %1, ptr %6, align 8, !tbaa !13
  %7 = add nsw i32 %2, 1
  %8 = icmp eq i32 %7, %3
  br i1 %8, label %9, label %17

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %10, i8 0, i64 16, i1 false)
  store i32 %2, ptr %11, align 8, !tbaa !14
  store i32 1, ptr %5, align 4, !tbaa !5
  %12 = load ptr, ptr %1, align 8, !tbaa !15
  %13 = getelementptr inbounds i8, ptr %12, i64 24
  %14 = load ptr, ptr %13, align 8
  %15 = tail call noundef float %14(ptr noundef nonnull align 8 dereferenceable(56) %1, i32 noundef %2)
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  store float %15, ptr %16, align 8, !tbaa !17
  br label %52

17:                                               ; preds = %4
  %18 = tail call noalias noundef nonnull dereferenceable(48) ptr @_Znwm(i64 noundef 48) #4
  invoke void @_ZN6paddle11distributed15WeightedSamplerC1Ev(ptr noundef nonnull align 8 dereferenceable(48) %18)
          to label %19 unwind label %48

19:                                               ; preds = %17
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %18, ptr %20, align 8, !tbaa !18
  %21 = tail call noalias noundef nonnull dereferenceable(48) ptr @_Znwm(i64 noundef 48) #4
  invoke void @_ZN6paddle11distributed15WeightedSamplerC1Ev(ptr noundef nonnull align 8 dereferenceable(48) %21)
          to label %22 unwind label %50

22:                                               ; preds = %19
  %23 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %21, ptr %23, align 8, !tbaa !19
  %24 = load ptr, ptr %20, align 8, !tbaa !18
  %25 = sub nsw i32 %3, %2
  %26 = sdiv i32 %25, 2
  %27 = add nsw i32 %26, %2
  %28 = load ptr, ptr %24, align 8, !tbaa !15
  %29 = getelementptr inbounds i8, ptr %28, i64 32
  %30 = load ptr, ptr %29, align 8
  tail call void %30(ptr noundef nonnull align 8 dereferenceable(48) %24, ptr noundef %1, i32 noundef %2, i32 noundef %27)
  %31 = load ptr, ptr %23, align 8, !tbaa !19
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = getelementptr inbounds i8, ptr %32, i64 32
  %34 = load ptr, ptr %33, align 8
  tail call void %34(ptr noundef nonnull align 8 dereferenceable(48) %31, ptr noundef %1, i32 noundef %27, i32 noundef %3)
  %35 = load ptr, ptr %20, align 8, !tbaa !18
  %36 = getelementptr inbounds i8, ptr %35, i64 24
  %37 = load float, ptr %36, align 8, !tbaa !17
  %38 = load ptr, ptr %23, align 8, !tbaa !19
  %39 = getelementptr inbounds i8, ptr %38, i64 24
  %40 = load float, ptr %39, align 8, !tbaa !17
  %41 = fadd float %37, %40
  %42 = getelementptr inbounds i8, ptr %0, i64 24
  store float %41, ptr %42, align 8, !tbaa !17
  %43 = getelementptr inbounds i8, ptr %35, i64 28
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = getelementptr inbounds i8, ptr %38, i64 28
  %46 = load i32, ptr %45, align 4, !tbaa !5
  %47 = add nsw i32 %46, %44
  store i32 %47, ptr %5, align 4, !tbaa !5
  br label %52

48:                                               ; preds = %17
  %49 = landingpad { ptr, i32 }
          cleanup
  br label %53

50:                                               ; preds = %19
  %51 = landingpad { ptr, i32 }
          cleanup
  br label %53

52:                                               ; preds = %22, %9
  ret void

53:                                               ; preds = %50, %48
  %.sink = phi ptr [ %21, %50 ], [ %18, %48 ]
  %.pn = phi { ptr, i32 } [ %51, %50 ], [ %49, %48 ]
  tail call void @_ZdlPvm(ptr noundef nonnull %.sink, i64 noundef 48) #5
  resume { ptr, i32 } %.pn
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #2

declare void @_ZN6paddle11distributed15WeightedSamplerC1Ev(ptr) local_unnamed_addr

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

attributes #0 = { nobuiltin nounwind "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 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 = { nobuiltin allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { builtin allocsize(0) }
attributes #5 = { builtin 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, !12, i64 28}
!6 = !{!"_ZTSN6paddle11distributed15WeightedSamplerE", !7, i64 0, !8, i64 8, !8, i64 16, !11, i64 24, !12, i64 28, !12, i64 32, !8, i64 40}
!7 = !{!"_ZTSN6paddle11distributed7SamplerE"}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"float", !9, i64 0}
!12 = !{!"int", !9, i64 0}
!13 = !{!6, !8, i64 40}
!14 = !{!6, !12, i64 32}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !10, i64 0}
!17 = !{!6, !11, i64 24}
!18 = !{!6, !8, i64 8}
!19 = !{!6, !8, i64 16}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass