; LLVM IR from l1mey112/yr11-physics-applied :: cimgui/imgui/imgui.ll (ZN7ImGuiIO22AddInputCharactersUTF8EPKc)

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

%struct.ImGuiIO = type { i32, i32, %struct.ImVec2, float, float, ptr, ptr, float, float, float, float, float, float, float, ptr, ptr, float, i8, ptr, %struct.ImVec2, i8, i8, i8, i8, i8, i8, i8, i8, float, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i8, i8, i8, i8, i8, i8, i8, float, i32, i32, i32, i32, i32, %struct.ImVec2, [652 x i32], [652 x i8], [16 x float], %struct.ImVec2, [5 x i8], float, float, i8, i8, i8, i8, i32, [652 x %struct.ImGuiKeyData], i8, %struct.ImVec2, [5 x %struct.ImVec2], [5 x double], [5 x i8], [5 x i8], [5 x i16], [5 x i16], [5 x i8], [5 x i8], [5 x i8], [5 x float], [5 x float], [5 x float], float, i8, i8, i8, i8, i16, %struct.ImVector }
%struct.ImGuiKeyData = type { i8, float, float, float }
%struct.ImVec2 = type { float, float }
%struct.ImVector = type { i32, i32, ptr }

; 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 void @_ZN7ImGuiIO17AddInputCharacterEj(ptr noundef nonnull align 8 dereferenceable(14264), i32 noundef) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7ImGuiIO22AddInputCharactersUTF8EPKc(ptr noundef nonnull align 8 dereferenceable(14264) %0, ptr noundef %1) #1 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %struct.ImGuiIO, ptr %6, i32 0, i32 82
  %8 = load i8, ptr %7, align 1, !tbaa !9, !range !17, !noundef !18
  %9 = trunc i8 %8 to i1
  br i1 %9, label %11, label %10

10:                                               ; preds = %2
  br label %28

11:                                               ; preds = %2
  br label %12

12:                                               ; preds = %27, %11
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i8, ptr %13, align 1, !tbaa !19
  %15 = sext i8 %14 to i32
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %28

17:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  store i32 0, ptr %5, align 4, !tbaa !20
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call noundef i32 @_Z18ImTextCharFromUtf8PjPKcS1_(ptr noundef %5, ptr noundef %18, ptr noundef null)
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds i8, ptr %20, i64 %21
  store ptr %22, ptr %4, align 8, !tbaa !5
  %23 = load i32, ptr %5, align 4, !tbaa !20
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %17
  %26 = load i32, ptr %5, align 4, !tbaa !20
  call void @_ZN7ImGuiIO17AddInputCharacterEj(ptr noundef nonnull align 8 dereferenceable(14264) %6, i32 noundef %26)
  br label %27

27:                                               ; preds = %25, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %12, !llvm.loop !21

28:                                               ; preds = %12, %10
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z18ImTextCharFromUtf8PjPKcS1_(ptr noundef, ptr noundef, ptr noundef) #1

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, !14, i64 14241}
!10 = !{!"_ZTS7ImGuiIO", !11, i64 0, !11, i64 4, !12, i64 8, !13, i64 16, !13, i64 20, !6, i64 24, !6, i64 32, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !13, i64 56, !13, i64 60, !13, i64 64, !6, i64 72, !6, i64 80, !13, i64 88, !14, i64 92, !6, i64 96, !12, i64 104, !14, i64 112, !14, i64 113, !14, i64 114, !14, i64 115, !14, i64 116, !14, i64 117, !14, i64 118, !14, i64 119, !13, i64 120, !6, i64 128, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192, !6, i64 200, !14, i64 208, !14, i64 209, !14, i64 210, !14, i64 211, !14, i64 212, !14, i64 213, !14, i64 214, !13, i64 216, !11, i64 220, !11, i64 224, !11, i64 228, !11, i64 232, !11, i64 236, !12, i64 240, !7, i64 248, !7, i64 2856, !7, i64 3508, !12, i64 3572, !7, i64 3580, !13, i64 3588, !13, i64 3592, !14, i64 3596, !14, i64 3597, !14, i64 3598, !14, i64 3599, !11, i64 3600, !7, i64 3604, !14, i64 14036, !12, i64 14040, !7, i64 14048, !7, i64 14088, !7, i64 14128, !7, i64 14133, !7, i64 14138, !7, i64 14148, !7, i64 14158, !7, i64 14163, !7, i64 14168, !7, i64 14176, !7, i64 14196, !7, i64 14216, !13, i64 14236, !14, i64 14240, !14, i64 14241, !7, i64 14242, !14, i64 14243, !15, i64 14244, !16, i64 14248}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTS6ImVec2", !13, i64 0, !13, i64 4}
!13 = !{!"float", !7, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{!"_ZTS8ImVectorItE", !11, i64 0, !11, i64 4, !6, i64 8}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!7, !7, i64 0}
!20 = !{!11, !11, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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 void @_ZN7ImGuiIO17AddInputCharacterEj(ptr noundef nonnull align 8 dereferenceable(14264), i32 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7ImGuiIO22AddInputCharactersUTF8EPKc(ptr noundef nonnull align 8 dereferenceable(14264) %0, ptr noundef %1) local_unnamed_addr #1 align 2 {
  %3 = alloca i32, align 4
  %4 = getelementptr inbounds i8, ptr %0, i64 14241
  %5 = load i8, ptr %4, align 1, !tbaa !5, !range !16, !noundef !17
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %.preheader, label %.loopexit

.preheader:                                       ; preds = %2
  %7 = load i8, ptr %1, align 1, !tbaa !18
  %.not6 = icmp eq i8 %7, 0
  br i1 %.not6, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %13
  %.07 = phi ptr [ %10, %13 ], [ %1, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #2
  store i32 0, ptr %3, align 4, !tbaa !19
  %8 = call noundef i32 @_Z18ImTextCharFromUtf8PjPKcS1_(ptr noundef nonnull %3, ptr noundef nonnull %.07, ptr noundef null)
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds i8, ptr %.07, i64 %9
  %11 = load i32, ptr %3, align 4, !tbaa !19
  %.not5 = icmp eq i32 %11, 0
  br i1 %.not5, label %13, label %12

12:                                               ; preds = %.lr.ph
  call void @_ZN7ImGuiIO17AddInputCharacterEj(ptr noundef nonnull align 8 dereferenceable(14264) %0, i32 noundef %11)
  br label %13

13:                                               ; preds = %12, %.lr.ph
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #2
  %14 = load i8, ptr %10, align 1, !tbaa !18
  %.not = icmp eq i8 %14, 0
  br i1 %.not, label %.loopexit, label %.lr.ph, !llvm.loop !20

.loopexit:                                        ; preds = %13, %.preheader, %2
  ret void
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z18ImTextCharFromUtf8PjPKcS1_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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, !13, i64 14241}
!6 = !{!"_ZTS7ImGuiIO", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !11, i64 20, !12, i64 24, !12, i64 32, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !12, i64 72, !12, i64 80, !11, i64 88, !13, i64 92, !12, i64 96, !10, i64 104, !13, i64 112, !13, i64 113, !13, i64 114, !13, i64 115, !13, i64 116, !13, i64 117, !13, i64 118, !13, i64 119, !11, i64 120, !12, i64 128, !12, i64 136, !12, i64 144, !12, i64 152, !12, i64 160, !12, i64 168, !12, i64 176, !12, i64 184, !12, i64 192, !12, i64 200, !13, i64 208, !13, i64 209, !13, i64 210, !13, i64 211, !13, i64 212, !13, i64 213, !13, i64 214, !11, i64 216, !7, i64 220, !7, i64 224, !7, i64 228, !7, i64 232, !7, i64 236, !10, i64 240, !8, i64 248, !8, i64 2856, !8, i64 3508, !10, i64 3572, !8, i64 3580, !11, i64 3588, !11, i64 3592, !13, i64 3596, !13, i64 3597, !13, i64 3598, !13, i64 3599, !7, i64 3600, !8, i64 3604, !13, i64 14036, !10, i64 14040, !8, i64 14048, !8, i64 14088, !8, i64 14128, !8, i64 14133, !8, i64 14138, !8, i64 14148, !8, i64 14158, !8, i64 14163, !8, i64 14168, !8, i64 14176, !8, i64 14196, !8, i64 14216, !11, i64 14236, !13, i64 14240, !13, i64 14241, !8, i64 14242, !13, i64 14243, !14, i64 14244, !15, i64 14248}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS6ImVec2", !11, i64 0, !11, i64 4}
!11 = !{!"float", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!"bool", !8, i64 0}
!14 = !{!"short", !8, i64 0}
!15 = !{!"_ZTS8ImVectorItE", !7, i64 0, !7, i64 4, !12, i64 8}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = !{!8, !8, i64 0}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass