; LLVM IR from caryll/otfcc :: lib/table/otl/subtables (gsub-ligature)

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

@otl_iCoverage = external constant %struct.__otfcc_ICoverage, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 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: 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 @otl_gsub_dump_ligature(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %8, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.subtable_gsub_ligature, ptr %9, i32 0, i32 0
  %11 = load i64, ptr %10, align 8, !tbaa !9
  %12 = call ptr @json_array_new(i64 noundef %11)
  store ptr %12, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #4
  store i16 0, ptr %5, align 2, !tbaa !12
  br label %13

13:                                               ; preds = %62, %1
  %14 = load i16, ptr %5, align 2, !tbaa !12
  %15 = zext i16 %14 to i64
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.subtable_gsub_ligature, ptr %16, i32 0, i32 0
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = icmp ult i64 %15, %18
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %22 = call ptr @json_object_new(i64 noundef 2)
  store ptr %22, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load ptr, ptr getelementptr inbounds (%struct.__otfcc_ICoverage, ptr @otl_iCoverage, i32 0, i32 10), align 8, !tbaa !14
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.subtable_gsub_ligature, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !16
  %28 = load i16, ptr %5, align 2, !tbaa !12
  %29 = zext i16 %28 to i64
  %30 = getelementptr inbounds %struct.otl_GsubLigatureEntry, ptr %27, i64 %29
  %31 = getelementptr inbounds %struct.otl_GsubLigatureEntry, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !17
  %33 = call ptr %24(ptr noundef %32)
  %34 = call ptr @json_object_push(ptr noundef %23, ptr noundef @.str, ptr noundef %33)
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.subtable_gsub_ligature, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !16
  %39 = load i16, ptr %5, align 2, !tbaa !12
  %40 = zext i16 %39 to i64
  %41 = getelementptr inbounds %struct.otl_GsubLigatureEntry, ptr %38, i64 %40
  %42 = getelementptr inbounds %struct.otl_GsubLigatureEntry, ptr %41, i32 0, i32 1
  %43 = getelementptr inbounds %struct.otfcc_Handle, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !21
  %45 = call i64 @sdslen(ptr noundef %44)
  %46 = trunc i64 %45 to i32
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.subtable_gsub_ligature, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = load i16, ptr %5, align 2, !tbaa !12
  %51 = zext i16 %50 to i64
  %52 = getelementptr inbounds %struct.otl_GsubLigatureEntry, ptr %49, i64 %51
  %53 = getelementptr inbounds %struct.otl_GsubLigatureEntry, ptr %52, i32 0, i32 1
  %54 = getelementptr inbounds %struct.otfcc_Handle, ptr %53, i32 0, i32 2
  %55 = load ptr, ptr %54, align 8, !tbaa !21
  %56 = call ptr @json_string_new_length(i32 noundef %46, ptr noundef %55)
  %57 = call ptr @json_object_push(ptr noundef %35, ptr noundef @.str.1, ptr noundef %56)
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = call ptr @preserialize(ptr noundef %59)
  %61 = call ptr @json_array_push(ptr noundef %58, ptr noundef %60)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %62

62:                                               ; preds = %21
  %63 = load i16, ptr %5, align 2, !tbaa !12
  %64 = add i16 %63, 1
  store i16 %64, ptr %5, align 2, !tbaa !12
  br label %13, !llvm.loop !22

65:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %66 = call ptr @json_object_new(i64 noundef 1)
  store ptr %66, ptr %7, align 8, !tbaa !5
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = call ptr @json_object_push(ptr noundef %67, ptr noundef @.str.2, ptr noundef %68)
  %70 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #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 %70
}

declare ptr @json_array_new(i64 noundef) #2

declare ptr @json_object_new(i64 noundef) #2

declare ptr @json_object_push(ptr noundef, ptr noundef, ptr noundef) #2

declare ptr @json_string_new_length(i32 noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @sdslen(ptr noundef) #3

declare ptr @json_array_push(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @preserialize(ptr noundef) #3

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 = { 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 #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 0}
!10 = !{!"", !11, i64 0, !11, i64 8, !6, i64 16}
!11 = !{!"long", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !6, i64 80}
!15 = !{!"__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}
!16 = !{!10, !6, i64 16}
!17 = !{!18, !6, i64 0}
!18 = !{!"", !6, i64 0, !19, i64 8}
!19 = !{!"otfcc_Handle", !20, i64 0, !13, i64 4, !6, i64 8}
!20 = !{!"int", !7, i64 0}
!21 = !{!18, !6, i64 16}
!22 = distinct !{!22, !23}
!23 = !{!"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.__otfcc_ICoverage = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.otl_GsubLigatureEntry = type { ptr, %struct.otfcc_Handle }
%struct.otfcc_Handle = type { i32, i16, ptr }

@otl_iCoverage = external local_unnamed_addr constant %struct.__otfcc_ICoverage, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 x i8], align 1

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

.lr.ph:                                           ; preds = %1
  %5 = load ptr, ptr getelementptr inbounds (i8, ptr @otl_iCoverage, i64 80), align 8
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  br label %9

._crit_edge:                                      ; preds = %9, %1
  %7 = tail call ptr @json_object_new(i64 noundef 1) #3
  %8 = tail call ptr @json_object_push(ptr noundef %7, ptr noundef nonnull @.str.2, ptr noundef %3) #3
  ret ptr %7

9:                                                ; preds = %.lr.ph, %9
  %10 = phi i64 [ 0, %.lr.ph ], [ %30, %9 ]
  %.018 = phi i16 [ 0, %.lr.ph ], [ %29, %9 ]
  %11 = tail call ptr @json_object_new(i64 noundef 2) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !11
  %13 = getelementptr inbounds %struct.otl_GsubLigatureEntry, ptr %12, i64 %10
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = tail call ptr %5(ptr noundef %14) #3
  %16 = tail call ptr @json_object_push(ptr noundef %11, ptr noundef nonnull @.str, ptr noundef %15) #3
  %17 = load ptr, ptr %6, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.otl_GsubLigatureEntry, ptr %17, i64 %10, i32 1, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !17
  %20 = tail call i64 @sdslen(ptr noundef %19)
  %21 = trunc i64 %20 to i32
  %22 = load ptr, ptr %6, align 8, !tbaa !11
  %23 = getelementptr inbounds %struct.otl_GsubLigatureEntry, ptr %22, i64 %10, i32 1, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !17
  %25 = tail call ptr @json_string_new_length(i32 noundef %21, ptr noundef %24) #3
  %26 = tail call ptr @json_object_push(ptr noundef %11, ptr noundef nonnull @.str.1, ptr noundef %25) #3
  %27 = tail call ptr @preserialize(ptr noundef %11)
  %28 = tail call ptr @json_array_push(ptr noundef %3, ptr noundef %27) #3
  %29 = add i16 %.018, 1
  %30 = zext i16 %29 to i64
  %31 = load i64, ptr %0, align 8, !tbaa !5
  %32 = icmp ugt i64 %31, %30
  br i1 %32, label %9, label %._crit_edge, !llvm.loop !18
}

declare ptr @json_array_new(i64 noundef) local_unnamed_addr #1

declare ptr @json_object_new(i64 noundef) local_unnamed_addr #1

declare ptr @json_object_push(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @json_string_new_length(i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @sdslen(ptr noundef) local_unnamed_addr #2

declare ptr @json_array_push(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @preserialize(ptr noundef) local_unnamed_addr #2

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 = { 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 #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 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 16}
!12 = !{!13, !10, i64 0}
!13 = !{!"", !10, i64 0, !14, i64 8}
!14 = !{!"otfcc_Handle", !15, i64 0, !16, i64 4, !10, i64 8}
!15 = !{!"int", !8, i64 0}
!16 = !{!"short", !8, i64 0}
!17 = !{!13, !10, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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