; LLVM IR from Samson-Mano/EM_Propogation_simulation :: EM_Propogation_simulation/src/ImGui/imgui.ll (Z27ImTextCountUtf8BytesFromStrPKtS0_)

; 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: 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 @_Z27ImTextCountUtf8BytesFromStrPKtS0_(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %35, %2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %14

10:                                               ; preds = %7
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8, !tbaa !5
  %13 = icmp ult ptr %11, %12
  br i1 %13, label %14, label %18

14:                                               ; preds = %10, %7
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load i16, ptr %15, align 2, !tbaa !11
  %17 = icmp ne i16 %16, 0
  br label %18

18:                                               ; preds = %14, %10
  %19 = phi i1 [ false, %10 ], [ %17, %14 ]
  br i1 %19, label %20, label %36

20:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds i16, ptr %21, i32 1
  store ptr %22, ptr %3, align 8, !tbaa !5
  %23 = load i16, ptr %21, align 2, !tbaa !11
  %24 = zext i16 %23 to i32
  store i32 %24, ptr %6, align 4, !tbaa !9
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = icmp ult i32 %25, 128
  br i1 %26, label %27, label %30

27:                                               ; preds = %20
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %5, align 4, !tbaa !9
  br label %35

30:                                               ; preds = %20
  %31 = load i32, ptr %6, align 4, !tbaa !9
  %32 = call noundef i32 @_ZL28ImTextCountUtf8BytesFromCharj(i32 noundef %31)
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = add nsw i32 %33, %32
  store i32 %34, ptr %5, align 4, !tbaa !9
  br label %35

35:                                               ; preds = %30, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %7, !llvm.loop !13

36:                                               ; preds = %18
  %37 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret i32 %37
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL28ImTextCountUtf8BytesFromCharj(i32 noundef) #2

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 = { inlinehint 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 = { 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, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 uwtable
define dso_local noundef i32 @_Z27ImTextCountUtf8BytesFromStrPKtS0_(ptr noundef readonly %0, ptr noundef readnone %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %1, null
  %3 = icmp ult ptr %0, %1
  %or.cond14 = or i1 %.not, %3
  br i1 %or.cond14, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %2
  br i1 %.not, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph
  %4 = load i16, ptr %0, align 2, !tbaa !5
  %.not13.us19 = icmp eq i16 %4, 0
  br i1 %.not13.us19, label %.critedge, label %.lr.ph22

.lr.ph22:                                         ; preds = %.lr.ph.split.us, %14
  %5 = phi i16 [ %15, %14 ], [ %4, %.lr.ph.split.us ]
  %.0915.us21 = phi i32 [ %.1.us, %14 ], [ 0, %.lr.ph.split.us ]
  %.016.us20 = phi ptr [ %6, %14 ], [ %0, %.lr.ph.split.us ]
  %6 = getelementptr inbounds i8, ptr %.016.us20, i64 2
  %7 = icmp ult i16 %5, 128
  br i1 %7, label %12, label %8

8:                                                ; preds = %.lr.ph22
  %9 = zext i16 %5 to i32
  %10 = tail call noundef i32 @_ZL28ImTextCountUtf8BytesFromCharj(i32 noundef %9)
  %11 = add nsw i32 %10, %.0915.us21
  br label %14

12:                                               ; preds = %.lr.ph22
  %13 = add nsw i32 %.0915.us21, 1
  br label %14

14:                                               ; preds = %12, %8
  %.1.us = phi i32 [ %13, %12 ], [ %11, %8 ]
  %15 = load i16, ptr %6, align 2, !tbaa !5
  %.not13.us = icmp eq i16 %15, 0
  br i1 %.not13.us, label %.critedge, label %.lr.ph22

.lr.ph.split:                                     ; preds = %.lr.ph, %26
  %.016 = phi ptr [ %18, %26 ], [ %0, %.lr.ph ]
  %.0915 = phi i32 [ %.1, %26 ], [ 0, %.lr.ph ]
  %16 = load i16, ptr %.016, align 2, !tbaa !5
  %.not13 = icmp eq i16 %16, 0
  br i1 %.not13, label %.critedge, label %17

17:                                               ; preds = %.lr.ph.split
  %18 = getelementptr inbounds i8, ptr %.016, i64 2
  %19 = icmp ult i16 %16, 128
  br i1 %19, label %20, label %22

20:                                               ; preds = %17
  %21 = add nsw i32 %.0915, 1
  br label %26

22:                                               ; preds = %17
  %23 = zext i16 %16 to i32
  %24 = tail call noundef i32 @_ZL28ImTextCountUtf8BytesFromCharj(i32 noundef %23)
  %25 = add nsw i32 %24, %.0915
  br label %26

26:                                               ; preds = %22, %20
  %.1 = phi i32 [ %21, %20 ], [ %25, %22 ]
  %27 = icmp ult ptr %18, %1
  br i1 %27, label %.lr.ph.split, label %.critedge, !llvm.loop !9

.critedge:                                        ; preds = %.lr.ph.split, %26, %14, %.lr.ph.split.us, %2
  %.09.lcssa = phi i32 [ 0, %2 ], [ 0, %.lr.ph.split.us ], [ %.1.us, %14 ], [ %.1, %26 ], [ %.0915, %.lr.ph.split ]
  ret i32 %.09.lcssa
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL28ImTextCountUtf8BytesFromCharj(i32 noundef) local_unnamed_addr #1

attributes #0 = { 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 #1 = { inlinehint 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" }

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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