; LLVM IR from Overload-Technologies/Overload :: Dependencies/soloud/src/audiosource/speech/darray.ll (ZN6darray12getDataInPosEi)

; 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.darray = type <{ ptr, i32, i32, i32, [4 x i8] }>

; Function Attrs: nounwind
declare void @free(ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN6darray12getDataInPosEi(ptr noundef nonnull align 8 dereferenceable(20) %0, i32 noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %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
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %9 = load ptr, ptr %4, align 8
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 2
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = icmp slt i32 %10, %12
  br i1 %13, label %14, label %25

14:                                               ; preds = %2
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 1
  %17 = load i32, ptr %16, align 8, !tbaa !13
  %18 = icmp slt i32 %15, %17
  br i1 %18, label %19, label %25

19:                                               ; preds = %14
  %20 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = load i32, ptr %5, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %21, i64 %23
  store ptr %24, ptr %3, align 8
  br label %93

25:                                               ; preds = %14, %2
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 2
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = icmp sge i32 %26, %28
  br i1 %29, label %30, label %78

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %31 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !11
  store i32 %32, ptr %6, align 4, !tbaa !9
  br label %33

33:                                               ; preds = %37, %30
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = icmp sle i32 %34, %35
  br i1 %36, label %37, label %45

37:                                               ; preds = %33
  %38 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 3
  %39 = load i32, ptr %38, align 8, !tbaa !15
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = add nsw i32 %40, %39
  store i32 %41, ptr %6, align 4, !tbaa !9
  %42 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 3
  %43 = load i32, ptr %42, align 8, !tbaa !15
  %44 = mul nsw i32 %43, 2
  store i32 %44, ptr %42, align 8, !tbaa !15
  br label %33, !llvm.loop !16

45:                                               ; preds = %33
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %46 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !14
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = call ptr @realloc(ptr noundef %47, i64 noundef %49) #6
  store ptr %50, ptr %7, align 8, !tbaa !5
  %51 = load ptr, ptr %7, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %59, label %53

53:                                               ; preds = %45
  %54 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !14
  call void @free(ptr noundef %55) #5
  %56 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 0
  store ptr null, ptr %56, align 8, !tbaa !14
  %57 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 1
  store i32 0, ptr %57, align 8, !tbaa !13
  %58 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 2
  store i32 0, ptr %58, align 4, !tbaa !11
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %75

59:                                               ; preds = %45
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 2
  %62 = load i32, ptr %61, align 4, !tbaa !11
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i8, ptr %60, i64 %63
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 2
  %67 = load i32, ptr %66, align 4, !tbaa !11
  %68 = sub nsw i32 %65, %67
  %69 = sext i32 %68 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %64, i8 0, i64 %69, i1 false)
  br label %70

70:                                               ; preds = %59
  %71 = load ptr, ptr %7, align 8, !tbaa !5
  %72 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 0
  store ptr %71, ptr %72, align 8, !tbaa !14
  %73 = load i32, ptr %6, align 4, !tbaa !9
  %74 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 2
  store i32 %73, ptr %74, align 4, !tbaa !11
  store i32 0, ptr %8, align 4
  br label %75

75:                                               ; preds = %70, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %76 = load i32, ptr %8, align 4
  switch i32 %76, label %95 [
    i32 0, label %77
    i32 1, label %93
  ]

77:                                               ; preds = %75
  br label %78

78:                                               ; preds = %77, %25
  %79 = load i32, ptr %5, align 4, !tbaa !9
  %80 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 1
  %81 = load i32, ptr %80, align 8, !tbaa !13
  %82 = icmp sge i32 %79, %81
  br i1 %82, label %83, label %87

83:                                               ; preds = %78
  %84 = load i32, ptr %5, align 4, !tbaa !9
  %85 = add nsw i32 %84, 1
  %86 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 1
  store i32 %85, ptr %86, align 8, !tbaa !13
  br label %87

87:                                               ; preds = %83, %78
  %88 = getelementptr inbounds %class.darray, ptr %9, i32 0, i32 0
  %89 = load ptr, ptr %88, align 8, !tbaa !14
  %90 = load i32, ptr %5, align 4, !tbaa !9
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds i8, ptr %89, i64 %91
  store ptr %92, ptr %3, align 8
  br label %93

93:                                               ; preds = %87, %75, %19
  %94 = load ptr, ptr %3, align 8
  ret ptr %94

95:                                               ; preds = %75
  unreachable
}

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

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #3

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

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

attributes #0 = { 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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind allocsize(1) "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nounwind }
attributes #6 = { nounwind allocsize(1) }

!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 12}
!12 = !{!"_ZTS6darray", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !6, i64 0}
!15 = !{!12, !10, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_ZN6darray12getDataInPosEi(ptr nocapture noundef nonnull align 8 dereferenceable(20) %0, i32 noundef %1) local_unnamed_addr #1 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 12
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, %1
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i32, ptr %6, align 8
  %8 = icmp sgt i32 %7, %1
  %or.cond = select i1 %5, i1 %8, i1 false
  br i1 %or.cond, label %9, label %13

9:                                                ; preds = %2
  %10 = load ptr, ptr %0, align 8, !tbaa !11
  %11 = sext i32 %1 to i64
  %12 = getelementptr inbounds i8, ptr %10, i64 %11
  br label %38

13:                                               ; preds = %2
  br i1 %5, label %30, label %.preheader

.preheader:                                       ; preds = %13
  %14 = getelementptr inbounds i8, ptr %0, i64 16
  %.promoted = load i32, ptr %14, align 8, !tbaa !12
  br label %15

15:                                               ; preds = %.preheader, %15
  %16 = phi i32 [ %.promoted, %.preheader ], [ %18, %15 ]
  %.01930 = phi i32 [ %4, %.preheader ], [ %17, %15 ]
  %17 = add nsw i32 %16, %.01930
  %18 = shl nsw i32 %16, 1
  %.not23 = icmp sgt i32 %17, %1
  br i1 %.not23, label %19, label %15, !llvm.loop !13

19:                                               ; preds = %15
  store i32 %18, ptr %14, align 8, !tbaa !12
  %20 = load ptr, ptr %0, align 8, !tbaa !11
  %21 = sext i32 %17 to i64
  %22 = tail call ptr @realloc(ptr noundef %20, i64 noundef %21) #4
  %.not24 = icmp eq ptr %22, null
  br i1 %.not24, label %28, label %.thread

.thread:                                          ; preds = %19
  %23 = load i32, ptr %3, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds i8, ptr %22, i64 %24
  %26 = sub nsw i32 %17, %23
  %27 = sext i32 %26 to i64
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %25, i8 0, i64 %27, i1 false)
  store ptr %22, ptr %0, align 8, !tbaa !11
  store i32 %17, ptr %3, align 4, !tbaa !5
  %.pre = load i32, ptr %6, align 8, !tbaa !15
  br label %30

28:                                               ; preds = %19
  %29 = load ptr, ptr %0, align 8, !tbaa !11
  tail call void @free(ptr noundef %29) #5
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %0, i8 0, i64 16, i1 false)
  br label %38

30:                                               ; preds = %.thread, %13
  %31 = phi i32 [ %.pre, %.thread ], [ %7, %13 ]
  %.not25 = icmp sgt i32 %31, %1
  br i1 %.not25, label %34, label %32

32:                                               ; preds = %30
  %33 = add nsw i32 %1, 1
  store i32 %33, ptr %6, align 8, !tbaa !15
  br label %34

34:                                               ; preds = %32, %30
  %35 = load ptr, ptr %0, align 8, !tbaa !11
  %36 = sext i32 %1 to i64
  %37 = getelementptr inbounds i8, ptr %35, i64 %36
  br label %38

38:                                               ; preds = %28, %34, %9
  %.1 = phi ptr [ %12, %9 ], [ null, %28 ], [ %37, %34 ]
  ret ptr %.1
}

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #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 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind allocsize(1) }
attributes #5 = { 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, !10, i64 12}
!6 = !{!"_ZTS6darray", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 16}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!6, !10, i64 8}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass