; LLVM IR from erwincoumans/tiny-differentiable-simulator :: src/visualizer/opengl (tiny_font_stash)

; 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.stbtt_fontinfo = type { ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i32 @_ZL7ttULONGPKh(ptr noundef) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i16 @_ZL8ttUSHORTPKh(ptr noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef signext i16 @_ZL7ttSHORTPKh(ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local i32 @stbtt_GetGlyphKernAdvance(ptr noundef %0, i32 noundef %1, i32 noundef %2) #2 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.stbtt_fontinfo, ptr %15, i32 0, i32 1
  %17 = load ptr, ptr %16, align 8, !tbaa !11
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.stbtt_fontinfo, ptr %18, i32 0, i32 9
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %17, i64 %21
  store ptr %22, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.stbtt_fontinfo, ptr %23, i32 0, i32 9
  %25 = load i32, ptr %24, align 4, !tbaa !13
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %28, label %27

27:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %93

28:                                               ; preds = %3
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds i8, ptr %29, i64 2
  %31 = call noundef zeroext i16 @_ZL8ttUSHORTPKh(ptr noundef %30)
  %32 = zext i16 %31 to i32
  %33 = icmp slt i32 %32, 1
  br i1 %33, label %34, label %35

34:                                               ; preds = %28
  store i32 0, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %93

35:                                               ; preds = %28
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = getelementptr inbounds i8, ptr %36, i64 8
  %38 = call noundef zeroext i16 @_ZL8ttUSHORTPKh(ptr noundef %37)
  %39 = zext i16 %38 to i32
  %40 = icmp ne i32 %39, 1
  br i1 %40, label %41, label %42

41:                                               ; preds = %35
  store i32 0, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %93

42:                                               ; preds = %35
  store i32 0, ptr %11, align 4, !tbaa !9
  %43 = load ptr, ptr %8, align 8, !tbaa !5
  %44 = getelementptr inbounds i8, ptr %43, i64 10
  %45 = call noundef zeroext i16 @_ZL8ttUSHORTPKh(ptr noundef %44)
  %46 = zext i16 %45 to i32
  %47 = sub nsw i32 %46, 1
  store i32 %47, ptr %12, align 4, !tbaa !9
  %48 = load i32, ptr %6, align 4, !tbaa !9
  %49 = shl i32 %48, 16
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = or i32 %49, %50
  store i32 %51, ptr %9, align 4, !tbaa !9
  br label %52

52:                                               ; preds = %91, %42
  %53 = load i32, ptr %11, align 4, !tbaa !9
  %54 = load i32, ptr %12, align 4, !tbaa !9
  %55 = icmp sle i32 %53, %54
  br i1 %55, label %56, label %92

56:                                               ; preds = %52
  %57 = load i32, ptr %11, align 4, !tbaa !9
  %58 = load i32, ptr %12, align 4, !tbaa !9
  %59 = add nsw i32 %57, %58
  %60 = ashr i32 %59, 1
  store i32 %60, ptr %13, align 4, !tbaa !9
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i64 18
  %63 = load i32, ptr %13, align 4, !tbaa !9
  %64 = mul nsw i32 %63, 6
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds i8, ptr %62, i64 %65
  %67 = call noundef i32 @_ZL7ttULONGPKh(ptr noundef %66)
  store i32 %67, ptr %10, align 4, !tbaa !9
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = icmp ult i32 %68, %69
  br i1 %70, label %71, label %74

71:                                               ; preds = %56
  %72 = load i32, ptr %13, align 4, !tbaa !9
  %73 = sub nsw i32 %72, 1
  store i32 %73, ptr %12, align 4, !tbaa !9
  br label %91

74:                                               ; preds = %56
  %75 = load i32, ptr %9, align 4, !tbaa !9
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = icmp ugt i32 %75, %76
  br i1 %77, label %78, label %81

78:                                               ; preds = %74
  %79 = load i32, ptr %13, align 4, !tbaa !9
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %11, align 4, !tbaa !9
  br label %90

81:                                               ; preds = %74
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = getelementptr inbounds i8, ptr %82, i64 22
  %84 = load i32, ptr %13, align 4, !tbaa !9
  %85 = mul nsw i32 %84, 6
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds i8, ptr %83, i64 %86
  %88 = call noundef signext i16 @_ZL7ttSHORTPKh(ptr noundef %87)
  %89 = sext i16 %88 to i32
  store i32 %89, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %93

90:                                               ; preds = %78
  br label %91

91:                                               ; preds = %90, %71
  br label %52, !llvm.loop !14

92:                                               ; preds = %52
  store i32 0, ptr %4, align 4
  store i32 1, ptr %14, align 4
  br label %93

93:                                               ; preds = %92, %81, %41, %34, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %94 = load i32, ptr %4, align 4
  ret i32 %94
}

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 8}
!12 = !{!"_ZTS14stbtt_fontinfo", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!13 = !{!12, !10, i64 44}
!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 nounwind uwtable
declare hidden noundef i32 @_ZL7ttULONGPKh(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i16 @_ZL8ttUSHORTPKh(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef signext i16 @_ZL7ttSHORTPKh(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local range(i32 -32768, 32768) i32 @stbtt_GetGlyphKernAdvance(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 44
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds i8, ptr %5, i64 %8
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %.loopexit, label %10

10:                                               ; preds = %3
  %11 = getelementptr inbounds i8, ptr %9, i64 2
  %12 = tail call noundef zeroext i16 @_ZL8ttUSHORTPKh(ptr noundef nonnull %11)
  %13 = icmp eq i16 %12, 0
  br i1 %13, label %.loopexit, label %14

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %9, i64 8
  %16 = tail call noundef zeroext i16 @_ZL8ttUSHORTPKh(ptr noundef nonnull %15)
  %.not27 = icmp eq i16 %16, 1
  br i1 %.not27, label %17, label %.loopexit

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %9, i64 10
  %19 = tail call noundef zeroext i16 @_ZL8ttUSHORTPKh(ptr noundef nonnull %18)
  %20 = shl i32 %1, 16
  %21 = or i32 %20, %2
  %.not2829 = icmp eq i16 %19, 0
  br i1 %.not2829, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %17
  %22 = zext i16 %19 to i32
  %23 = add nsw i32 %22, -1
  %24 = getelementptr inbounds i8, ptr %9, i64 18
  br label %25

25:                                               ; preds = %.lr.ph, %44
  %.02231 = phi i32 [ %23, %.lr.ph ], [ %.1, %44 ]
  %.02330 = phi i32 [ 0, %.lr.ph ], [ %.124, %44 ]
  %26 = add nsw i32 %.02231, %.02330
  %27 = ashr i32 %26, 1
  %28 = mul nsw i32 %27, 6
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i8, ptr %24, i64 %29
  %31 = tail call noundef i32 @_ZL7ttULONGPKh(ptr noundef nonnull %30)
  %32 = icmp ult i32 %21, %31
  br i1 %32, label %33, label %35

33:                                               ; preds = %25
  %34 = add nsw i32 %27, -1
  br label %44

35:                                               ; preds = %25
  %36 = icmp ugt i32 %21, %31
  br i1 %36, label %37, label %39

37:                                               ; preds = %35
  %38 = add nsw i32 %27, 1
  br label %44

39:                                               ; preds = %35
  %40 = getelementptr inbounds i8, ptr %9, i64 22
  %41 = getelementptr inbounds i8, ptr %40, i64 %29
  %42 = tail call noundef signext i16 @_ZL7ttSHORTPKh(ptr noundef nonnull %41)
  %43 = sext i16 %42 to i32
  br label %.loopexit

44:                                               ; preds = %37, %33
  %.124 = phi i32 [ %.02330, %33 ], [ %38, %37 ]
  %.1 = phi i32 [ %34, %33 ], [ %.02231, %37 ]
  %.not28 = icmp sgt i32 %.124, %.1
  br i1 %.not28, label %.loopexit, label %25, !llvm.loop !12

.loopexit:                                        ; preds = %44, %17, %14, %10, %3, %39
  %.0 = phi i32 [ %43, %39 ], [ 0, %3 ], [ 0, %10 ], [ 0, %14 ], [ 0, %17 ], [ 0, %44 ]
  ret i32 %.0
}

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

!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, !7, i64 8}
!6 = !{!"_ZTS14stbtt_fontinfo", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 44}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass