; 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.__caryll_vectorinterface_subtable_gsub_multi = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%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_GsubMultiEntry = type { %struct.otfcc_Handle, ptr }
%struct.otfcc_Handle = type { i32, i16, ptr }
%struct._json_value = type { ptr, i32, %union.anon.0, %union.anon.4 }
%union.anon.0 = type { %struct.anon.1 }
%struct.anon.1 = type { i32, ptr }
%union.anon.4 = type { ptr }
%struct.anon.2 = type { i32, ptr }
%struct._json_object_entry = type { ptr, i32, ptr }

@iSubtable_gsub_multi = external dso_local constant %struct.__caryll_vectorinterface_subtable_gsub_multi, align 8
@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 @otl_gsub_parse_multi(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca %struct.otl_GsubMultiEntry, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %10 = load ptr, ptr getelementptr inbounds (%struct.__caryll_vectorinterface_subtable_gsub_multi, ptr @iSubtable_gsub_multi, i32 0, i32 6), align 8, !tbaa !9
  %11 = call ptr (...) %10()
  store ptr %11, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #3
  store i16 0, ptr %6, align 2, !tbaa !11
  br label %12

12:                                               ; preds = %76, %2
  %13 = load i16, ptr %6, align 2, !tbaa !11
  %14 = zext i16 %13 to i32
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct._json_value, ptr %15, i32 0, i32 2
  %17 = getelementptr inbounds %struct.anon.2, ptr %16, i32 0, i32 0
  %18 = load i32, ptr %17, align 8, !tbaa !13
  %19 = icmp ult i32 %14, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %12
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #3
  br label %79

21:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._json_value, ptr %22, i32 0, i32 2
  %24 = getelementptr inbounds %struct.anon.2, ptr %23, i32 0, i32 1
  %25 = load ptr, ptr %24, align 8, !tbaa !13
  %26 = load i16, ptr %6, align 2, !tbaa !11
  %27 = zext i16 %26 to i64
  %28 = getelementptr inbounds %struct._json_object_entry, ptr %25, i64 %27
  %29 = getelementptr inbounds %struct._json_object_entry, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  store ptr %30, ptr %8, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %38

33:                                               ; preds = %21
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct._json_value, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !17
  %37 = icmp ne i32 %36, 2
  br i1 %37, label %38, label %39

38:                                               ; preds = %33, %21
  store i32 4, ptr %7, align 4
  br label %73

39:                                               ; preds = %33
  %40 = load ptr, ptr getelementptr inbounds (%struct.__caryll_vectorinterface_subtable_gsub_multi, ptr @iSubtable_gsub_multi, i32 0, i32 13), align 8, !tbaa !19
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.otl_GsubMultiEntry, ptr %9, i32 0, i32 0
  %43 = load ptr, ptr getelementptr inbounds (%struct.otfcc_HandlePackage, ptr @otfcc_iHandle, i32 0, i32 9), align 8, !tbaa !20
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct._json_value, ptr %44, i32 0, i32 2
  %46 = getelementptr inbounds %struct.anon.2, ptr %45, i32 0, i32 1
  %47 = load ptr, ptr %46, align 8, !tbaa !13
  %48 = load i16, ptr %6, align 2, !tbaa !11
  %49 = zext i16 %48 to i64
  %50 = getelementptr inbounds %struct._json_object_entry, ptr %47, i64 %49
  %51 = getelementptr inbounds %struct._json_object_entry, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !22
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct._json_value, ptr %53, i32 0, i32 2
  %55 = getelementptr inbounds %struct.anon.2, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !13
  %57 = load i16, ptr %6, align 2, !tbaa !11
  %58 = zext i16 %57 to i64
  %59 = getelementptr inbounds %struct._json_object_entry, ptr %56, i64 %58
  %60 = getelementptr inbounds %struct._json_object_entry, ptr %59, i32 0, i32 1
  %61 = load i32, ptr %60, align 8, !tbaa !23
  %62 = zext i32 %61 to i64
  %63 = call ptr @sdsnewlen(ptr noundef %52, i64 noundef %62)
  %64 = call { i64, ptr } %43(ptr noundef %63)
  %65 = getelementptr inbounds { i64, ptr }, ptr %42, i32 0, i32 0
  %66 = extractvalue { i64, ptr } %64, 0
  store i64 %66, ptr %65, align 8
  %67 = getelementptr inbounds { i64, ptr }, ptr %42, i32 0, i32 1
  %68 = extractvalue { i64, ptr } %64, 1
  store ptr %68, ptr %67, align 8
  %69 = getelementptr inbounds %struct.otl_GsubMultiEntry, ptr %9, i32 0, i32 1
  %70 = load ptr, ptr getelementptr inbounds (%struct.__otfcc_ICoverage, ptr @otl_iCoverage, i32 0, i32 11), align 8, !tbaa !24
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = call ptr %70(ptr noundef %71)
  store ptr %72, ptr %69, align 8, !tbaa !26
  call void %40(ptr noundef %41, ptr noundef byval(%struct.otl_GsubMultiEntry) align 8 %9)
  store i32 0, ptr %7, align 4
  br label %73

73:                                               ; preds = %39, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %74 = load i32, ptr %7, align 4
  switch i32 %74, label %81 [
    i32 0, label %75
    i32 4, label %76
  ]

75:                                               ; preds = %73
  br label %76

76:                                               ; preds = %75, %73
  %77 = load i16, ptr %6, align 2, !tbaa !11
  %78 = add i16 %77, 1
  store i16 %78, ptr %6, align 2, !tbaa !11
  br label %12, !llvm.loop !29

79:                                               ; preds = %20
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %80

81:                                               ; preds = %73
  unreachable
}

declare ptr @sdsnewlen(ptr noundef, i64 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, !6, i64 48}
!10 = !{!"__caryll_vectorinterface_subtable_gsub_multi", !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, !6, i64 128, !6, i64 136, !6, i64 144}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !6, i64 16}
!15 = !{!"_json_object_entry", !6, i64 0, !16, i64 8, !6, i64 16}
!16 = !{!"int", !7, i64 0}
!17 = !{!18, !16, i64 8}
!18 = !{!"_json_value", !6, i64 0, !16, i64 8, !7, i64 16, !7, i64 32}
!19 = !{!10, !6, i64 104}
!20 = !{!21, !6, i64 72}
!21 = !{!"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}
!22 = !{!15, !6, i64 0}
!23 = !{!15, !16, i64 8}
!24 = !{!25, !6, i64 88}
!25 = !{!"__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}
!26 = !{!27, !6, i64 16}
!27 = !{!"", !28, i64 0, !6, i64 16}
!28 = !{!"otfcc_Handle", !16, i64 0, !12, i64 4, !6, i64 8}
!29 = distinct !{!29, !30}
!30 = !{!"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.__caryll_vectorinterface_subtable_gsub_multi = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%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_GsubMultiEntry = type { %struct.otfcc_Handle, ptr }
%struct.otfcc_Handle = type { i32, i16, ptr }
%struct._json_object_entry = type { ptr, i32, ptr }

@iSubtable_gsub_multi = external dso_local local_unnamed_addr constant %struct.__caryll_vectorinterface_subtable_gsub_multi, align 8
@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 @otl_gsub_parse_multi(ptr nocapture noundef readonly %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca %struct.otl_GsubMultiEntry, align 8
  %4 = load ptr, ptr getelementptr inbounds (i8, ptr @iSubtable_gsub_multi, i64 48), align 8, !tbaa !5
  %5 = tail call ptr (...) %4() #2
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load i32, ptr %6, align 8, !tbaa !10
  %.not16 = icmp eq i32 %7, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load ptr, ptr getelementptr inbounds (i8, ptr @iSubtable_gsub_multi, i64 104), align 8
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @otfcc_iHandle, i64 72), align 8
  %11 = getelementptr inbounds i8, ptr %3, i64 8
  %12 = getelementptr inbounds i8, ptr %3, i64 16
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @otl_iCoverage, i64 88), align 8
  br label %14

._crit_edge:                                      ; preds = %34, %2
  ret ptr %5

14:                                               ; preds = %.lr.ph, %34
  %15 = phi i32 [ %7, %.lr.ph ], [ %35, %34 ]
  %.015 = phi i16 [ 0, %.lr.ph ], [ %36, %34 ]
  %16 = load ptr, ptr %8, align 8, !tbaa !10
  %17 = zext i16 %.015 to i64
  %18 = getelementptr inbounds %struct._json_object_entry, ptr %16, i64 %17
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %.not = icmp eq ptr %20, null
  br i1 %.not, label %34, label %21

21:                                               ; preds = %14
  %22 = getelementptr inbounds i8, ptr %20, i64 8
  %23 = load i32, ptr %22, align 8, !tbaa !14
  %.not14 = icmp eq i32 %23, 2
  br i1 %.not14, label %24, label %34

24:                                               ; preds = %21
  %25 = load ptr, ptr %18, align 8, !tbaa !16
  %26 = getelementptr inbounds i8, ptr %18, i64 8
  %27 = load i32, ptr %26, align 8, !tbaa !17
  %28 = zext i32 %27 to i64
  %29 = tail call ptr @sdsnewlen(ptr noundef %25, i64 noundef %28) #2
  %30 = tail call { i64, ptr } %10(ptr noundef %29) #2
  %31 = extractvalue { i64, ptr } %30, 0
  store i64 %31, ptr %3, align 8
  %32 = extractvalue { i64, ptr } %30, 1
  store ptr %32, ptr %11, align 8
  %33 = tail call ptr %13(ptr noundef nonnull %20) #2
  store ptr %33, ptr %12, align 8, !tbaa !18
  tail call void %9(ptr noundef %5, ptr noundef nonnull byval(%struct.otl_GsubMultiEntry) align 8 %3) #2
  %.pre = load i32, ptr %6, align 8, !tbaa !10
  br label %34

34:                                               ; preds = %14, %21, %24
  %35 = phi i32 [ %15, %14 ], [ %15, %21 ], [ %.pre, %24 ]
  %36 = add i16 %.015, 1
  %37 = zext i16 %36 to i32
  %38 = icmp ugt i32 %35, %37
  br i1 %38, label %14, label %._crit_edge, !llvm.loop !22
}

declare ptr @sdsnewlen(ptr noundef, i64 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 = !{!"__caryll_vectorinterface_subtable_gsub_multi", !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, i64 128, !7, i64 136, !7, i64 144}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12, !7, i64 16}
!12 = !{!"_json_object_entry", !7, i64 0, !13, i64 8, !7, i64 16}
!13 = !{!"int", !8, i64 0}
!14 = !{!15, !13, i64 8}
!15 = !{!"_json_value", !7, i64 0, !13, i64 8, !8, i64 16, !8, i64 32}
!16 = !{!12, !7, i64 0}
!17 = !{!12, !13, i64 8}
!18 = !{!19, !7, i64 16}
!19 = !{!"", !20, i64 0, !7, i64 16}
!20 = !{!"otfcc_Handle", !13, i64 0, !21, i64 4, !7, i64 8}
!21 = !{!"short", !8, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


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