; LLVM IR from caryll/otfcc :: lib/table/otl/subtables/chaining (build)

; 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.subtable_chaining = type { i32, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { i16, ptr, ptr, ptr, ptr }
%struct.otl_ChainingRule = type { i16, i16, i16, ptr, i16, ptr }
%struct.otl_ChainLookupApplication = type { i16, %struct.otfcc_Handle }
%struct.otfcc_Handle = type { i32, i16, ptr }

@otl_iCoverage = external constant %struct.__otfcc_ICoverage, 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: inlinehint nounwind uwtable
declare hidden void @reverseBacktracks(ptr noundef) #1

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

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

declare ptr @bk_newBlockFromBuffer(ptr noundef) #2

declare ptr @bk_build_Block(ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @otfcc_build_contextual_coverage(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca ptr, align 8
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %10, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.subtable_chaining, ptr %11, i32 0, i32 1
  store ptr %12, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #4
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.otl_ChainingRule, ptr %13, i32 0, i32 2
  %15 = load i16, ptr %14, align 4, !tbaa !9
  %16 = zext i16 %15 to i32
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.otl_ChainingRule, ptr %17, i32 0, i32 1
  %19 = load i16, ptr %18, align 2, !tbaa !12
  %20 = zext i16 %19 to i32
  %21 = sub nsw i32 %16, %20
  %22 = trunc i32 %21 to i16
  store i16 %22, ptr %5, align 2, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #4
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.otl_ChainingRule, ptr %23, i32 0, i32 4
  %25 = load i16, ptr %24, align 8, !tbaa !14
  store i16 %25, ptr %6, align 2, !tbaa !13
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  call void @reverseBacktracks(ptr noundef %26)
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %27 = call ptr (i32, ...) @bk_new_Block(i32 noundef 2, i32 noundef 3, i32 noundef 0)
  store ptr %27, ptr %7, align 8, !tbaa !5
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = load i16, ptr %5, align 2, !tbaa !13
  %30 = zext i16 %29 to i32
  %31 = call ptr (ptr, i32, ...) @bk_push(ptr noundef %28, i32 noundef 2, i32 noundef %30, i32 noundef 0)
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i16, ptr %6, align 2, !tbaa !13
  %34 = zext i16 %33 to i32
  %35 = call ptr (ptr, i32, ...) @bk_push(ptr noundef %32, i32 noundef 2, i32 noundef %34, i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #4
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.otl_ChainingRule, ptr %36, i32 0, i32 1
  %38 = load i16, ptr %37, align 2, !tbaa !12
  store i16 %38, ptr %8, align 2, !tbaa !13
  br label %39

39:                                               ; preds = %61, %1
  %40 = load i16, ptr %8, align 2, !tbaa !13
  %41 = zext i16 %40 to i32
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.otl_ChainingRule, ptr %42, i32 0, i32 2
  %44 = load i16, ptr %43, align 4, !tbaa !9
  %45 = zext i16 %44 to i32
  %46 = icmp slt i32 %41, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %39
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #4
  br label %64

48:                                               ; preds = %39
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load ptr, ptr getelementptr inbounds (%struct.__otfcc_ICoverage, ptr @otl_iCoverage, i32 0, i32 12), align 8, !tbaa !15
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.otl_ChainingRule, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !17
  %54 = load i16, ptr %8, align 2, !tbaa !13
  %55 = zext i16 %54 to i64
  %56 = getelementptr inbounds ptr, ptr %53, i64 %55
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  %58 = call ptr %50(ptr noundef %57)
  %59 = call ptr @bk_newBlockFromBuffer(ptr noundef %58)
  %60 = call ptr (ptr, i32, ...) @bk_push(ptr noundef %49, i32 noundef 16, ptr noundef %59, i32 noundef 0)
  br label %61

61:                                               ; preds = %48
  %62 = load i16, ptr %8, align 2, !tbaa !13
  %63 = add i16 %62, 1
  store i16 %63, ptr %8, align 2, !tbaa !13
  br label %39, !llvm.loop !18

64:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #4
  store i16 0, ptr %9, align 2, !tbaa !13
  br label %65

65:                                               ; preds = %94, %64
  %66 = load i16, ptr %9, align 2, !tbaa !13
  %67 = zext i16 %66 to i32
  %68 = load i16, ptr %6, align 2, !tbaa !13
  %69 = zext i16 %68 to i32
  %70 = icmp slt i32 %67, %69
  br i1 %70, label %72, label %71

71:                                               ; preds = %65
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #4
  br label %97

72:                                               ; preds = %65
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.otl_ChainingRule, ptr %74, i32 0, i32 5
  %76 = load ptr, ptr %75, align 8, !tbaa !20
  %77 = load i16, ptr %9, align 2, !tbaa !13
  %78 = zext i16 %77 to i64
  %79 = getelementptr inbounds %struct.otl_ChainLookupApplication, ptr %76, i64 %78
  %80 = getelementptr inbounds %struct.otl_ChainLookupApplication, ptr %79, i32 0, i32 0
  %81 = load i16, ptr %80, align 8, !tbaa !21
  %82 = zext i16 %81 to i32
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.otl_ChainingRule, ptr %83, i32 0, i32 5
  %85 = load ptr, ptr %84, align 8, !tbaa !20
  %86 = load i16, ptr %9, align 2, !tbaa !13
  %87 = zext i16 %86 to i64
  %88 = getelementptr inbounds %struct.otl_ChainLookupApplication, ptr %85, i64 %87
  %89 = getelementptr inbounds %struct.otl_ChainLookupApplication, ptr %88, i32 0, i32 1
  %90 = getelementptr inbounds %struct.otfcc_Handle, ptr %89, i32 0, i32 1
  %91 = load i16, ptr %90, align 4, !tbaa !25
  %92 = zext i16 %91 to i32
  %93 = call ptr (ptr, i32, ...) @bk_push(ptr noundef %73, i32 noundef 2, i32 noundef %82, i32 noundef 2, i32 noundef %92, i32 noundef 0)
  br label %94

94:                                               ; preds = %72
  %95 = load i16, ptr %9, align 2, !tbaa !13
  %96 = add i16 %95, 1
  store i16 %96, ptr %9, align 2, !tbaa !13
  br label %65, !llvm.loop !26

97:                                               ; preds = %71
  %98 = load ptr, ptr %7, align 8, !tbaa !5
  %99 = call ptr @bk_build_Block(ptr noundef %98)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret ptr %99
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint 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 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 #4 = { 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, !11, i64 4}
!10 = !{!"", !11, i64 0, !11, i64 2, !11, i64 4, !6, i64 8, !11, i64 16, !6, i64 24}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !11, i64 2}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 16}
!15 = !{!16, !6, i64 96}
!16 = !{!"__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}
!17 = !{!10, !6, i64 8}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!10, !6, i64 24}
!21 = !{!22, !11, i64 0}
!22 = !{!"", !11, i64 0, !23, i64 8}
!23 = !{!"otfcc_Handle", !24, i64 0, !11, i64 4, !6, i64 8}
!24 = !{!"int", !7, i64 0}
!25 = !{!22, !11, i64 12}
!26 = distinct !{!26, !19}


; 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.otl_ChainLookupApplication = type { i16, %struct.otfcc_Handle }
%struct.otfcc_Handle = type { i32, i16, ptr }

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @reverseBacktracks(ptr noundef) local_unnamed_addr #0

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

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

declare ptr @bk_newBlockFromBuffer(ptr noundef) local_unnamed_addr #1

declare ptr @bk_build_Block(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @otfcc_build_contextual_coverage(ptr noundef %0) local_unnamed_addr #2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = getelementptr inbounds i8, ptr %0, i64 12
  %4 = load i16, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 10
  %6 = load i16, ptr %5, align 2, !tbaa !11
  %7 = sub i16 %4, %6
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load i16, ptr %8, align 8, !tbaa !12
  tail call void @reverseBacktracks(ptr noundef nonnull %2)
  %10 = tail call ptr (i32, ...) @bk_new_Block(i32 noundef 2, i32 noundef 3, i32 noundef 0) #3
  %11 = zext i16 %7 to i32
  %12 = tail call ptr (ptr, i32, ...) @bk_push(ptr noundef %10, i32 noundef 2, i32 noundef %11, i32 noundef 0) #3
  %13 = zext i16 %9 to i32
  %14 = tail call ptr (ptr, i32, ...) @bk_push(ptr noundef %10, i32 noundef 2, i32 noundef %13, i32 noundef 0) #3
  %15 = load i16, ptr %5, align 2, !tbaa !11
  %16 = load i16, ptr %3, align 4, !tbaa !5
  %17 = icmp ult i16 %15, %16
  br i1 %17, label %.lr.ph, label %.preheader

.lr.ph:                                           ; preds = %1
  %18 = load ptr, ptr getelementptr inbounds (i8, ptr @otl_iCoverage, i64 96), align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %0, i64 16
  %20 = zext i16 %15 to i64
  br label %22

.preheader:                                       ; preds = %22, %1
  %.not = icmp eq i16 %9, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph28

.lr.ph28:                                         ; preds = %.preheader
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  %wide.trip.count = zext i16 %9 to i64
  br label %33

22:                                               ; preds = %.lr.ph, %22
  %indvars.iv = phi i64 [ %20, %.lr.ph ], [ %indvars.iv.next, %22 ]
  %23 = load ptr, ptr %19, align 8, !tbaa !15
  %24 = getelementptr inbounds ptr, ptr %23, i64 %indvars.iv
  %25 = load ptr, ptr %24, align 8, !tbaa !16
  %26 = tail call ptr %18(ptr noundef %25) #3
  %27 = tail call ptr @bk_newBlockFromBuffer(ptr noundef %26) #3
  %28 = tail call ptr (ptr, i32, ...) @bk_push(ptr noundef %10, i32 noundef 16, ptr noundef %27, i32 noundef 0) #3
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = load i16, ptr %3, align 4, !tbaa !5
  %30 = zext i16 %29 to i64
  %31 = icmp ult i64 %indvars.iv.next, %30
  br i1 %31, label %22, label %.preheader, !llvm.loop !17

._crit_edge:                                      ; preds = %33, %.preheader
  %32 = tail call ptr @bk_build_Block(ptr noundef %10) #3
  ret ptr %32

33:                                               ; preds = %.lr.ph28, %33
  %indvars.iv30 = phi i64 [ 0, %.lr.ph28 ], [ %indvars.iv.next31, %33 ]
  %34 = load ptr, ptr %21, align 8, !tbaa !19
  %35 = getelementptr inbounds %struct.otl_ChainLookupApplication, ptr %34, i64 %indvars.iv30
  %36 = load i16, ptr %35, align 8, !tbaa !20
  %37 = zext i16 %36 to i32
  %38 = getelementptr inbounds i8, ptr %35, i64 12
  %39 = load i16, ptr %38, align 4, !tbaa !24
  %40 = zext i16 %39 to i32
  %41 = tail call ptr (ptr, i32, ...) @bk_push(ptr noundef %10, i32 noundef 2, i32 noundef %37, i32 noundef 2, i32 noundef %40, i32 noundef 0) #3
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next31, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %33, !llvm.loop !25
}

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


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