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

; 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_single = type { ptr, ptr, ptr, 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.otfcc_Handle = type { i32, i16, ptr }
%struct.otl_GsubSingleEntry = type { %struct.otfcc_Handle, %struct.otfcc_Handle }
%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_single = external dso_local constant %struct.__caryll_vectorinterface_subtable_gsub_single, 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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
define dso_local ptr @otl_gsub_parse_single(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i16, align 2
  %7 = alloca %struct.otfcc_Handle, align 8
  %8 = alloca %struct.otfcc_Handle, align 8
  %9 = alloca %struct.otl_GsubSingleEntry, 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) #4
  %10 = load ptr, ptr getelementptr inbounds (%struct.__caryll_vectorinterface_subtable_gsub_single, ptr @iSubtable_gsub_single, 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) #4
  store i16 0, ptr %6, align 2, !tbaa !11
  br label %12

12:                                               ; preds = %109, %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
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #4
  br label %112

21:                                               ; preds = %12
  %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
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %108

32:                                               ; preds = %21
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct._json_value, ptr %33, i32 0, i32 2
  %35 = getelementptr inbounds %struct.anon.2, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !13
  %37 = load i16, ptr %6, align 2, !tbaa !11
  %38 = zext i16 %37 to i64
  %39 = getelementptr inbounds %struct._json_object_entry, ptr %36, i64 %38
  %40 = getelementptr inbounds %struct._json_object_entry, ptr %39, i32 0, i32 2
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = getelementptr inbounds %struct._json_value, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 8, !tbaa !17
  %44 = icmp eq i32 %43, 5
  br i1 %44, label %45, label %108

45:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %46 = load ptr, ptr getelementptr inbounds (%struct.otfcc_HandlePackage, ptr @otfcc_iHandle, i32 0, i32 9), align 8, !tbaa !19
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._json_value, ptr %47, i32 0, i32 2
  %49 = getelementptr inbounds %struct.anon.2, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !13
  %51 = load i16, ptr %6, align 2, !tbaa !11
  %52 = zext i16 %51 to i64
  %53 = getelementptr inbounds %struct._json_object_entry, ptr %50, i64 %52
  %54 = getelementptr inbounds %struct._json_object_entry, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !21
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct._json_value, ptr %56, i32 0, i32 2
  %58 = getelementptr inbounds %struct.anon.2, ptr %57, i32 0, i32 1
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  %60 = load i16, ptr %6, align 2, !tbaa !11
  %61 = zext i16 %60 to i64
  %62 = getelementptr inbounds %struct._json_object_entry, ptr %59, i64 %61
  %63 = getelementptr inbounds %struct._json_object_entry, ptr %62, i32 0, i32 1
  %64 = load i32, ptr %63, align 8, !tbaa !22
  %65 = zext i32 %64 to i64
  %66 = call ptr @sdsnewlen(ptr noundef %55, i64 noundef %65)
  %67 = call { i64, ptr } %46(ptr noundef %66)
  %68 = getelementptr inbounds { i64, ptr }, ptr %7, i32 0, i32 0
  %69 = extractvalue { i64, ptr } %67, 0
  store i64 %69, ptr %68, align 8
  %70 = getelementptr inbounds { i64, ptr }, ptr %7, i32 0, i32 1
  %71 = extractvalue { i64, ptr } %67, 1
  store ptr %71, ptr %70, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr %8) #4
  %72 = load ptr, ptr getelementptr inbounds (%struct.otfcc_HandlePackage, ptr @otfcc_iHandle, i32 0, i32 9), align 8, !tbaa !19
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct._json_value, ptr %73, i32 0, i32 2
  %75 = getelementptr inbounds %struct.anon.2, ptr %74, i32 0, i32 1
  %76 = load ptr, ptr %75, align 8, !tbaa !13
  %77 = load i16, ptr %6, align 2, !tbaa !11
  %78 = zext i16 %77 to i64
  %79 = getelementptr inbounds %struct._json_object_entry, ptr %76, i64 %78
  %80 = getelementptr inbounds %struct._json_object_entry, ptr %79, i32 0, i32 2
  %81 = load ptr, ptr %80, align 8, !tbaa !14
  %82 = getelementptr inbounds %struct._json_value, ptr %81, i32 0, i32 2
  %83 = getelementptr inbounds %struct.anon.1, ptr %82, i32 0, i32 1
  %84 = load ptr, ptr %83, align 8, !tbaa !13
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct._json_value, ptr %85, i32 0, i32 2
  %87 = getelementptr inbounds %struct.anon.2, ptr %86, i32 0, i32 1
  %88 = load ptr, ptr %87, align 8, !tbaa !13
  %89 = load i16, ptr %6, align 2, !tbaa !11
  %90 = zext i16 %89 to i64
  %91 = getelementptr inbounds %struct._json_object_entry, ptr %88, i64 %90
  %92 = getelementptr inbounds %struct._json_object_entry, ptr %91, i32 0, i32 2
  %93 = load ptr, ptr %92, align 8, !tbaa !14
  %94 = getelementptr inbounds %struct._json_value, ptr %93, i32 0, i32 2
  %95 = getelementptr inbounds %struct.anon.1, ptr %94, i32 0, i32 0
  %96 = load i32, ptr %95, align 8, !tbaa !13
  %97 = zext i32 %96 to i64
  %98 = call ptr @sdsnewlen(ptr noundef %84, i64 noundef %97)
  %99 = call { i64, ptr } %72(ptr noundef %98)
  %100 = getelementptr inbounds { i64, ptr }, ptr %8, i32 0, i32 0
  %101 = extractvalue { i64, ptr } %99, 0
  store i64 %101, ptr %100, align 8
  %102 = getelementptr inbounds { i64, ptr }, ptr %8, i32 0, i32 1
  %103 = extractvalue { i64, ptr } %99, 1
  store ptr %103, ptr %102, align 8
  %104 = load ptr, ptr getelementptr inbounds (%struct.__caryll_vectorinterface_subtable_gsub_single, ptr @iSubtable_gsub_single, i32 0, i32 13), align 8, !tbaa !23
  %105 = load ptr, ptr %5, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.otl_GsubSingleEntry, ptr %9, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %106, ptr align 8 %7, i64 16, i1 false), !tbaa.struct !24
  %107 = getelementptr inbounds %struct.otl_GsubSingleEntry, ptr %9, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %107, ptr align 8 %8, i64 16, i1 false), !tbaa.struct !24
  call void %104(ptr noundef %105, ptr noundef byval(%struct.otl_GsubSingleEntry) align 8 %9)
  call void @llvm.lifetime.end.p0(i64 16, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  br label %108

108:                                              ; preds = %45, %32, %21
  br label %109

109:                                              ; preds = %108
  %110 = load i16, ptr %6, align 2, !tbaa !11
  %111 = add i16 %110, 1
  store i16 %111, ptr %6, align 2, !tbaa !11
  br label %12, !llvm.loop !26

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

declare ptr @sdsnewlen(ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 48}
!10 = !{!"__caryll_vectorinterface_subtable_gsub_single", !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 = !{!20, !6, i64 72}
!20 = !{!"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}
!21 = !{!15, !6, i64 0}
!22 = !{!15, !16, i64 8}
!23 = !{!10, !6, i64 104}
!24 = !{i64 0, i64 4, !25, i64 4, i64 2, !11, i64 8, i64 8, !5}
!25 = !{!16, !16, i64 0}
!26 = distinct !{!26, !27}
!27 = !{!"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_single = type { ptr, ptr, ptr, 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_GsubSingleEntry = type { %struct.otfcc_Handle, %struct.otfcc_Handle }
%struct.otfcc_Handle = type { i32, i16, ptr }
%struct._json_object_entry = type { ptr, i32, ptr }

@iSubtable_gsub_single = external dso_local local_unnamed_addr constant %struct.__caryll_vectorinterface_subtable_gsub_single, 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_single(ptr nocapture noundef readonly %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca %struct.otl_GsubSingleEntry, align 8
  %4 = load ptr, ptr getelementptr inbounds (i8, ptr @iSubtable_gsub_single, 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
  %.not20 = icmp eq i32 %7, 0
  br i1 %.not20, 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 @otfcc_iHandle, i64 72), align 8
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @iSubtable_gsub_single, i64 104), align 8
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 8
  %11 = getelementptr inbounds i8, ptr %3, i64 16
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 24
  br label %12

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

12:                                               ; preds = %.lr.ph, %44
  %13 = phi i32 [ %7, %.lr.ph ], [ %45, %44 ]
  %.019 = phi i16 [ 0, %.lr.ph ], [ %46, %44 ]
  %14 = load ptr, ptr %8, align 8, !tbaa !10
  %15 = zext i16 %.019 to i64
  %16 = getelementptr inbounds %struct._json_object_entry, ptr %14, i64 %15
  %17 = getelementptr inbounds i8, ptr %16, i64 16
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  %.not = icmp eq ptr %18, null
  br i1 %.not, label %44, label %19

19:                                               ; preds = %12
  %20 = getelementptr inbounds i8, ptr %18, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !14
  %22 = icmp eq i32 %21, 5
  br i1 %22, label %23, label %44

23:                                               ; preds = %19
  %24 = load ptr, ptr %16, align 8, !tbaa !16
  %25 = getelementptr inbounds i8, ptr %16, i64 8
  %26 = load i32, ptr %25, align 8, !tbaa !17
  %27 = zext i32 %26 to i64
  %28 = tail call ptr @sdsnewlen(ptr noundef %24, i64 noundef %27) #2
  %29 = tail call { i64, ptr } %9(ptr noundef %28) #2
  %30 = extractvalue { i64, ptr } %29, 0
  %31 = extractvalue { i64, ptr } %29, 1
  %32 = load ptr, ptr %8, align 8, !tbaa !10
  %33 = getelementptr inbounds %struct._json_object_entry, ptr %32, i64 %15, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !11
  %35 = getelementptr inbounds i8, ptr %34, i64 16
  %36 = getelementptr inbounds i8, ptr %34, i64 24
  %37 = load ptr, ptr %36, align 8, !tbaa !10
  %38 = load i32, ptr %35, align 8, !tbaa !10
  %39 = zext i32 %38 to i64
  %40 = tail call ptr @sdsnewlen(ptr noundef %37, i64 noundef %39) #2
  %41 = tail call { i64, ptr } %9(ptr noundef %40) #2
  %42 = extractvalue { i64, ptr } %41, 0
  %43 = extractvalue { i64, ptr } %41, 1
  store i64 %30, ptr %3, align 8
  store ptr %31, ptr %.sroa.42.0..sroa_idx, align 8, !tbaa !18
  store i64 %42, ptr %11, align 8
  store ptr %43, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !18
  tail call void %10(ptr noundef %5, ptr noundef nonnull byval(%struct.otl_GsubSingleEntry) align 8 %3) #2
  %.pre = load i32, ptr %6, align 8, !tbaa !10
  br label %44

44:                                               ; preds = %12, %19, %23
  %45 = phi i32 [ %13, %12 ], [ %13, %19 ], [ %.pre, %23 ]
  %46 = add i16 %.019, 1
  %47 = zext i16 %46 to i32
  %48 = icmp ugt i32 %45, %47
  br i1 %48, label %12, label %._crit_edge, !llvm.loop !19
}

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_single", !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 = !{!7, !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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