; LLVM IR from fcimeson/cbTSP :: cbLKH/SRC (AllocateStructures)

; 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.Segment = type { i8, ptr, ptr, ptr, ptr, i32, i32, ptr }
%struct.SSegment = type { i8, ptr, ptr, ptr, ptr, i32, i32 }

@Dimension = external dso_local global i32, align 4
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@GroupSize = external dso_local global i32, align 4
@Groups = external dso_local global i32, align 4
@.str.16 = external hidden unnamed_addr constant [40 x i8], align 1
@__PRETTY_FUNCTION__.AllocateSegments = external hidden unnamed_addr constant [24 x i8], align 1
@FirstSegment = external dso_local global ptr, align 8
@SGroupSize = external dso_local global i32, align 4
@SGroups = external dso_local global i32, align 4
@FirstSSegment = external dso_local global ptr, align 8

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @AllocateSegments() #3 {
  %1 = alloca ptr, align 8
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #6
  store ptr null, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @FreeSegments()
  %6 = load i32, ptr @Dimension, align 4, !tbaa !9
  %7 = sitofp i32 %6 to double
  %8 = call double @sqrt(double noundef %7) #6
  %9 = fptosi double %8 to i32
  store i32 %9, ptr @GroupSize, align 4, !tbaa !9
  store i32 0, ptr @Groups, align 4, !tbaa !9
  %10 = load i32, ptr @Dimension, align 4, !tbaa !9
  store i32 %10, ptr %5, align 4, !tbaa !9
  store ptr null, ptr %2, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %36, %0
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %14, label %41

14:                                               ; preds = %11
  %15 = call noalias ptr @malloc(i64 noundef 56) #7
  store ptr %15, ptr %1, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  br label %19

18:                                               ; preds = %14
  call void @__assert_fail(ptr noundef @.str.16, ptr noundef @.str.1, i32 noundef 86, ptr noundef @__PRETTY_FUNCTION__.AllocateSegments) #8
  unreachable

19:                                               ; preds = %17
  %20 = load i32, ptr @Groups, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @Groups, align 4, !tbaa !9
  %22 = load ptr, ptr %1, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Segment, ptr %22, i32 0, i32 5
  store i32 %21, ptr %23, align 8, !tbaa !11
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %28, label %26

26:                                               ; preds = %19
  %27 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %27, ptr @FirstSegment, align 8, !tbaa !5
  br label %35

28:                                               ; preds = %19
  %29 = load ptr, ptr %1, align 8, !tbaa !5
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.Segment, ptr %30, i32 0, i32 4
  store ptr %29, ptr %31, align 8, !tbaa !13
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = load ptr, ptr %1, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.Segment, ptr %33, i32 0, i32 3
  store ptr %32, ptr %34, align 8, !tbaa !14
  br label %35

35:                                               ; preds = %28, %26
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr @GroupSize, align 4, !tbaa !9
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = sub nsw i32 %38, %37
  store i32 %39, ptr %5, align 4, !tbaa !9
  %40 = load ptr, ptr %1, align 8, !tbaa !5
  store ptr %40, ptr %2, align 8, !tbaa !5
  br label %11, !llvm.loop !15

41:                                               ; preds = %11
  %42 = load ptr, ptr @FirstSegment, align 8, !tbaa !5
  %43 = load ptr, ptr %1, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.Segment, ptr %43, i32 0, i32 4
  store ptr %42, ptr %44, align 8, !tbaa !13
  %45 = load ptr, ptr %1, align 8, !tbaa !5
  %46 = load ptr, ptr @FirstSegment, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.Segment, ptr %46, i32 0, i32 3
  store ptr %45, ptr %47, align 8, !tbaa !14
  %48 = load i32, ptr @Dimension, align 4, !tbaa !9
  store i32 %48, ptr @SGroupSize, align 4, !tbaa !9
  store i32 0, ptr @SGroups, align 4, !tbaa !9
  %49 = load i32, ptr @Groups, align 4, !tbaa !9
  store i32 %49, ptr %5, align 4, !tbaa !9
  store ptr null, ptr %4, align 8, !tbaa !5
  br label %50

50:                                               ; preds = %71, %41
  %51 = load i32, ptr %5, align 4, !tbaa !9
  %52 = icmp sgt i32 %51, 0
  br i1 %52, label %53, label %76

53:                                               ; preds = %50
  %54 = call noalias ptr @malloc(i64 noundef 48) #7
  store ptr %54, ptr %3, align 8, !tbaa !5
  %55 = load i32, ptr @SGroups, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr @SGroups, align 4, !tbaa !9
  %57 = load ptr, ptr %3, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.SSegment, ptr %57, i32 0, i32 5
  store i32 %56, ptr %58, align 8, !tbaa !17
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = icmp ne ptr %59, null
  br i1 %60, label %63, label %61

61:                                               ; preds = %53
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %62, ptr @FirstSSegment, align 8, !tbaa !5
  br label %70

63:                                               ; preds = %53
  %64 = load ptr, ptr %3, align 8, !tbaa !5
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.SSegment, ptr %65, i32 0, i32 4
  store ptr %64, ptr %66, align 8, !tbaa !19
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.SSegment, ptr %68, i32 0, i32 3
  store ptr %67, ptr %69, align 8, !tbaa !20
  br label %70

70:                                               ; preds = %63, %61
  br label %71

71:                                               ; preds = %70
  %72 = load i32, ptr @SGroupSize, align 4, !tbaa !9
  %73 = load i32, ptr %5, align 4, !tbaa !9
  %74 = sub nsw i32 %73, %72
  store i32 %74, ptr %5, align 4, !tbaa !9
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %75, ptr %4, align 8, !tbaa !5
  br label %50, !llvm.loop !21

76:                                               ; preds = %50
  %77 = load ptr, ptr @FirstSSegment, align 8, !tbaa !5
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.SSegment, ptr %78, i32 0, i32 4
  store ptr %77, ptr %79, align 8, !tbaa !19
  %80 = load ptr, ptr %3, align 8, !tbaa !5
  %81 = load ptr, ptr @FirstSSegment, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.SSegment, ptr %81, i32 0, i32 3
  store ptr %80, ptr %82, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #6
  ret void
}

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

declare void @FreeSegments() #4

; Function Attrs: nounwind
declare double @sqrt(double noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #2 = { nounwind 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 = { 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 = { "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 #5 = { 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 #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }
attributes #8 = { noreturn 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 40}
!12 = !{!"Segment", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !6, i64 48}
!13 = !{!12, !6, i64 32}
!14 = !{!12, !6, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !10, i64 40}
!18 = !{!"SSegment", !7, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44}
!19 = !{!18, !6, i64 32}
!20 = !{!18, !6, i64 24}
!21 = distinct !{!21, !16}


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

@Dimension = external dso_local local_unnamed_addr global i32, align 4
@.str.1 = external hidden unnamed_addr constant [79 x i8], align 1
@GroupSize = external dso_local local_unnamed_addr global i32, align 4
@Groups = external dso_local local_unnamed_addr global i32, align 4
@.str.16 = external hidden unnamed_addr constant [40 x i8], align 1
@__PRETTY_FUNCTION__.AllocateSegments = external hidden unnamed_addr constant [24 x i8], align 1
@FirstSegment = external dso_local local_unnamed_addr global ptr, align 8
@SGroupSize = external dso_local local_unnamed_addr global i32, align 4
@SGroups = external dso_local local_unnamed_addr global i32, align 4
@FirstSSegment = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @AllocateSegments() local_unnamed_addr #2 {
  tail call void @FreeSegments() #5
  %1 = load i32, ptr @Dimension, align 4, !tbaa !5
  %2 = sitofp i32 %1 to double
  %3 = tail call double @sqrt(double noundef %2) #5
  %4 = fptosi double %3 to i32
  store i32 %4, ptr @GroupSize, align 4, !tbaa !5
  store i32 0, ptr @Groups, align 4, !tbaa !5
  %5 = load i32, ptr @Dimension, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %17
  %.032 = phi i32 [ %18, %17 ], [ %5, %0 ]
  %.02531 = phi ptr [ %8, %17 ], [ null, %0 ]
  %7 = phi i32 [ %11, %17 ], [ 0, %0 ]
  %8 = tail call noalias dereferenceable_or_null(56) ptr @malloc(i64 noundef 56) #6
  %.not28 = icmp eq ptr %8, null
  br i1 %.not28, label %9, label %10

9:                                                ; preds = %.lr.ph
  tail call void @__assert_fail(ptr noundef nonnull @.str.16, ptr noundef nonnull @.str.1, i32 noundef 86, ptr noundef nonnull @__PRETTY_FUNCTION__.AllocateSegments) #7
  unreachable

10:                                               ; preds = %.lr.ph
  %11 = add nuw nsw i32 %7, 1
  store i32 %11, ptr @Groups, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %8, i64 40
  store i32 %11, ptr %12, align 8, !tbaa !9
  %.not29 = icmp eq ptr %.02531, null
  br i1 %.not29, label %13, label %14

13:                                               ; preds = %10
  store ptr %8, ptr @FirstSegment, align 8, !tbaa !12
  br label %17

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %.02531, i64 32
  store ptr %8, ptr %15, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %8, i64 24
  store ptr %.02531, ptr %16, align 8, !tbaa !14
  br label %17

17:                                               ; preds = %13, %14
  %18 = sub nsw i32 %.032, %4
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.lr.ph, label %.lr.ph36.preheader, !llvm.loop !15

._crit_edge:                                      ; preds = %0
  %20 = load ptr, ptr @FirstSegment, align 8, !tbaa !12
  store ptr %20, ptr inttoptr (i64 32 to ptr), align 32, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %20, i64 24
  store ptr null, ptr %21, align 8, !tbaa !14
  store i32 %5, ptr @SGroupSize, align 4, !tbaa !5
  br label %._crit_edge37

.lr.ph36.preheader:                               ; preds = %17
  %22 = load ptr, ptr @FirstSegment, align 8, !tbaa !12
  %23 = getelementptr inbounds i8, ptr %8, i64 32
  store ptr %22, ptr %23, align 8, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %22, i64 24
  store ptr %8, ptr %24, align 8, !tbaa !14
  store i32 %5, ptr @SGroupSize, align 4, !tbaa !5
  br label %.lr.ph36

.lr.ph36:                                         ; preds = %.lr.ph36.preheader, %33
  %.134 = phi i32 [ %34, %33 ], [ %11, %.lr.ph36.preheader ]
  %.02333 = phi ptr [ %26, %33 ], [ null, %.lr.ph36.preheader ]
  %25 = phi i32 [ %27, %33 ], [ 0, %.lr.ph36.preheader ]
  %26 = tail call noalias dereferenceable_or_null(48) ptr @malloc(i64 noundef 48) #6
  %27 = add nuw nsw i32 %25, 1
  %28 = getelementptr inbounds i8, ptr %26, i64 40
  store i32 %27, ptr %28, align 8, !tbaa !17
  %.not = icmp eq ptr %.02333, null
  br i1 %.not, label %29, label %30

29:                                               ; preds = %.lr.ph36
  store ptr %26, ptr @FirstSSegment, align 8, !tbaa !12
  br label %33

30:                                               ; preds = %.lr.ph36
  %31 = getelementptr inbounds i8, ptr %.02333, i64 32
  store ptr %26, ptr %31, align 8, !tbaa !19
  %32 = getelementptr inbounds i8, ptr %26, i64 24
  store ptr %.02333, ptr %32, align 8, !tbaa !20
  br label %33

33:                                               ; preds = %29, %30
  %34 = sub nsw i32 %.134, %5
  %35 = icmp sgt i32 %34, 0
  br i1 %35, label %.lr.ph36, label %._crit_edge37, !llvm.loop !21

._crit_edge37:                                    ; preds = %33, %._crit_edge
  %.sink = phi i32 [ 0, %._crit_edge ], [ %27, %33 ]
  %.023.lcssa = phi ptr [ null, %._crit_edge ], [ %26, %33 ]
  store i32 %.sink, ptr @SGroups, align 4, !tbaa !5
  %36 = load ptr, ptr @FirstSSegment, align 8, !tbaa !12
  %37 = getelementptr inbounds i8, ptr %.023.lcssa, i64 32
  store ptr %36, ptr %37, align 8, !tbaa !19
  %38 = getelementptr inbounds i8, ptr %36, i64 24
  store ptr %.023.lcssa, ptr %38, align 8, !tbaa !20
  ret void
}

declare void @FreeSegments() local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @sqrt(double noundef) local_unnamed_addr #4

attributes #0 = { noreturn 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 = { "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 = { mustprogress nofree nounwind willreturn memory(write) "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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }
attributes #7 = { noreturn 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/C++ TBAA"}
!9 = !{!10, !6, i64 40}
!10 = !{!"Segment", !7, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !6, i64 40, !6, i64 44, !11, i64 48}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 32}
!14 = !{!10, !11, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !6, i64 40}
!18 = !{!"SSegment", !7, i64 0, !11, i64 8, !11, i64 16, !11, i64 24, !11, i64 32, !6, i64 40, !6, i64 44}
!19 = !{!18, !11, i64 32}
!20 = !{!18, !11, i64 24}
!21 = distinct !{!21, !16}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass