; LLVM IR from ashishzero/karma :: src/modules/core (stb)

; 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, i32, i32, i32, i32, i32, i32, %struct.stbtt__buf, %struct.stbtt__buf, %struct.stbtt__buf, %struct.stbtt__buf, %struct.stbtt__buf, %struct.stbtt__buf }
%struct.stbtt__buf = type { ptr, i32, i32 }
%struct.stbtt_kerningentry = type { i32, i32, i32 }

; 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
declare hidden noundef zeroext i16 @_ZL8ttUSHORTPh(ptr noundef) #1

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

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

24:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %99

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

31:                                               ; preds = %25
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %99

32:                                               ; preds = %25
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 8
  %35 = call noundef zeroext i16 @_ZL8ttUSHORTPh(ptr noundef %34)
  %36 = zext i16 %35 to i32
  %37 = icmp ne i32 %36, 1
  br i1 %37, label %38, label %39

38:                                               ; preds = %32
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %99

39:                                               ; preds = %32
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds i8, ptr %40, i64 10
  %42 = call noundef zeroext i16 @_ZL8ttUSHORTPh(ptr noundef %41)
  %43 = zext i16 %42 to i32
  store i32 %43, ptr %10, align 4, !tbaa !9
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = load i32, ptr %10, align 4, !tbaa !9
  %46 = icmp slt i32 %44, %45
  br i1 %46, label %47, label %49

47:                                               ; preds = %39
  %48 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %48, ptr %10, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %47, %39
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %50

50:                                               ; preds = %94, %49
  %51 = load i32, ptr %9, align 4, !tbaa !9
  %52 = load i32, ptr %10, align 4, !tbaa !9
  %53 = icmp slt i32 %51, %52
  br i1 %53, label %54, label %97

54:                                               ; preds = %50
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i64 18
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = mul nsw i32 %57, 6
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i8, ptr %56, i64 %59
  %61 = call noundef zeroext i16 @_ZL8ttUSHORTPh(ptr noundef %60)
  %62 = zext i16 %61 to i32
  %63 = load ptr, ptr %6, align 8, !tbaa !5
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds %struct.stbtt_kerningentry, ptr %63, i64 %65
  %67 = getelementptr inbounds %struct.stbtt_kerningentry, ptr %66, i32 0, i32 0
  store i32 %62, ptr %67, align 4, !tbaa !15
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i64 20
  %70 = load i32, ptr %9, align 4, !tbaa !9
  %71 = mul nsw i32 %70, 6
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i8, ptr %69, i64 %72
  %74 = call noundef zeroext i16 @_ZL8ttUSHORTPh(ptr noundef %73)
  %75 = zext i16 %74 to i32
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds %struct.stbtt_kerningentry, ptr %76, i64 %78
  %80 = getelementptr inbounds %struct.stbtt_kerningentry, ptr %79, i32 0, i32 1
  store i32 %75, ptr %80, align 4, !tbaa !17
  %81 = load ptr, ptr %8, align 8, !tbaa !5
  %82 = getelementptr inbounds i8, ptr %81, i64 22
  %83 = load i32, ptr %9, align 4, !tbaa !9
  %84 = mul nsw i32 %83, 6
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds i8, ptr %82, i64 %85
  %87 = call noundef signext i16 @_ZL7ttSHORTPh(ptr noundef %86)
  %88 = sext i16 %87 to i32
  %89 = load ptr, ptr %6, align 8, !tbaa !5
  %90 = load i32, ptr %9, align 4, !tbaa !9
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds %struct.stbtt_kerningentry, ptr %89, i64 %91
  %93 = getelementptr inbounds %struct.stbtt_kerningentry, ptr %92, i32 0, i32 2
  store i32 %88, ptr %93, align 4, !tbaa !18
  br label %94

94:                                               ; preds = %54
  %95 = load i32, ptr %9, align 4, !tbaa !9
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %9, align 4, !tbaa !9
  br label %50, !llvm.loop !19

97:                                               ; preds = %50
  %98 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %98, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %99

99:                                               ; preds = %97, %38, %31, %24
  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
  %100 = load i32, ptr %4, align 4
  ret i32 %100
}

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 = { 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, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !13, i64 80, !13, i64 96, !13, i64 112, !13, i64 128, !13, i64 144, !13, i64 160}
!13 = !{!"_ZTS10stbtt__buf", !6, i64 0, !10, i64 8, !10, i64 12}
!14 = !{!12, !10, i64 44}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTS18stbtt_kerningentry", !10, i64 0, !10, i64 4, !10, i64 8}
!17 = !{!16, !10, i64 4}
!18 = !{!16, !10, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"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"

%struct.stbtt_kerningentry = type { i32, i32, i32 }

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

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @stbtt_GetKerningTable(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %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 !12
  %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 @_ZL8ttUSHORTPh(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 @_ZL8ttUSHORTPh(ptr noundef nonnull %15)
  %.not29 = icmp eq i16 %16, 1
  br i1 %.not29, label %17, label %.loopexit

17:                                               ; preds = %14
  %18 = getelementptr inbounds i8, ptr %9, i64 10
  %19 = tail call noundef zeroext i16 @_ZL8ttUSHORTPh(ptr noundef nonnull %18)
  %20 = zext i16 %19 to i32
  %spec.select = tail call i32 @llvm.smin.i32(i32 %20, i32 %2)
  %21 = icmp sgt i32 %spec.select, 0
  br i1 %21, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %17
  %22 = getelementptr inbounds i8, ptr %9, i64 18
  %23 = getelementptr inbounds i8, ptr %9, i64 20
  %24 = getelementptr inbounds i8, ptr %9, i64 22
  %wide.trip.count = zext nneg i32 %spec.select to i64
  br label %25

25:                                               ; preds = %.lr.ph, %25
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %25 ]
  %26 = mul nuw nsw i64 %indvars.iv, 6
  %27 = getelementptr inbounds i8, ptr %22, i64 %26
  %28 = tail call noundef zeroext i16 @_ZL8ttUSHORTPh(ptr noundef nonnull %27)
  %29 = zext i16 %28 to i32
  %30 = getelementptr inbounds %struct.stbtt_kerningentry, ptr %1, i64 %indvars.iv
  store i32 %29, ptr %30, align 4, !tbaa !13
  %31 = getelementptr inbounds i8, ptr %23, i64 %26
  %32 = tail call noundef zeroext i16 @_ZL8ttUSHORTPh(ptr noundef nonnull %31)
  %33 = zext i16 %32 to i32
  %34 = getelementptr inbounds i8, ptr %30, i64 4
  store i32 %33, ptr %34, align 4, !tbaa !15
  %35 = getelementptr inbounds i8, ptr %24, i64 %26
  %36 = tail call noundef signext i16 @_ZL7ttSHORTPh(ptr noundef nonnull %35)
  %37 = sext i16 %36 to i32
  %38 = getelementptr inbounds i8, ptr %30, i64 8
  store i32 %37, ptr %38, align 4, !tbaa !16
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %25, !llvm.loop !17

.loopexit:                                        ; preds = %25, %17, %14, %10, %3
  %.026 = phi i32 [ 0, %3 ], [ 0, %10 ], [ 0, %14 ], [ %spec.select, %17 ], [ %spec.select, %25 ]
  ret i32 %.026
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

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 speculatable willreturn memory(none) }

!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, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !11, i64 80, !11, i64 96, !11, i64 112, !11, i64 128, !11, i64 144, !11, i64 160}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"_ZTS10stbtt__buf", !7, i64 0, !10, i64 8, !10, i64 12}
!12 = !{!6, !10, i64 44}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS18stbtt_kerningentry", !10, i64 0, !10, i64 4, !10, i64 8}
!15 = !{!14, !10, i64 4}
!16 = !{!14, !10, i64 8}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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