; LLVM IR from DarrenSweeney/3D-Physics-Engine :: Physics Engine/Imgui/imgui.ll (ZN11ImFontAtlas22GetGlyphRangesJapaneseEv)

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

@_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE19offsets_from_0x4E00 = external hidden constant [1946 x i16], align 16
@_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE15ranges_unpacked = external hidden global i32, align 4
@_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE6ranges = external hidden global <{ [10 x i16], [3893 x i16] }>, align 16

; 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 nounwind uwtable
define dso_local noundef ptr @_ZN11ImFontAtlas22GetGlyphRangesJapaneseEv(ptr noundef nonnull align 8 dereferenceable(96) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  %7 = load i32, ptr @_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE15ranges_unpacked, align 4, !tbaa !9
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %36, label %9

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 19968, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  store ptr getelementptr inbounds ([3903 x i16], ptr @_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE6ranges, i64 0, i64 10), 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 %10

10:                                               ; preds = %28, %9
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 1946
  br i1 %12, label %14, label %13

13:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  br label %33

14:                                               ; preds = %10
  %15 = load i32, ptr %5, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [1946 x i16], ptr @_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE19offsets_from_0x4E00, i64 0, i64 %16
  %18 = load i16, ptr %17, align 2, !tbaa !11
  %19 = sext i16 %18 to i32
  %20 = add nsw i32 %19, 1
  %21 = load i32, ptr %3, align 4, !tbaa !9
  %22 = add nsw i32 %21, %20
  store i32 %22, ptr %3, align 4, !tbaa !9
  %23 = trunc i32 %22 to i16
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds i16, ptr %24, i64 1
  store i16 %23, ptr %25, align 2, !tbaa !11
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds i16, ptr %26, i64 0
  store i16 %23, ptr %27, align 2, !tbaa !11
  br label %28

28:                                               ; preds = %14
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %5, align 4, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds i16, ptr %31, i64 2
  store ptr %32, ptr %4, align 8, !tbaa !5
  br label %10, !llvm.loop !13

33:                                               ; preds = %13
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds i16, ptr %34, i64 0
  store i16 0, ptr %35, align 2, !tbaa !11
  store i32 1, ptr @_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE15ranges_unpacked, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  br label %36

36:                                               ; preds = %33, %1
  ret ptr @_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE6ranges
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!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"

@_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE19offsets_from_0x4E00 = external hidden local_unnamed_addr constant [1946 x i16], align 16
@_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE15ranges_unpacked = external hidden local_unnamed_addr global i32, align 4
@_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE6ranges = external hidden global <{ [10 x i16], [3893 x i16] }>, align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: write, inaccessiblemem: none) uwtable
define dso_local noundef nonnull ptr @_ZN11ImFontAtlas22GetGlyphRangesJapaneseEv(ptr nocapture noundef nonnull readnone align 8 dereferenceable(96) %0) local_unnamed_addr #0 align 2 {
  %2 = load i32, ptr @_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE15ranges_unpacked, align 4, !tbaa !5
  %.not = icmp eq i32 %2, 0
  br i1 %.not, label %.preheader, label %16

3:                                                ; preds = %.preheader
  store i16 0, ptr %15, align 2, !tbaa !9
  store i32 1, ptr @_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE15ranges_unpacked, align 4, !tbaa !5
  br label %16

.preheader:                                       ; preds = %1, %.preheader
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.preheader ], [ 0, %1 ]
  %.0811 = phi ptr [ %15, %.preheader ], [ getelementptr inbounds (i8, ptr @_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE6ranges, i64 20), %1 ]
  %.0910 = phi i16 [ %13, %.preheader ], [ 19968, %1 ]
  %4 = getelementptr inbounds [1946 x i16], ptr @_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE19offsets_from_0x4E00, i64 0, i64 %indvars.iv
  %5 = load i16, ptr %4, align 4, !tbaa !9
  %6 = add i16 %.0910, 1
  %7 = add i16 %6, %5
  %8 = getelementptr inbounds i8, ptr %.0811, i64 2
  store i16 %7, ptr %8, align 2, !tbaa !9
  store i16 %7, ptr %.0811, align 2, !tbaa !9
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %9 = getelementptr inbounds i8, ptr %.0811, i64 4
  %10 = getelementptr inbounds [1946 x i16], ptr @_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE19offsets_from_0x4E00, i64 0, i64 %indvars.iv.next
  %11 = load i16, ptr %10, align 2, !tbaa !9
  %12 = add i16 %7, 1
  %13 = add i16 %12, %11
  %14 = getelementptr inbounds i8, ptr %.0811, i64 6
  store i16 %13, ptr %14, align 2, !tbaa !9
  store i16 %13, ptr %9, align 2, !tbaa !9
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %15 = getelementptr inbounds i8, ptr %.0811, i64 8
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 1946
  br i1 %exitcond.not.1, label %3, label %.preheader, !llvm.loop !11

16:                                               ; preds = %3, %1
  ret ptr @_ZZN11ImFontAtlas22GetGlyphRangesJapaneseEvE6ranges
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind memory(readwrite, argmem: write, inaccessiblemem: none) 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 = !{!"int", !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"}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass