; LLVM IR from theolundqvist/parallax-voxel-ray-marcher :: src/external/Dear ImGui/imgui_draw.ll (ZN24ImFontGlyphRangesBuilder9AddRangesEPKt)

; 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: inlinehint mustprogress uwtable
declare dso_local void @_ZN24ImFontGlyphRangesBuilder7AddCharEt(ptr noundef nonnull align 8 dereferenceable(16), i16 noundef zeroext) #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN24ImFontGlyphRangesBuilder9AddRangesEPKt(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1) #2 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  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
  br label %7

7:                                                ; preds = %31, %2
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = getelementptr inbounds i16, ptr %8, i64 0
  %10 = load i16, ptr %9, align 2, !tbaa !9
  %11 = icmp ne i16 %10, 0
  br i1 %11, label %12, label %34

12:                                               ; preds = %7
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds i16, ptr %13, i64 0
  %15 = load i16, ptr %14, align 2, !tbaa !9
  store i16 %15, ptr %5, align 2, !tbaa !9
  br label %16

16:                                               ; preds = %27, %12
  %17 = load i16, ptr %5, align 2, !tbaa !9
  %18 = zext i16 %17 to i32
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds i16, ptr %19, i64 1
  %21 = load i16, ptr %20, align 2, !tbaa !9
  %22 = zext i16 %21 to i32
  %23 = icmp sle i32 %18, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #3
  br label %30

25:                                               ; preds = %16
  %26 = load i16, ptr %5, align 2, !tbaa !9
  call void @_ZN24ImFontGlyphRangesBuilder7AddCharEt(ptr noundef nonnull align 8 dereferenceable(16) %6, i16 noundef zeroext %26)
  br label %27

27:                                               ; preds = %25
  %28 = load i16, ptr %5, align 2, !tbaa !9
  %29 = add i16 %28, 1
  store i16 %29, ptr %5, align 2, !tbaa !9
  br label %16, !llvm.loop !11

30:                                               ; preds = %24
  br label %31

31:                                               ; preds = %30
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds i16, ptr %32, i64 2
  store ptr %33, ptr %4, align 8, !tbaa !5
  br label %7, !llvm.loop !13

34:                                               ; preds = %7
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 = !{!"short", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; 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: inlinehint mustprogress uwtable
declare dso_local void @_ZN24ImFontGlyphRangesBuilder7AddCharEt(ptr noundef nonnull align 8 dereferenceable(16), i16 noundef zeroext) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN24ImFontGlyphRangesBuilder9AddRangesEPKt(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr nocapture noundef readonly %1) local_unnamed_addr #1 align 2 {
  %3 = load i16, ptr %1, align 2, !tbaa !5
  %.not12 = icmp eq i16 %3, 0
  br i1 %.not12, label %._crit_edge14, label %.preheader

.preheader:                                       ; preds = %2, %._crit_edge
  %4 = phi i16 [ %8, %._crit_edge ], [ %3, %2 ]
  %.0713 = phi ptr [ %7, %._crit_edge ], [ %1, %2 ]
  %5 = getelementptr inbounds i8, ptr %.0713, i64 2
  %6 = load i16, ptr %5, align 2, !tbaa !5
  %.not910 = icmp ugt i16 %4, %6
  br i1 %.not910, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %7 = getelementptr inbounds i8, ptr %.0713, i64 4
  %8 = load i16, ptr %7, align 2, !tbaa !5
  %.not = icmp eq i16 %8, 0
  br i1 %.not, label %._crit_edge14, label %.preheader, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.011 = phi i16 [ %9, %.lr.ph ], [ %4, %.preheader ]
  tail call void @_ZN24ImFontGlyphRangesBuilder7AddCharEt(ptr noundef nonnull align 8 dereferenceable(16) %0, i16 noundef zeroext %.011)
  %9 = add i16 %.011, 1
  %10 = load i16, ptr %5, align 2, !tbaa !5
  %.not9 = icmp ugt i16 %9, %10
  br i1 %.not9, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge14:                                    ; preds = %._crit_edge, %2
  ret void
}

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

!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"}
!11 = distinct !{!11, !10}


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