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

; 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_gsub_reverse = type { 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._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.3 = type { i32, ptr }
%struct.subtable_gsub_reverse = type { i16, i16, ptr, ptr }

@iSubtable_gsub_reverse = external dso_local constant %struct.__caryll_elementinterface_subtable_gsub_reverse, align 8
@otl_iCoverage = external constant %struct.__otfcc_ICoverage, align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 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
define dso_local ptr @otl_gsub_parse_reverse(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i16, align 2
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = call ptr @json_obj_get_type(ptr noundef %11, ptr noundef @.str, i32 noundef 2)
  store ptr %12, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call ptr @json_obj_get_type(ptr noundef %13, ptr noundef @.str.1, i32 noundef 2)
  store ptr %14, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %20

17:                                               ; preds = %2
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %21, label %20

20:                                               ; preds = %17, %2
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %80

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %22 = load ptr, ptr getelementptr inbounds (%struct.__caryll_elementinterface_subtable_gsub_reverse, ptr @iSubtable_gsub_reverse, i32 0, i32 6), align 8, !tbaa !9
  %23 = call ptr (...) %22()
  store ptr %23, ptr %9, align 8, !tbaa !5
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct._json_value, ptr %24, i32 0, i32 2
  %26 = getelementptr inbounds %struct.anon.3, ptr %25, i32 0, i32 0
  %27 = load i32, ptr %26, align 8, !tbaa !11
  %28 = trunc i32 %27 to i16
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.subtable_gsub_reverse, ptr %29, i32 0, i32 0
  store i16 %28, ptr %30, align 8, !tbaa !12
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.subtable_gsub_reverse, ptr %31, i32 0, i32 0
  %33 = load i16, ptr %32, align 8, !tbaa !12
  %34 = zext i16 %33 to i64
  %35 = mul i64 8, %34
  %36 = call ptr @__caryll_allocate_clean(i64 noundef %35, i64 noundef 100)
  %37 = load ptr, ptr %9, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.subtable_gsub_reverse, ptr %37, i32 0, i32 2
  store ptr %36, ptr %38, align 8, !tbaa !15
  %39 = load ptr, ptr %4, align 8, !tbaa !5
  %40 = call double @json_obj_getnum_fallback(ptr noundef %39, ptr noundef @.str.2, double noundef 0.000000e+00)
  %41 = fptoui double %40 to i16
  %42 = load ptr, ptr %9, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.subtable_gsub_reverse, ptr %42, i32 0, i32 1
  store i16 %41, ptr %43, align 2, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 2, ptr %10) #3
  store i16 0, ptr %10, align 2, !tbaa !17
  br label %44

44:                                               ; preds = %70, %21
  %45 = load i16, ptr %10, align 2, !tbaa !17
  %46 = zext i16 %45 to i32
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.subtable_gsub_reverse, ptr %47, i32 0, i32 0
  %49 = load i16, ptr %48, align 8, !tbaa !12
  %50 = zext i16 %49 to i32
  %51 = icmp slt i32 %46, %50
  br i1 %51, label %53, label %52

52:                                               ; preds = %44
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 2, ptr %10) #3
  br label %73

53:                                               ; preds = %44
  %54 = load ptr, ptr getelementptr inbounds (%struct.__otfcc_ICoverage, ptr @otl_iCoverage, i32 0, i32 11), align 8, !tbaa !18
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct._json_value, ptr %55, i32 0, i32 2
  %57 = getelementptr inbounds %struct.anon.3, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !11
  %59 = load i16, ptr %10, align 2, !tbaa !17
  %60 = zext i16 %59 to i64
  %61 = getelementptr inbounds ptr, ptr %58, i64 %60
  %62 = load ptr, ptr %61, align 8, !tbaa !5
  %63 = call ptr %54(ptr noundef %62)
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.subtable_gsub_reverse, ptr %64, i32 0, i32 2
  %66 = load ptr, ptr %65, align 8, !tbaa !15
  %67 = load i16, ptr %10, align 2, !tbaa !17
  %68 = zext i16 %67 to i64
  %69 = getelementptr inbounds ptr, ptr %66, i64 %68
  store ptr %63, ptr %69, align 8, !tbaa !5
  br label %70

70:                                               ; preds = %53
  %71 = load i16, ptr %10, align 2, !tbaa !17
  %72 = add i16 %71, 1
  store i16 %72, ptr %10, align 2, !tbaa !17
  br label %44, !llvm.loop !20

73:                                               ; preds = %52
  %74 = load ptr, ptr getelementptr inbounds (%struct.__otfcc_ICoverage, ptr @otl_iCoverage, i32 0, i32 11), align 8, !tbaa !18
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = call ptr %74(ptr noundef %75)
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.subtable_gsub_reverse, ptr %77, i32 0, i32 3
  store ptr %76, ptr %78, align 8, !tbaa !22
  %79 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %79, ptr %3, align 8
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %80

80:                                               ; preds = %73, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %81 = load ptr, ptr %3, align 8
  ret ptr %81
}

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

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

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 = { 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_elementinterface_subtable_gsub_reverse", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"", !14, i64 0, !14, i64 2, !6, i64 8, !6, i64 16}
!14 = !{!"short", !7, i64 0}
!15 = !{!13, !6, i64 8}
!16 = !{!13, !14, i64 2}
!17 = !{!14, !14, i64 0}
!18 = !{!19, !6, i64 88}
!19 = !{!"__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}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!13, !6, i64 16}


; 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_gsub_reverse = type { 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 }

@iSubtable_gsub_reverse = external dso_local local_unnamed_addr constant %struct.__caryll_elementinterface_subtable_gsub_reverse, align 8
@otl_iCoverage = external local_unnamed_addr constant %struct.__otfcc_ICoverage, align 8
@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [11 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
define dso_local noundef ptr @otl_gsub_parse_reverse(ptr noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #1 {
  %3 = tail call ptr @json_obj_get_type(ptr noundef %0, ptr noundef nonnull @.str, i32 noundef 2)
  %4 = tail call ptr @json_obj_get_type(ptr noundef %0, ptr noundef nonnull @.str.1, i32 noundef 2)
  %5 = icmp ne ptr %3, null
  %6 = icmp ne ptr %4, null
  %or.cond = select i1 %5, i1 %6, i1 false
  br i1 %or.cond, label %7, label %34

7:                                                ; preds = %2
  %8 = load ptr, ptr getelementptr inbounds (i8, ptr @iSubtable_gsub_reverse, i64 48), align 8, !tbaa !5
  %9 = tail call ptr (...) %8() #2
  %10 = getelementptr inbounds i8, ptr %3, i64 16
  %11 = load i32, ptr %10, align 8, !tbaa !10
  %12 = trunc i32 %11 to i16
  store i16 %12, ptr %9, align 8, !tbaa !11
  %.mask = shl i32 %11, 3
  %13 = and i32 %.mask, 524280
  %14 = zext nneg i32 %13 to i64
  %15 = tail call ptr @__caryll_allocate_clean(i64 noundef %14, i64 noundef 100)
  %16 = getelementptr inbounds i8, ptr %9, i64 8
  store ptr %15, ptr %16, align 8, !tbaa !14
  %17 = tail call double @json_obj_getnum_fallback(ptr noundef %0, ptr noundef nonnull @.str.2, double noundef 0.000000e+00)
  %18 = fptoui double %17 to i16
  %19 = getelementptr inbounds i8, ptr %9, i64 2
  store i16 %18, ptr %19, align 2, !tbaa !15
  %20 = load i16, ptr %9, align 8, !tbaa !11
  %.not = icmp eq i16 %20, 0
  %.pre = load ptr, ptr getelementptr inbounds (i8, ptr @otl_iCoverage, i64 88), align 8, !tbaa !16
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %7
  %21 = getelementptr inbounds i8, ptr %3, i64 24
  br label %24

._crit_edge:                                      ; preds = %24, %7
  %22 = tail call ptr %.pre(ptr noundef nonnull %4) #2
  %23 = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %22, ptr %23, align 8, !tbaa !18
  br label %34

24:                                               ; preds = %.lr.ph, %24
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %24 ]
  %25 = load ptr, ptr %21, align 8, !tbaa !10
  %26 = getelementptr inbounds ptr, ptr %25, i64 %indvars.iv
  %27 = load ptr, ptr %26, align 8, !tbaa !19
  %28 = tail call ptr %.pre(ptr noundef %27) #2
  %29 = load ptr, ptr %16, align 8, !tbaa !14
  %30 = getelementptr inbounds ptr, ptr %29, i64 %indvars.iv
  store ptr %28, ptr %30, align 8, !tbaa !19
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load i16, ptr %9, align 8, !tbaa !11
  %32 = zext i16 %31 to i64
  %33 = icmp ult i64 %indvars.iv.next, %32
  br i1 %33, label %24, label %._crit_edge, !llvm.loop !20

34:                                               ; preds = %2, %._crit_edge
  %.021 = phi ptr [ %9, %._crit_edge ], [ null, %2 ]
  ret ptr %.021
}

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

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

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 = { 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_gsub_reverse", !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 = !{!8, !8, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 2, !7, i64 8, !7, i64 16}
!13 = !{!"short", !8, i64 0}
!14 = !{!12, !7, i64 8}
!15 = !{!12, !13, i64 2}
!16 = !{!17, !7, i64 88}
!17 = !{!"__otfcc_ICoverage", !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}
!18 = !{!12, !7, i64 16}
!19 = !{!7, !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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