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

; 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 @_Z17ImTextStrFromUtf8PtiPKcS1_PS1_(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %14, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = load i32, ptr %7, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds i16, ptr %15, i64 %17
  store ptr %18, ptr %12, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %37, %5
  %20 = load ptr, ptr %11, align 8, !tbaa !5
  %21 = load ptr, ptr %12, align 8, !tbaa !5
  %22 = getelementptr inbounds i16, ptr %21, i64 -1
  %23 = icmp ult ptr %20, %22
  br i1 %23, label %24, label %35

24:                                               ; preds = %19
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %31

27:                                               ; preds = %24
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = icmp ult ptr %28, %29
  br i1 %30, label %31, label %35

31:                                               ; preds = %27, %24
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = icmp ne i8 %33, 0
  br label %35

35:                                               ; preds = %31, %27, %19
  %36 = phi i1 [ false, %27 ], [ false, %19 ], [ %34, %31 ]
  br i1 %36, label %37, label %48

37:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %9, align 8, !tbaa !5
  %40 = call noundef i32 @_Z18ImTextCharFromUtf8PjPKcS1_(ptr noundef %13, ptr noundef %38, ptr noundef %39)
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = sext i32 %40 to i64
  %43 = getelementptr inbounds i8, ptr %41, i64 %42
  store ptr %43, ptr %8, align 8, !tbaa !5
  %44 = load i32, ptr %13, align 4, !tbaa !9
  %45 = trunc i32 %44 to i16
  %46 = load ptr, ptr %11, align 8, !tbaa !5
  %47 = getelementptr inbounds i16, ptr %46, i32 1
  store ptr %47, ptr %11, align 8, !tbaa !5
  store i16 %45, ptr %46, align 2, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  br label %19, !llvm.loop !14

48:                                               ; preds = %35
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  store i16 0, ptr %49, align 2, !tbaa !12
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %55

52:                                               ; preds = %48
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %53, ptr %54, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %52, %48
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = ptrtoint ptr %56 to i64
  %59 = ptrtoint ptr %57 to i64
  %60 = sub i64 %58, %59
  %61 = sdiv exact i64 %60, 2
  %62 = trunc i64 %61 to i32
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  ret i32 %62
}

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 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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 @_Z17ImTextStrFromUtf8PtiPKcS1_PS1_(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef writeonly %4) local_unnamed_addr #1 {
  %6 = alloca i32, align 4
  %7 = sext i32 %1 to i64
  %8 = getelementptr inbounds i16, ptr %0, i64 %7
  %9 = getelementptr inbounds i8, ptr %8, i64 -2
  %10 = icmp ugt ptr %9, %0
  br i1 %10, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph, %12
  %.024.us = phi ptr [ %15, %12 ], [ %2, %.lr.ph ]
  %.01823.us = phi ptr [ %18, %12 ], [ %0, %.lr.ph ]
  %11 = load i8, ptr %.024.us, align 1, !tbaa !5
  %.not21.us = icmp eq i8 %11, 0
  br i1 %.not21.us, label %.critedge, label %12

12:                                               ; preds = %.lr.ph.split.us
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  %13 = call noundef i32 @_Z18ImTextCharFromUtf8PjPKcS1_(ptr noundef nonnull %6, ptr noundef nonnull %.024.us, ptr noundef null)
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds i8, ptr %.024.us, i64 %14
  %16 = load i32, ptr %6, align 4, !tbaa !8
  %17 = trunc i32 %16 to i16
  %18 = getelementptr inbounds i8, ptr %.01823.us, i64 2
  store i16 %17, ptr %.01823.us, align 2, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  %19 = icmp ult ptr %18, %9
  br i1 %19, label %.lr.ph.split.us, label %.critedge, !llvm.loop !12

.lr.ph.split:                                     ; preds = %.lr.ph, %23
  %.024 = phi ptr [ %26, %23 ], [ %2, %.lr.ph ]
  %.01823 = phi ptr [ %29, %23 ], [ %0, %.lr.ph ]
  %20 = icmp ult ptr %.024, %3
  br i1 %20, label %21, label %.critedge

21:                                               ; preds = %.lr.ph.split
  %22 = load i8, ptr %.024, align 1, !tbaa !5
  %.not21 = icmp eq i8 %22, 0
  br i1 %.not21, label %.critedge, label %23

23:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #2
  %24 = call noundef i32 @_Z18ImTextCharFromUtf8PjPKcS1_(ptr noundef nonnull %6, ptr noundef nonnull %.024, ptr noundef nonnull %3)
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %.024, i64 %25
  %27 = load i32, ptr %6, align 4, !tbaa !8
  %28 = trunc i32 %27 to i16
  %29 = getelementptr inbounds i8, ptr %.01823, i64 2
  store i16 %28, ptr %.01823, align 2, !tbaa !10
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #2
  %30 = icmp ult ptr %29, %9
  br i1 %30, label %.lr.ph.split, label %.critedge, !llvm.loop !12

.critedge:                                        ; preds = %21, %23, %.lr.ph.split, %.lr.ph.split.us, %12, %5
  %.018.lcssa = phi ptr [ %0, %5 ], [ %18, %12 ], [ %.01823.us, %.lr.ph.split.us ], [ %.01823, %.lr.ph.split ], [ %29, %23 ], [ %.01823, %21 ]
  %.0.lcssa = phi ptr [ %2, %5 ], [ %15, %12 ], [ %.024.us, %.lr.ph.split.us ], [ %.024, %.lr.ph.split ], [ %26, %23 ], [ %.024, %21 ]
  store i16 0, ptr %.018.lcssa, align 2, !tbaa !10
  %.not22 = icmp eq ptr %4, null
  br i1 %.not22, label %32, label %31

31:                                               ; preds = %.critedge
  store ptr %.0.lcssa, ptr %4, align 8, !tbaa !14
  br label %32

32:                                               ; preds = %31, %.critedge
  %33 = ptrtoint ptr %.018.lcssa to i64
  %34 = ptrtoint ptr %0 to i64
  %35 = sub i64 %33, %34
  %36 = lshr exact i64 %35, 1
  %37 = trunc i64 %36 to i32
  ret i32 %37
}

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 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"short", !6, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !15, i64 0}
!15 = !{!"any pointer", !6, i64 0}


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