; LLVM IR from caryll/otfcc :: lib/table/otl/subtables (gpos-cursive)

; 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.__otfcc_ICoverage = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.otfcc_HandlePackage = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.otfcc_Handle = type { i32, i16, ptr }
%struct.subtable_gpos_cursive = type { i64, i64, ptr }
%struct.otl_GposCursiveEntry = type { %struct.otfcc_Handle, %struct.otl_Anchor, %struct.otl_Anchor }
%struct.otl_Anchor = type { i8, double, double }

@otl_iCoverage = external constant %struct.__otfcc_ICoverage, align 8
@otfcc_iHandle = external constant %struct.otfcc_HandlePackage, align 8

; 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: nounwind uwtable
define dso_local ptr @otfcc_build_gpos_cursive(ptr noundef %0, i32 noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca %struct.otfcc_Handle, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i16, align 2
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %11, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %12 = load ptr, ptr getelementptr inbounds (%struct.__otfcc_ICoverage, ptr @otl_iCoverage, i32 0, i32 6), align 8, !tbaa !11
  %13 = call ptr (...) %12()
  store ptr %13, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #3
  store i16 0, ptr %7, align 2, !tbaa !13
  br label %14

14:                                               ; preds = %46, %2
  %15 = load i16, ptr %7, align 2, !tbaa !13
  %16 = zext i16 %15 to i64
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.subtable_gpos_cursive, ptr %17, i32 0, i32 0
  %19 = load i64, ptr %18, align 8, !tbaa !15
  %20 = icmp ult i64 %16, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %14
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #3
  br label %49

22:                                               ; preds = %14
  %23 = load ptr, ptr getelementptr inbounds (%struct.__otfcc_ICoverage, ptr @otl_iCoverage, i32 0, i32 15), align 8, !tbaa !18
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = load ptr, ptr getelementptr inbounds (%struct.otfcc_HandlePackage, ptr @otfcc_iHandle, i32 0, i32 7), align 8, !tbaa !19
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.subtable_gpos_cursive, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !21
  %29 = load i16, ptr %7, align 2, !tbaa !13
  %30 = zext i16 %29 to i64
  %31 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %28, i64 %30
  %32 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds { i64, ptr }, ptr %32, i32 0, i32 0
  %34 = load i64, ptr %33, align 8
  %35 = getelementptr inbounds { i64, ptr }, ptr %32, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8
  %37 = call { i64, ptr } %25(i64 %34, ptr %36)
  %38 = getelementptr inbounds { i64, ptr }, ptr %8, i32 0, i32 0
  %39 = extractvalue { i64, ptr } %37, 0
  store i64 %39, ptr %38, align 8
  %40 = getelementptr inbounds { i64, ptr }, ptr %8, i32 0, i32 1
  %41 = extractvalue { i64, ptr } %37, 1
  store ptr %41, ptr %40, align 8
  %42 = getelementptr inbounds { i64, ptr }, ptr %8, i32 0, i32 0
  %43 = load i64, ptr %42, align 8
  %44 = getelementptr inbounds { i64, ptr }, ptr %8, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8
  call void %23(ptr noundef %24, i64 %43, ptr %45)
  br label %46

46:                                               ; preds = %22
  %47 = load i16, ptr %7, align 2, !tbaa !13
  %48 = add i16 %47, 1
  store i16 %48, ptr %7, align 2, !tbaa !13
  br label %14, !llvm.loop !22

49:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %50 = load ptr, ptr getelementptr inbounds (%struct.__otfcc_ICoverage, ptr @otl_iCoverage, i32 0, i32 12), align 8, !tbaa !24
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = call ptr %50(ptr noundef %51)
  %53 = call ptr @bk_newBlockFromBuffer(ptr noundef %52)
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.subtable_gpos_cursive, ptr %54, i32 0, i32 0
  %56 = load i64, ptr %55, align 8, !tbaa !15
  %57 = call ptr (i32, ...) @bk_new_Block(i32 noundef 2, i32 noundef 1, i32 noundef 16, ptr noundef %53, i32 noundef 2, i64 noundef %56, i32 noundef 0)
  store ptr %57, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  store i16 0, ptr %10, align 2, !tbaa !13
  br label %58

58:                                               ; preds = %85, %49
  %59 = load i16, ptr %10, align 2, !tbaa !13
  %60 = zext i16 %59 to i64
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.subtable_gpos_cursive, ptr %61, i32 0, i32 0
  %63 = load i64, ptr %62, align 8, !tbaa !15
  %64 = icmp ult i64 %60, %63
  br i1 %64, label %66, label %65

65:                                               ; preds = %58
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  br label %88

66:                                               ; preds = %58
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.subtable_gpos_cursive, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !21
  %71 = load i16, ptr %10, align 2, !tbaa !13
  %72 = zext i16 %71 to i64
  %73 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %70, i64 %72
  %74 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %73, i32 0, i32 1
  %75 = call ptr @bkFromAnchor(ptr noundef byval(%struct.otl_Anchor) align 8 %74)
  %76 = load ptr, ptr %5, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.subtable_gpos_cursive, ptr %76, i32 0, i32 2
  %78 = load ptr, ptr %77, align 8, !tbaa !21
  %79 = load i16, ptr %10, align 2, !tbaa !13
  %80 = zext i16 %79 to i64
  %81 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %78, i64 %80
  %82 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %81, i32 0, i32 2
  %83 = call ptr @bkFromAnchor(ptr noundef byval(%struct.otl_Anchor) align 8 %82)
  %84 = call ptr (ptr, i32, ...) @bk_push(ptr noundef %67, i32 noundef 16, ptr noundef %75, i32 noundef 16, ptr noundef %83, i32 noundef 0)
  br label %85

85:                                               ; preds = %66
  %86 = load i16, ptr %10, align 2, !tbaa !13
  %87 = add i16 %86, 1
  store i16 %87, ptr %10, align 2, !tbaa !13
  br label %58, !llvm.loop !25

88:                                               ; preds = %65
  %89 = load ptr, ptr getelementptr inbounds (%struct.__otfcc_ICoverage, ptr @otl_iCoverage, i32 0, i32 7), align 8, !tbaa !26
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  call void %89(ptr noundef %90)
  %91 = load ptr, ptr %9, align 8, !tbaa !5
  %92 = call ptr @bk_build_Block(ptr noundef %91)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %92
}

declare ptr @bk_new_Block(i32 noundef, ...) #2

declare ptr @bk_newBlockFromBuffer(ptr noundef) #2

declare ptr @bk_push(ptr noundef, i32 noundef, ...) #2

declare ptr @bkFromAnchor(ptr noundef byval(%struct.otl_Anchor) align 8) #2

declare ptr @bk_build_Block(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 48}
!12 = !{!"__otfcc_ICoverage", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !17, i64 0}
!16 = !{!"", !17, i64 0, !17, i64 8, !6, i64 16}
!17 = !{!"long", !7, i64 0}
!18 = !{!12, !6, i64 120}
!19 = !{!20, !6, i64 56}
!20 = !{!"otfcc_HandlePackage", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88}
!21 = !{!16, !6, i64 16}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}
!24 = !{!12, !6, i64 96}
!25 = distinct !{!25, !23}
!26 = !{!12, !6, i64 56}


; 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.__otfcc_ICoverage = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.otfcc_HandlePackage = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.otl_GposCursiveEntry = type { %struct.otfcc_Handle, %struct.otl_Anchor, %struct.otl_Anchor }
%struct.otfcc_Handle = type { i32, i16, ptr }
%struct.otl_Anchor = type { i8, double, double }

@otl_iCoverage = external local_unnamed_addr constant %struct.__otfcc_ICoverage, align 8
@otfcc_iHandle = external local_unnamed_addr constant %struct.otfcc_HandlePackage, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @otfcc_build_gpos_cursive(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr getelementptr inbounds (i8, ptr @otl_iCoverage, i64 48), align 8, !tbaa !5
  %4 = tail call ptr (...) %3() #2
  %5 = load i64, ptr %0, align 8, !tbaa !10
  %.not = icmp eq i64 %5, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %6 = load ptr, ptr getelementptr inbounds (i8, ptr @otl_iCoverage, i64 120), align 8, !tbaa !13
  %7 = load ptr, ptr getelementptr inbounds (i8, ptr @otfcc_iHandle, i64 56), align 8, !tbaa !14
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  br label %16

._crit_edge:                                      ; preds = %16, %2
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @otl_iCoverage, i64 96), align 8, !tbaa !16
  %10 = tail call ptr %9(ptr noundef %4) #2
  %11 = tail call ptr @bk_newBlockFromBuffer(ptr noundef %10) #2
  %12 = load i64, ptr %0, align 8, !tbaa !10
  %13 = tail call ptr (i32, ...) @bk_new_Block(i32 noundef 2, i32 noundef 1, i32 noundef 16, ptr noundef %11, i32 noundef 2, i64 noundef %12, i32 noundef 0) #2
  %14 = load i64, ptr %0, align 8, !tbaa !10
  %.not26 = icmp eq i64 %14, 0
  br i1 %.not26, label %._crit_edge25, label %.lr.ph24

.lr.ph24:                                         ; preds = %._crit_edge
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  br label %32

16:                                               ; preds = %.lr.ph, %16
  %17 = phi i64 [ 0, %.lr.ph ], [ %27, %16 ]
  %.01821 = phi i16 [ 0, %.lr.ph ], [ %26, %16 ]
  %18 = load ptr, ptr %8, align 8, !tbaa !17
  %19 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %18, i64 %17
  %20 = load i64, ptr %19, align 8
  %21 = getelementptr inbounds i8, ptr %19, i64 8
  %22 = load ptr, ptr %21, align 8
  %23 = tail call { i64, ptr } %7(i64 %20, ptr %22) #2
  %24 = extractvalue { i64, ptr } %23, 0
  %25 = extractvalue { i64, ptr } %23, 1
  tail call void %6(ptr noundef %4, i64 %24, ptr %25) #2
  %26 = add i16 %.01821, 1
  %27 = zext i16 %26 to i64
  %28 = load i64, ptr %0, align 8, !tbaa !10
  %29 = icmp ugt i64 %28, %27
  br i1 %29, label %16, label %._crit_edge, !llvm.loop !18

._crit_edge25:                                    ; preds = %32, %._crit_edge
  %30 = load ptr, ptr getelementptr inbounds (i8, ptr @otl_iCoverage, i64 56), align 8, !tbaa !20
  tail call void %30(ptr noundef %4) #2
  %31 = tail call ptr @bk_build_Block(ptr noundef %13) #2
  ret ptr %31

32:                                               ; preds = %.lr.ph24, %32
  %33 = phi i64 [ 0, %.lr.ph24 ], [ %42, %32 ]
  %.022 = phi i16 [ 0, %.lr.ph24 ], [ %41, %32 ]
  %34 = load ptr, ptr %15, align 8, !tbaa !17
  %35 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %34, i64 %33, i32 1
  %36 = tail call ptr @bkFromAnchor(ptr noundef nonnull byval(%struct.otl_Anchor) align 8 %35) #2
  %37 = load ptr, ptr %15, align 8, !tbaa !17
  %38 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %37, i64 %33, i32 2
  %39 = tail call ptr @bkFromAnchor(ptr noundef nonnull byval(%struct.otl_Anchor) align 8 %38) #2
  %40 = tail call ptr (ptr, i32, ...) @bk_push(ptr noundef %13, i32 noundef 16, ptr noundef %36, i32 noundef 16, ptr noundef %39, i32 noundef 0) #2
  %41 = add i16 %.022, 1
  %42 = zext i16 %41 to i64
  %43 = load i64, ptr %0, align 8, !tbaa !10
  %44 = icmp ugt i64 %43, %42
  br i1 %44, label %32, label %._crit_edge25, !llvm.loop !21
}

declare ptr @bk_new_Block(i32 noundef, ...) local_unnamed_addr #1

declare ptr @bk_newBlockFromBuffer(ptr noundef) local_unnamed_addr #1

declare ptr @bk_push(ptr noundef, i32 noundef, ...) local_unnamed_addr #1

declare ptr @bkFromAnchor(ptr noundef byval(%struct.otl_Anchor) align 8) local_unnamed_addr #1

declare ptr @bk_build_Block(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 = { "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, !7, i64 48}
!6 = !{!"__otfcc_ICoverage", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !7, i64 120}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"", !12, i64 0, !12, i64 8, !7, i64 16}
!12 = !{!"long", !8, i64 0}
!13 = !{!6, !7, i64 120}
!14 = !{!15, !7, i64 56}
!15 = !{!"otfcc_HandlePackage", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88}
!16 = !{!6, !7, i64 96}
!17 = !{!11, !7, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!6, !7, i64 56}
!21 = distinct !{!21, !19}


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