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

; 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
declare dso_local noundef i32 @_Z18ImTextCharFromUtf8PjPKcS1_(ptr noundef, ptr noundef, ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z24ImTextCountCharsFromUtf8PKcS0_(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) #2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %20, %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 i8, ptr %15, align 1, !tbaa !11
  %17 = icmp ne i8 %16, 0
  br label %18

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

20:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = call noundef i32 @_Z18ImTextCharFromUtf8PjPKcS1_(ptr noundef %6, ptr noundef %21, ptr noundef %22)
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = sext i32 %23 to i64
  %26 = getelementptr inbounds i8, ptr %24, i64 %25
  store ptr %26, ptr %3, align 8, !tbaa !5
  %27 = load i32, ptr %5, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %7, !llvm.loop !12

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

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 = { 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 = distinct !{!12, !13}
!13 = !{!"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 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
declare dso_local noundef i32 @_Z18ImTextCharFromUtf8PjPKcS1_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z24ImTextCountCharsFromUtf8PKcS0_(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca i32, align 4
  %.not = icmp eq ptr %1, null
  %4 = icmp ult ptr %0, %1
  %or.cond11 = or i1 %.not, %4
  br i1 %or.cond11, 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
  %5 = load i8, ptr %0, align 1, !tbaa !5
  %.not10.us16 = icmp eq i8 %5, 0
  br i1 %.not10.us16, label %.critedge, label %.lr.ph19

.lr.ph19:                                         ; preds = %.lr.ph.split.us, %.lr.ph19
  %.0812.us18 = phi ptr [ %8, %.lr.ph19 ], [ %0, %.lr.ph.split.us ]
  %.013.us17 = phi i32 [ %9, %.lr.ph19 ], [ 0, %.lr.ph.split.us ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  %6 = call noundef i32 @_Z18ImTextCharFromUtf8PjPKcS1_(ptr noundef nonnull %3, ptr noundef nonnull %.0812.us18, ptr noundef null)
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds i8, ptr %.0812.us18, i64 %7
  %9 = add nuw nsw i32 %.013.us17, 1
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  %10 = load i8, ptr %8, align 1, !tbaa !5
  %.not10.us = icmp eq i8 %10, 0
  br i1 %.not10.us, label %.critedge, label %.lr.ph19

.lr.ph.split:                                     ; preds = %.lr.ph, %12
  %.013 = phi i32 [ %16, %12 ], [ 0, %.lr.ph ]
  %.0812 = phi ptr [ %15, %12 ], [ %0, %.lr.ph ]
  %11 = load i8, ptr %.0812, align 1, !tbaa !5
  %.not10 = icmp eq i8 %11, 0
  br i1 %.not10, label %.critedge, label %12

12:                                               ; preds = %.lr.ph.split
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  %13 = call noundef i32 @_Z18ImTextCharFromUtf8PjPKcS1_(ptr noundef nonnull %3, ptr noundef nonnull %.0812, ptr noundef nonnull %1)
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %.0812, i64 %14
  %16 = add nuw nsw i32 %.013, 1
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  %17 = icmp ult ptr %15, %1
  br i1 %17, label %.lr.ph.split, label %.critedge, !llvm.loop !8

.critedge:                                        ; preds = %.lr.ph.split, %12, %.lr.ph19, %.lr.ph.split.us, %2
  %.0.lcssa = phi i32 [ 0, %2 ], [ 0, %.lr.ph.split.us ], [ %9, %.lr.ph19 ], [ %16, %12 ], [ %.013, %.lr.ph.split ]
  ret i32 %.0.lcssa
}

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 = { 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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


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