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

; 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.__caryll_elementinterface_subtable_chaining = type { 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.otfcc_Options = type { i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, i8, ptr, ptr }
%struct.otfcc_ILogger = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@iSubtable_chaining = external constant %struct.__caryll_elementinterface_subtable_chaining, align 8
@.str = external hidden unnamed_addr constant [24 x i8], align 1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @__caryll_allocate_clean(i64 noundef, i64 noundef) #1

; 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
declare dso_local ptr @format3Coverage(ptr noundef, i32 noundef, i16 noundef zeroext, i32 noundef, i16 noundef zeroext, i16 noundef zeroext, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @read_16u(ptr noundef) #1

declare ptr @sdscatprintf(ptr noundef, ptr noundef, ...) #3

declare ptr @sdsempty() #3

; Function Attrs: nounwind uwtable
declare dso_local ptr @GeneralReadChainingRule(ptr noundef, i32 noundef, i32 noundef, i16 noundef zeroext, i1 noundef zeroext, ptr noundef, i16 noundef zeroext, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local ptr @otl_read_chaining(ptr noundef %0, i32 noundef %1, i32 noundef %2, i16 noundef zeroext %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i16, align 2
  %11 = alloca ptr, align 8
  %12 = alloca i16, align 2
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i16 %3, ptr %10, align 2, !tbaa !11
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %12) #4
  store i16 0, ptr %12, align 2, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %15 = load ptr, ptr getelementptr inbounds (%struct.__caryll_elementinterface_subtable_chaining, ptr @iSubtable_chaining, i32 0, i32 6), align 8, !tbaa !13
  %16 = call ptr (...) %15()
  store ptr %16, ptr %13, align 8, !tbaa !5
  %17 = load ptr, ptr %13, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.subtable_chaining, ptr %17, i32 0, i32 0
  store i32 1, ptr %18, align 8, !tbaa !15
  %19 = load i32, ptr %8, align 4, !tbaa !9
  %20 = load i32, ptr %9, align 4, !tbaa !9
  %21 = add i32 %20, 2
  %22 = icmp ult i32 %19, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %5
  br label %78

24:                                               ; preds = %5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  %29 = call zeroext i16 @read_16u(ptr noundef %28)
  store i16 %29, ptr %12, align 2, !tbaa !11
  %30 = load i16, ptr %12, align 2, !tbaa !11
  %31 = zext i16 %30 to i32
  %32 = icmp eq i32 %31, 1
  br i1 %32, label %33, label %40

33:                                               ; preds = %24
  %34 = load ptr, ptr %13, align 8, !tbaa !5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = load i32, ptr %9, align 4, !tbaa !9
  %38 = load i16, ptr %10, align 2, !tbaa !11
  %39 = call ptr @readChainingFormat1(ptr noundef %34, ptr noundef %35, i32 noundef %36, i32 noundef %37, i16 noundef zeroext %38)
  store ptr %39, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %93

40:                                               ; preds = %24
  %41 = load i16, ptr %12, align 2, !tbaa !11
  %42 = zext i16 %41 to i32
  %43 = icmp eq i32 %42, 2
  br i1 %43, label %44, label %51

44:                                               ; preds = %40
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = load i16, ptr %10, align 2, !tbaa !11
  %50 = call ptr @readChainingFormat2(ptr noundef %45, ptr noundef %46, i32 noundef %47, i32 noundef %48, i16 noundef zeroext %49)
  store ptr %50, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %93

51:                                               ; preds = %40
  %52 = load i16, ptr %12, align 2, !tbaa !11
  %53 = zext i16 %52 to i32
  %54 = icmp eq i32 %53, 3
  br i1 %54, label %55, label %75

55:                                               ; preds = %51
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.subtable_chaining, ptr %56, i32 0, i32 1
  %58 = getelementptr inbounds %struct.anon, ptr %57, i32 0, i32 0
  store i16 1, ptr %58, align 8, !tbaa !17
  %59 = call ptr @__caryll_allocate_clean(i64 noundef 8, i64 noundef 407)
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.subtable_chaining, ptr %60, i32 0, i32 1
  %62 = getelementptr inbounds %struct.anon, ptr %61, i32 0, i32 1
  store ptr %59, ptr %62, align 8, !tbaa !17
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = add i32 %65, 2
  %67 = load i16, ptr %10, align 2, !tbaa !11
  %68 = call ptr @GeneralReadChainingRule(ptr noundef %63, i32 noundef %64, i32 noundef %66, i16 noundef zeroext 0, i1 noundef zeroext false, ptr noundef @format3Coverage, i16 noundef zeroext %67, ptr noundef null)
  %69 = load ptr, ptr %13, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.subtable_chaining, ptr %69, i32 0, i32 1
  %71 = getelementptr inbounds %struct.anon, ptr %70, i32 0, i32 1
  %72 = load ptr, ptr %71, align 8, !tbaa !17
  %73 = getelementptr inbounds ptr, ptr %72, i64 0
  store ptr %68, ptr %73, align 8, !tbaa !5
  %74 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %74, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %93

75:                                               ; preds = %51
  br label %76

76:                                               ; preds = %75
  br label %77

77:                                               ; preds = %76
  br label %78

78:                                               ; preds = %77, %23
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.otfcc_Options, ptr %79, i32 0, i32 24
  %81 = load ptr, ptr %80, align 8, !tbaa !18
  %82 = getelementptr inbounds %struct.otfcc_ILogger, ptr %81, i32 0, i32 6
  %83 = load ptr, ptr %82, align 8, !tbaa !21
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.otfcc_Options, ptr %84, i32 0, i32 24
  %86 = load ptr, ptr %85, align 8, !tbaa !18
  %87 = call ptr @sdsempty()
  %88 = load i16, ptr %12, align 2, !tbaa !11
  %89 = zext i16 %88 to i32
  %90 = call ptr (ptr, ptr, ...) @sdscatprintf(ptr noundef %87, ptr noundef @.str, i32 noundef %89)
  call void %83(ptr noundef %86, i8 noundef zeroext 1, i32 noundef 1, ptr noundef %90)
  %91 = load ptr, ptr getelementptr inbounds (%struct.__caryll_elementinterface_subtable_chaining, ptr @iSubtable_chaining, i32 0, i32 7), align 8, !tbaa !23
  %92 = load ptr, ptr %13, align 8, !tbaa !5
  call void %91(ptr noundef %92)
  store ptr null, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %93

93:                                               ; preds = %78, %55, %44, %33
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 2, ptr %12) #4
  %94 = load ptr, ptr %6, align 8
  ret ptr %94
}

; Function Attrs: nounwind uwtable
declare hidden ptr @readChainingFormat1(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i16 noundef zeroext) #2

; Function Attrs: nounwind uwtable
declare hidden ptr @readChainingFormat2(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i16 noundef zeroext) #2

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 = { 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 = { "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !6, i64 48}
!14 = !{!"__caryll_elementinterface_subtable_chaining", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!15 = !{!16, !10, i64 0}
!16 = !{!"", !10, i64 0, !7, i64 8}
!17 = !{!7, !7, i64 0}
!18 = !{!19, !6, i64 32}
!19 = !{!"", !20, i64 0, !20, i64 1, !20, i64 2, !20, i64 3, !20, i64 4, !20, i64 5, !20, i64 6, !20, i64 7, !20, i64 8, !20, i64 9, !20, i64 10, !20, i64 11, !20, i64 12, !20, i64 13, !20, i64 14, !20, i64 15, !20, i64 16, !20, i64 17, !20, i64 18, !20, i64 19, !20, i64 20, !20, i64 21, !20, i64 22, !6, i64 24, !6, i64 32}
!20 = !{!"_Bool", !7, i64 0}
!21 = !{!22, !6, i64 48}
!22 = !{!"otfcc_ILogger", !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}
!23 = !{!14, !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.__caryll_elementinterface_subtable_chaining = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@iSubtable_chaining = external local_unnamed_addr constant %struct.__caryll_elementinterface_subtable_chaining, align 8
@.str = external hidden unnamed_addr constant [24 x i8], align 1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @__caryll_allocate_clean(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @format3Coverage(ptr noundef, i32 noundef, i16 noundef zeroext, i32 noundef, i16 noundef zeroext, i16 noundef zeroext, ptr noundef) #1

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

declare ptr @sdscatprintf(ptr noundef, ptr noundef, ...) local_unnamed_addr #2

declare ptr @sdsempty() local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @GeneralReadChainingRule(ptr noundef, i32 noundef, i32 noundef, i16 noundef zeroext, i1 noundef zeroext, ptr noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local ptr @otl_read_chaining(ptr noundef %0, i32 noundef %1, i32 noundef %2, i16 noundef zeroext %3, ptr nocapture noundef readonly %4) local_unnamed_addr #1 {
  %6 = load ptr, ptr getelementptr inbounds (i8, ptr @iSubtable_chaining, i64 48), align 8, !tbaa !5
  %7 = tail call ptr (...) %6() #3
  store i32 1, ptr %7, align 8, !tbaa !10
  %8 = add i32 %2, 2
  %9 = icmp ugt i32 %8, %1
  br i1 %9, label %24, label %10

10:                                               ; preds = %5
  %11 = zext i32 %2 to i64
  %12 = getelementptr inbounds i8, ptr %0, i64 %11
  %13 = tail call zeroext i16 @read_16u(ptr noundef %12)
  switch i16 %13, label %24 [
    i16 1, label %14
    i16 2, label %16
    i16 3, label %18
  ]

14:                                               ; preds = %10
  %15 = tail call ptr @readChainingFormat1(ptr noundef nonnull %7, ptr noundef %0, i32 noundef %1, i32 noundef %2, i16 noundef zeroext %3)
  br label %33

16:                                               ; preds = %10
  %17 = tail call ptr @readChainingFormat2(ptr noundef nonnull %7, ptr noundef %0, i32 noundef %1, i32 noundef %2, i16 noundef zeroext %3)
  br label %33

18:                                               ; preds = %10
  %19 = getelementptr inbounds i8, ptr %7, i64 8
  store i16 1, ptr %19, align 8, !tbaa !13
  %20 = tail call ptr @__caryll_allocate_clean(i64 noundef 8, i64 noundef 407)
  %21 = getelementptr inbounds i8, ptr %7, i64 16
  store ptr %20, ptr %21, align 8, !tbaa !13
  %22 = tail call ptr @GeneralReadChainingRule(ptr noundef %0, i32 noundef %1, i32 noundef %8, i16 noundef zeroext 0, i1 noundef zeroext false, ptr noundef nonnull @format3Coverage, i16 noundef zeroext %3, ptr noundef null)
  %23 = load ptr, ptr %21, align 8, !tbaa !13
  store ptr %22, ptr %23, align 8, !tbaa !14
  br label %33

24:                                               ; preds = %10, %5
  %.030 = phi i16 [ 0, %5 ], [ %13, %10 ]
  %25 = getelementptr inbounds i8, ptr %4, i64 32
  %26 = load ptr, ptr %25, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %26, i64 48
  %28 = load ptr, ptr %27, align 8, !tbaa !18
  %29 = tail call ptr @sdsempty() #3
  %30 = zext i16 %.030 to i32
  %31 = tail call ptr (ptr, ptr, ...) @sdscatprintf(ptr noundef %29, ptr noundef nonnull @.str, i32 noundef %30) #3
  tail call void %28(ptr noundef %26, i8 noundef zeroext 1, i32 noundef 1, ptr noundef %31) #3
  %32 = load ptr, ptr getelementptr inbounds (i8, ptr @iSubtable_chaining, i64 56), align 8, !tbaa !20
  tail call void %32(ptr noundef nonnull %7) #3
  br label %33

33:                                               ; preds = %24, %18, %16, %14
  %.0 = phi ptr [ null, %24 ], [ %15, %14 ], [ %17, %16 ], [ %7, %18 ]
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare hidden ptr @readChainingFormat1(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i16 noundef zeroext) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden ptr @readChainingFormat2(ptr noundef, ptr noundef, i32 noundef, i32 noundef, i16 noundef zeroext) local_unnamed_addr #1

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 = { 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, !7, i64 48}
!6 = !{!"__caryll_elementinterface_subtable_chaining", !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 = !{!"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, !8, i64 8}
!12 = !{!"int", !8, i64 0}
!13 = !{!8, !8, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !7, i64 32}
!16 = !{!"", !17, i64 0, !17, i64 1, !17, i64 2, !17, i64 3, !17, i64 4, !17, i64 5, !17, i64 6, !17, i64 7, !17, i64 8, !17, i64 9, !17, i64 10, !17, i64 11, !17, i64 12, !17, i64 13, !17, i64 14, !17, i64 15, !17, i64 16, !17, i64 17, !17, i64 18, !17, i64 19, !17, i64 20, !17, i64 21, !17, i64 22, !7, i64 24, !7, i64 32}
!17 = !{!"_Bool", !8, i64 0}
!18 = !{!19, !7, i64 48}
!19 = !{!"otfcc_ILogger", !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}
!20 = !{!6, !7, i64 56}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass