; LLVM IR from maksimandrianov/cdcontainers :: examples (array)

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

; Function Attrs: nounwind uwtable
define dso_local ptr @find_uint_prime_numbers(i32 noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store ptr null, ptr %4, align 8, !tbaa !9
  %11 = call i32 @cdc_array_ctor(ptr noundef %4, ptr noundef null)
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %96

14:                                               ; preds = %1
  %15 = load ptr, ptr %4, align 8, !tbaa !9
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = add i32 %16, 1
  %18 = zext i32 %17 to i64
  %19 = call i32 @cdc_array_reserve(ptr noundef %15, i64 noundef %18)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %20

20:                                               ; preds = %32, %14
  %21 = load i32, ptr %6, align 4, !tbaa !5
  %22 = load i32, ptr %3, align 4, !tbaa !5
  %23 = add i32 %22, 1
  %24 = icmp ult i32 %21, %23
  br i1 %24, label %26, label %25

25:                                               ; preds = %20
  store i32 2, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %35

26:                                               ; preds = %20
  %27 = load ptr, ptr %4, align 8, !tbaa !9
  %28 = load i32, ptr %6, align 4, !tbaa !5
  %29 = zext i32 %28 to i64
  %30 = inttoptr i64 %29 to ptr
  %31 = call i32 @cdc_array_push_back(ptr noundef %27, ptr noundef %30)
  br label %32

32:                                               ; preds = %26
  %33 = load i32, ptr %6, align 4, !tbaa !5
  %34 = add i32 %33, 1
  store i32 %34, ptr %6, align 4, !tbaa !5
  br label %20, !llvm.loop !11

35:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr null, ptr %7, align 8, !tbaa !9
  %36 = call i32 @cdc_array_ctor(ptr noundef %7, ptr noundef null)
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %35
  %39 = load ptr, ptr %4, align 8, !tbaa !9
  call void @cdc_array_dtor(ptr noundef %39)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %95

40:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 2, ptr %8, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %87, %40
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = add i32 %43, 1
  %45 = icmp ult i32 %42, %44
  br i1 %45, label %47, label %46

46:                                               ; preds = %41
  store i32 5, ptr %5, align 4
  br label %90

47:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  %48 = load ptr, ptr %4, align 8, !tbaa !9
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = zext i32 %49 to i64
  %51 = call ptr @cdc_array_get(ptr noundef %48, i64 noundef %50)
  store ptr %51, ptr %9, align 8, !tbaa !9
  %52 = load ptr, ptr %9, align 8, !tbaa !9
  %53 = ptrtoint ptr %52 to i64
  %54 = trunc i64 %53 to i32
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %83

56:                                               ; preds = %47
  %57 = load ptr, ptr %7, align 8, !tbaa !9
  %58 = load ptr, ptr %9, align 8, !tbaa !9
  %59 = call i32 @cdc_array_push_back(ptr noundef %57, ptr noundef %58)
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %64

61:                                               ; preds = %56
  %62 = load ptr, ptr %7, align 8, !tbaa !9
  call void @cdc_array_dtor(ptr noundef %62)
  %63 = load ptr, ptr %4, align 8, !tbaa !9
  call void @cdc_array_dtor(ptr noundef %63)
  store ptr null, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %84

64:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %65 = load i32, ptr %8, align 4, !tbaa !5
  %66 = load i32, ptr %8, align 4, !tbaa !5
  %67 = mul i32 %65, %66
  store i32 %67, ptr %10, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %78, %64
  %69 = load i32, ptr %10, align 4, !tbaa !5
  %70 = load i32, ptr %3, align 4, !tbaa !5
  %71 = add i32 %70, 1
  %72 = icmp ult i32 %69, %71
  br i1 %72, label %74, label %73

73:                                               ; preds = %68
  store i32 8, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  br label %82

74:                                               ; preds = %68
  %75 = load ptr, ptr %4, align 8, !tbaa !9
  %76 = load i32, ptr %10, align 4, !tbaa !5
  %77 = zext i32 %76 to i64
  call void @cdc_array_set(ptr noundef %75, i64 noundef %77, ptr noundef null)
  br label %78

78:                                               ; preds = %74
  %79 = load i32, ptr %8, align 4, !tbaa !5
  %80 = load i32, ptr %10, align 4, !tbaa !5
  %81 = add i32 %80, %79
  store i32 %81, ptr %10, align 4, !tbaa !5
  br label %68, !llvm.loop !13

82:                                               ; preds = %73
  br label %83

83:                                               ; preds = %82, %47
  store i32 0, ptr %5, align 4
  br label %84

84:                                               ; preds = %83, %61
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %85 = load i32, ptr %5, align 4
  switch i32 %85, label %90 [
    i32 0, label %86
  ]

86:                                               ; preds = %84
  br label %87

87:                                               ; preds = %86
  %88 = load i32, ptr %8, align 4, !tbaa !5
  %89 = add i32 %88, 1
  store i32 %89, ptr %8, align 4, !tbaa !5
  br label %41, !llvm.loop !14

90:                                               ; preds = %84, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %91 = load i32, ptr %5, align 4
  switch i32 %91, label %95 [
    i32 5, label %92
  ]

92:                                               ; preds = %90
  %93 = load ptr, ptr %4, align 8, !tbaa !9
  call void @cdc_array_dtor(ptr noundef %93)
  %94 = load ptr, ptr %7, align 8, !tbaa !9
  store ptr %94, ptr %2, align 8
  store i32 1, ptr %5, align 4
  br label %95

95:                                               ; preds = %92, %90, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %96

96:                                               ; preds = %95, %13
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  %97 = load ptr, ptr %2, align 8
  ret ptr %97
}

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

declare i32 @cdc_array_ctor(ptr noundef, ptr noundef) #2

declare i32 @cdc_array_reserve(ptr noundef, i64 noundef) #2

declare i32 @cdc_array_push_back(ptr noundef, ptr noundef) #2

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

declare void @cdc_array_dtor(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @cdc_array_get(ptr noundef, i64 noundef) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cdc_array_set(ptr noundef, i64 noundef, ptr noundef) #3

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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

; Function Attrs: nounwind uwtable
define dso_local ptr @find_uint_prime_numbers(i32 noundef %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  store ptr null, ptr %2, align 8, !tbaa !5
  %4 = call i32 @cdc_array_ctor(ptr noundef nonnull %2, ptr noundef null) #4
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %36

5:                                                ; preds = %1
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = add i32 %0, 1
  %8 = zext i32 %7 to i64
  %9 = call i32 @cdc_array_reserve(ptr noundef %6, i64 noundef %8) #4
  %.not41 = icmp eq i32 %7, 0
  br i1 %.not41, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  store ptr null, ptr %3, align 8, !tbaa !5
  %10 = call i32 @cdc_array_ctor(ptr noundef nonnull %3, ptr noundef null) #4
  %.not27 = icmp eq i32 %10, 0
  br i1 %.not27, label %.preheader, label %14

.preheader:                                       ; preds = %._crit_edge
  %.not3037 = icmp ugt i32 %7, 2
  br i1 %.not3037, label %.lr.ph40, label %.critedge32

.lr.ph:                                           ; preds = %5, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %5 ]
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = inttoptr i64 %indvars.iv to ptr
  %13 = call i32 @cdc_array_push_back(ptr noundef %11, ptr noundef %12) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %8
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !9

14:                                               ; preds = %._crit_edge
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  call void @cdc_array_dtor(ptr noundef %15) #4
  br label %35

.lr.ph40:                                         ; preds = %.preheader, %.loopexit
  %indvars.iv43 = phi i64 [ %indvars.iv.next44, %.loopexit ], [ 2, %.preheader ]
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = call ptr @cdc_array_get(ptr noundef %16, i64 noundef %indvars.iv43)
  %18 = ptrtoint ptr %17 to i64
  %19 = and i64 %18, 4294967295
  %.not28 = icmp eq i64 %19, 0
  br i1 %.not28, label %.loopexit, label %20

20:                                               ; preds = %.lr.ph40
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call i32 @cdc_array_push_back(ptr noundef %21, ptr noundef %17) #4
  %.not29 = icmp eq i32 %22, 0
  br i1 %.not29, label %25, label %.critedge

.critedge:                                        ; preds = %20
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  call void @cdc_array_dtor(ptr noundef %23) #4
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  call void @cdc_array_dtor(ptr noundef %24) #4
  br label %35

25:                                               ; preds = %20
  %26 = trunc nuw i64 %indvars.iv43 to i32
  %27 = mul i32 %26, %26
  %28 = icmp ult i32 %27, %7
  br i1 %28, label %.lr.ph36, label %.loopexit

.lr.ph36:                                         ; preds = %25, %.lr.ph36
  %.034 = phi i32 [ %31, %.lr.ph36 ], [ %27, %25 ]
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = zext i32 %.034 to i64
  call void @cdc_array_set(ptr noundef %29, i64 noundef %30, ptr noundef null)
  %31 = add i32 %.034, %26
  %32 = icmp ult i32 %31, %7
  br i1 %32, label %.lr.ph36, label %.loopexit, !llvm.loop !11

.loopexit:                                        ; preds = %.lr.ph36, %25, %.lr.ph40
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %exitcond47.not = icmp eq i64 %indvars.iv.next44, %8
  br i1 %exitcond47.not, label %.critedge32, label %.lr.ph40, !llvm.loop !12

.critedge32:                                      ; preds = %.loopexit, %.preheader
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  call void @cdc_array_dtor(ptr noundef %33) #4
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  br label %35

35:                                               ; preds = %.critedge, %.critedge32, %14
  %.3 = phi ptr [ null, %14 ], [ %34, %.critedge32 ], [ null, %.critedge ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  br label %36

36:                                               ; preds = %1, %35
  %.4 = phi ptr [ %.3, %35 ], [ null, %1 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  ret ptr %.4
}

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

declare i32 @cdc_array_ctor(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @cdc_array_reserve(ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @cdc_array_push_back(ptr noundef, ptr noundef) local_unnamed_addr #2

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

declare void @cdc_array_dtor(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @cdc_array_get(ptr noundef, i64 noundef) local_unnamed_addr #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @cdc_array_set(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass