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

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

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

18:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #3
  br label %44

19:                                               ; preds = %11
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.subtable_gsub_multi, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = load i16, ptr %5, align 2, !tbaa !12
  %25 = zext i16 %24 to i64
  %26 = getelementptr inbounds %struct.otl_GsubMultiEntry, ptr %23, i64 %25
  %27 = getelementptr inbounds %struct.otl_GsubMultiEntry, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.otfcc_Handle, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = load ptr, ptr getelementptr inbounds (%struct.__otfcc_ICoverage, ptr @otl_iCoverage, i32 0, i32 10), align 8, !tbaa !19
  %31 = load ptr, ptr %3, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.subtable_gsub_multi, ptr %31, i32 0, i32 2
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = load i16, ptr %5, align 2, !tbaa !12
  %35 = zext i16 %34 to i64
  %36 = getelementptr inbounds %struct.otl_GsubMultiEntry, ptr %33, i64 %35
  %37 = getelementptr inbounds %struct.otl_GsubMultiEntry, ptr %36, i32 0, i32 1
  %38 = load ptr, ptr %37, align 8, !tbaa !21
  %39 = call ptr %30(ptr noundef %38)
  %40 = call ptr @json_object_push(ptr noundef %20, ptr noundef %29, ptr noundef %39)
  br label %41

41:                                               ; preds = %19
  %42 = load i16, ptr %5, align 2, !tbaa !12
  %43 = add i16 %42, 1
  store i16 %43, ptr %5, align 2, !tbaa !12
  br label %11, !llvm.loop !22

44:                                               ; preds = %18
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr %45
}

declare ptr @json_object_new(i64 noundef) #2

declare ptr @json_object_push(ptr noundef, ptr noundef, 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, !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 = !{!10, !6, i64 16}
!15 = !{!16, !6, i64 8}
!16 = !{!"", !17, i64 0, !6, i64 16}
!17 = !{!"otfcc_Handle", !18, i64 0, !13, i64 4, !6, i64 8}
!18 = !{!"int", !7, i64 0}
!19 = !{!20, !6, i64 80}
!20 = !{!"__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}
!21 = !{!16, !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_GsubMultiEntry = type { %struct.otfcc_Handle, ptr }
%struct.otfcc_Handle = type { i32, i16, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local ptr @otl_gsub_dump_multi(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = load i64, ptr %0, align 8, !tbaa !5
  %3 = tail call ptr @json_object_new(i64 noundef %2) #2
  %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 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr getelementptr inbounds (i8, ptr @otl_iCoverage, i64 80), align 8, !tbaa !11
  br label %7

._crit_edge:                                      ; preds = %7, %1
  ret ptr %3

7:                                                ; preds = %.lr.ph, %7
  %8 = phi i64 [ 0, %.lr.ph ], [ %18, %7 ]
  %.011 = phi i16 [ 0, %.lr.ph ], [ %17, %7 ]
  %9 = load ptr, ptr %5, align 8, !tbaa !13
  %10 = getelementptr inbounds %struct.otl_GsubMultiEntry, ptr %9, i64 %8
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %10, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !19
  %15 = tail call ptr %6(ptr noundef %14) #2
  %16 = tail call ptr @json_object_push(ptr noundef %3, ptr noundef %12, ptr noundef %15) #2
  %17 = add i16 %.011, 1
  %18 = zext i16 %17 to i64
  %19 = load i64, ptr %0, align 8, !tbaa !5
  %20 = icmp ugt i64 %19, %18
  br i1 %20, label %7, label %._crit_edge, !llvm.loop !20
}

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

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 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 = !{!12, !10, i64 80}
!12 = !{!"__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}
!13 = !{!6, !10, i64 16}
!14 = !{!15, !10, i64 8}
!15 = !{!"", !16, i64 0, !10, i64 16}
!16 = !{!"otfcc_Handle", !17, i64 0, !18, i64 4, !10, i64 8}
!17 = !{!"int", !8, i64 0}
!18 = !{!"short", !8, i64 0}
!19 = !{!15, !10, i64 16}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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