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

; 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.Element = type { ptr, i8, i8, i8, i8, ptr, ptr, i32, [19 x %class.Interp] }
%class.Interp = type { float, float, i8, i8, i8 }

@_ZL8gElement = external hidden global [69 x %class.Element], 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 @_ZN5klatt12phone_to_elmEPciP6darray(ptr noundef %0, i32 noundef %1, ptr noundef %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %17, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds i8, ptr %18, i64 %20
  store ptr %21, ptr %10, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %92, %3
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = icmp ult ptr %23, %24
  br i1 %25, label %26, label %30

26:                                               ; preds = %22
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = icmp ne i8 %28, 0
  br label %30

30:                                               ; preds = %26, %22
  %31 = phi i1 [ false, %22 ], [ %29, %26 ]
  br i1 %31, label %32, label %93

32:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store ptr null, ptr %11, align 8, !tbaa !5
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = call noundef ptr @_ZL25phoneme_to_element_lookupPcPPv(ptr noundef %33, ptr noundef %11)
  store ptr %34, ptr %8, align 8, !tbaa !5
  %35 = load ptr, ptr %11, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %81

37:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %38 = load ptr, ptr %11, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %38, i32 1
  store ptr %39, ptr %11, align 8, !tbaa !5
  %40 = load i8, ptr %38, align 1, !tbaa !11
  %41 = sext i8 %40 to i32
  store i32 %41, ptr %12, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %62, %37
  %43 = load i32, ptr %12, align 4, !tbaa !9
  %44 = add nsw i32 %43, -1
  store i32 %44, ptr %12, align 4, !tbaa !9
  %45 = icmp sgt i32 %43, 0
  br i1 %45, label %46, label %80

46:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i32 1
  store ptr %48, ptr %11, align 8, !tbaa !5
  %49 = load i8, ptr %47, align 1, !tbaa !11
  %50 = sext i8 %49 to i32
  store i32 %50, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %51 = load i32, ptr %13, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [69 x %class.Element], ptr @_ZL8gElement, i64 0, i64 %52
  store ptr %53, ptr %14, align 8, !tbaa !5
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = load i32, ptr %13, align 4, !tbaa !9
  call void @_ZN6darray3putEi(ptr noundef nonnull align 8 dereferenceable(20) %54, i32 noundef %55)
  %56 = load ptr, ptr %14, align 8, !tbaa !5
  %57 = getelementptr inbounds %class.Element, ptr %56, i32 0, i32 7
  %58 = load i32, ptr %57, align 8, !tbaa !12
  %59 = and i32 %58, 268435456
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %62, label %61

61:                                               ; preds = %46
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %61, %46
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %63 = load ptr, ptr %14, align 8, !tbaa !5
  %64 = getelementptr inbounds %class.Element, ptr %63, i32 0, i32 2
  %65 = load i8, ptr %64, align 1, !tbaa !14
  %66 = sext i8 %65 to i32
  %67 = load ptr, ptr %14, align 8, !tbaa !5
  %68 = getelementptr inbounds %class.Element, ptr %67, i32 0, i32 3
  %69 = load i8, ptr %68, align 2, !tbaa !15
  %70 = sext i8 %69 to i32
  %71 = add nsw i32 %66, %70
  %72 = sdiv i32 %71, 2
  store i32 %72, ptr %15, align 4, !tbaa !9
  %73 = load i32, ptr %15, align 4, !tbaa !9
  %74 = load i32, ptr %9, align 4, !tbaa !9
  %75 = add nsw i32 %74, %73
  store i32 %75, ptr %9, align 4, !tbaa !9
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load i32, ptr %15, align 4, !tbaa !9
  call void @_ZN6darray3putEi(ptr noundef nonnull align 8 dereferenceable(20) %76, i32 noundef %77)
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = load i32, ptr %7, align 4, !tbaa !9
  call void @_ZN6darray3putEi(ptr noundef nonnull align 8 dereferenceable(20) %78, i32 noundef %79)
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %42, !llvm.loop !16

80:                                               ; preds = %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %92

81:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 1, ptr %16) #4
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i32 1
  store ptr %83, ptr %8, align 8, !tbaa !5
  %84 = load i8, ptr %82, align 1, !tbaa !11
  store i8 %84, ptr %16, align 1, !tbaa !11
  %85 = load i8, ptr %16, align 1, !tbaa !11
  %86 = sext i8 %85 to i32
  switch i32 %86, label %90 [
    i32 39, label %87
    i32 44, label %88
    i32 43, label %89
    i32 45, label %91
  ]

87:                                               ; preds = %81
  store i32 3, ptr %7, align 4, !tbaa !9
  br label %91

88:                                               ; preds = %81
  store i32 2, ptr %7, align 4, !tbaa !9
  br label %91

89:                                               ; preds = %81
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %91

90:                                               ; preds = %81
  br label %91

91:                                               ; preds = %90, %89, %88, %87, %81
  call void @llvm.lifetime.end.p0(i64 1, ptr %16) #4
  br label %92

92:                                               ; preds = %91, %80
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %22, !llvm.loop !18

93:                                               ; preds = %30
  %94 = load i32, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i32 %94
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL25phoneme_to_element_lookupPcPPv(ptr noundef, ptr noundef) #2

declare void @_ZN6darray3putEi(ptr noundef nonnull align 8 dereferenceable(20), i32 noundef) #3

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 = { 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 = { "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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 32}
!13 = !{!"_ZTS7Element", !6, i64 0, !7, i64 8, !7, i64 9, !7, i64 10, !7, i64 11, !6, i64 16, !6, i64 24, !10, i64 32, !7, i64 36}
!14 = !{!13, !7, i64 9}
!15 = !{!13, !7, i64 10}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


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

%class.Element = type { ptr, i8, i8, i8, i8, ptr, ptr, i32, [19 x %class.Interp] }
%class.Interp = type { float, float, i8, i8, i8 }

@_ZL8gElement = external hidden local_unnamed_addr global [69 x %class.Element], 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 uwtable
define dso_local noundef i32 @_ZN5klatt12phone_to_elmEPciP6darray(ptr noundef %0, i32 noundef %1, ptr noundef %2) local_unnamed_addr #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = sext i32 %1 to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 %5
  %7 = icmp sgt i32 %1, 0
  br i1 %7, label %.lr.ph38, label %.critedge

.lr.ph38:                                         ; preds = %3, %.loopexit
  %.037 = phi i32 [ %.4, %.loopexit ], [ 0, %3 ]
  %.02236 = phi ptr [ %.123, %.loopexit ], [ %0, %3 ]
  %.02435 = phi i32 [ %.226, %.loopexit ], [ 0, %3 ]
  %8 = load i8, ptr %.02236, align 1, !tbaa !5
  %.not = icmp eq i8 %8, 0
  br i1 %.not, label %.critedge, label %9

9:                                                ; preds = %.lr.ph38
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store ptr null, ptr %4, align 8, !tbaa !8
  %10 = call noundef ptr @_ZL25phoneme_to_element_lookupPcPPv(ptr noundef nonnull %.02236, ptr noundef nonnull %4)
  %11 = load ptr, ptr %4, align 8, !tbaa !8
  %.not29 = icmp eq ptr %11, null
  br i1 %.not29, label %36, label %12

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %11, i64 1
  store ptr %13, ptr %4, align 8, !tbaa !8
  %14 = load i8, ptr %11, align 1, !tbaa !5
  %15 = icmp sgt i8 %14, 0
  br i1 %15, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %12
  %16 = zext nneg i8 %14 to i32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %.133 = phi i32 [ %spec.select, %.lr.ph ], [ %.037, %.lr.ph.preheader ]
  %.12532 = phi i32 [ %34, %.lr.ph ], [ %.02435, %.lr.ph.preheader ]
  %.02731 = phi i32 [ %17, %.lr.ph ], [ %16, %.lr.ph.preheader ]
  %17 = add nsw i32 %.02731, -1
  %18 = load ptr, ptr %4, align 8, !tbaa !8
  %19 = getelementptr inbounds i8, ptr %18, i64 1
  store ptr %19, ptr %4, align 8, !tbaa !8
  %20 = load i8, ptr %18, align 1, !tbaa !5
  %21 = sext i8 %20 to i32
  %22 = sext i8 %20 to i64
  %23 = getelementptr inbounds [69 x %class.Element], ptr @_ZL8gElement, i64 0, i64 %22
  call void @_ZN6darray3putEi(ptr noundef nonnull align 8 dereferenceable(20) %2, i32 noundef %21)
  %24 = getelementptr inbounds i8, ptr %23, i64 32
  %25 = load i32, ptr %24, align 8, !tbaa !10
  %26 = and i32 %25, 268435456
  %.not30 = icmp eq i32 %26, 0
  %spec.select = select i1 %.not30, i32 0, i32 %.133
  %27 = getelementptr inbounds i8, ptr %23, i64 9
  %28 = load i8, ptr %27, align 1, !tbaa !13
  %29 = sext i8 %28 to i16
  %30 = getelementptr inbounds i8, ptr %23, i64 10
  %31 = load i8, ptr %30, align 2, !tbaa !14
  %32 = sext i8 %31 to i16
  %.lhs.trunc = add nsw i16 %32, %29
  %33 = sdiv i16 %.lhs.trunc, 2
  %.sext = sext i16 %33 to i32
  %34 = add nsw i32 %.12532, %.sext
  call void @_ZN6darray3putEi(ptr noundef nonnull align 8 dereferenceable(20) %2, i32 noundef %.sext)
  call void @_ZN6darray3putEi(ptr noundef nonnull align 8 dereferenceable(20) %2, i32 noundef %spec.select)
  %35 = icmp ugt i32 %.02731, 1
  br i1 %35, label %.lr.ph, label %.loopexit, !llvm.loop !15

36:                                               ; preds = %9
  %37 = getelementptr inbounds i8, ptr %10, i64 1
  %38 = load i8, ptr %10, align 1, !tbaa !5
  switch i8 %38, label %.loopexit [
    i8 39, label %39
    i8 44, label %40
    i8 43, label %41
  ]

39:                                               ; preds = %36
  br label %.loopexit

40:                                               ; preds = %36
  br label %.loopexit

41:                                               ; preds = %36
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %12, %39, %40, %41, %36
  %.226 = phi i32 [ %.02435, %36 ], [ %.02435, %41 ], [ %.02435, %40 ], [ %.02435, %39 ], [ %.02435, %12 ], [ %34, %.lr.ph ]
  %.123 = phi ptr [ %37, %36 ], [ %37, %41 ], [ %37, %40 ], [ %37, %39 ], [ %10, %12 ], [ %10, %.lr.ph ]
  %.4 = phi i32 [ %.037, %36 ], [ 1, %41 ], [ 2, %40 ], [ 3, %39 ], [ %.037, %12 ], [ %spec.select, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  %42 = icmp ult ptr %.123, %6
  br i1 %42, label %.lr.ph38, label %.critedge, !llvm.loop !17

.critedge:                                        ; preds = %.lr.ph38, %.loopexit, %3
  %.024.lcssa = phi i32 [ 0, %3 ], [ %.226, %.loopexit ], [ %.02435, %.lr.ph38 ]
  ret i32 %.024.lcssa
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL25phoneme_to_element_lookupPcPPv(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @_ZN6darray3putEi(ptr noundef nonnull align 8 dereferenceable(20), i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { 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 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"any pointer", !6, i64 0}
!10 = !{!11, !12, i64 32}
!11 = !{!"_ZTS7Element", !9, i64 0, !6, i64 8, !6, i64 9, !6, i64 10, !6, i64 11, !9, i64 16, !9, i64 24, !12, i64 32, !6, i64 36}
!12 = !{!"int", !6, i64 0}
!13 = !{!11, !6, i64 9}
!14 = !{!11, !6, i64 10}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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