; LLVM IR from caryll/otfcc :: lib/table/otl/subtables (gpos-cursive)

; 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.subtable_gpos_cursive = type { i64, i64, ptr }
%struct.otl_GposCursiveEntry = type { %struct.otfcc_Handle, %struct.otl_Anchor, %struct.otl_Anchor }
%struct.otfcc_Handle = type { i32, i16, ptr }
%struct.otl_Anchor = type { i8, double, double }

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 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_gpos_dump_cursive(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
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.subtable_gpos_cursive, ptr %8, i32 0, i32 0
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = call ptr @json_object_new(i64 noundef %10)
  store ptr %11, 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 %12

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

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

20:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %21 = call ptr @json_object_new(i64 noundef 2)
  store ptr %21, ptr %6, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.subtable_gpos_cursive, ptr %23, i32 0, i32 2
  %25 = load ptr, ptr %24, align 8, !tbaa !14
  %26 = load i16, ptr %5, align 2, !tbaa !12
  %27 = zext i16 %26 to i64
  %28 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %25, i64 %27
  %29 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %28, i32 0, i32 1
  %30 = call ptr @otl_dump_anchor(ptr noundef byval(%struct.otl_Anchor) align 8 %29)
  %31 = call ptr @json_object_push(ptr noundef %22, ptr noundef @.str, ptr noundef %30)
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.subtable_gpos_cursive, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !14
  %36 = load i16, ptr %5, align 2, !tbaa !12
  %37 = zext i16 %36 to i64
  %38 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %35, i64 %37
  %39 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %38, i32 0, i32 2
  %40 = call ptr @otl_dump_anchor(ptr noundef byval(%struct.otl_Anchor) align 8 %39)
  %41 = call ptr @json_object_push(ptr noundef %32, ptr noundef @.str.1, ptr noundef %40)
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.subtable_gpos_cursive, ptr %43, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = load i16, ptr %5, align 2, !tbaa !12
  %47 = zext i16 %46 to i64
  %48 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %45, i64 %47
  %49 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds %struct.otfcc_Handle, ptr %49, i32 0, i32 2
  %51 = load ptr, ptr %50, align 8, !tbaa !15
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = call ptr @preserialize(ptr noundef %52)
  %54 = call ptr @json_object_push(ptr noundef %42, ptr noundef %51, ptr noundef %53)
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %55

55:                                               ; preds = %20
  %56 = load i16, ptr %5, align 2, !tbaa !12
  %57 = add i16 %56, 1
  store i16 %57, ptr %5, align 2, !tbaa !12
  br label %12, !llvm.loop !22

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

declare ptr @json_object_new(i64 noundef) #2

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

declare ptr @otl_dump_anchor(ptr noundef byval(%struct.otl_Anchor) align 8) #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 = !{!10, !6, i64 16}
!15 = !{!16, !6, i64 8}
!16 = !{!"", !17, i64 0, !19, i64 16, !19, i64 40}
!17 = !{!"otfcc_Handle", !18, i64 0, !13, i64 4, !6, i64 8}
!18 = !{!"int", !7, i64 0}
!19 = !{!"", !20, i64 0, !21, i64 8, !21, i64 16}
!20 = !{!"_Bool", !7, i64 0}
!21 = !{!"double", !7, i64 0}
!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.otl_GposCursiveEntry = type { %struct.otfcc_Handle, %struct.otl_Anchor, %struct.otl_Anchor }
%struct.otfcc_Handle = type { i32, i16, ptr }
%struct.otl_Anchor = type { i8, double, double }

@.str = external hidden unnamed_addr constant [6 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local ptr @otl_gpos_dump_cursive(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) #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 = getelementptr inbounds i8, ptr %0, i64 16
  br label %6

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

6:                                                ; preds = %.lr.ph, %6
  %7 = phi i64 [ 0, %.lr.ph ], [ %23, %6 ]
  %.016 = phi i16 [ 0, %.lr.ph ], [ %22, %6 ]
  %8 = tail call ptr @json_object_new(i64 noundef 2) #3
  %9 = load ptr, ptr %5, align 8, !tbaa !11
  %10 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %9, i64 %7, i32 1
  %11 = tail call ptr @otl_dump_anchor(ptr noundef nonnull byval(%struct.otl_Anchor) align 8 %10) #3
  %12 = tail call ptr @json_object_push(ptr noundef %8, ptr noundef nonnull @.str, ptr noundef %11) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !11
  %14 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %13, i64 %7, i32 2
  %15 = tail call ptr @otl_dump_anchor(ptr noundef nonnull byval(%struct.otl_Anchor) align 8 %14) #3
  %16 = tail call ptr @json_object_push(ptr noundef %8, ptr noundef nonnull @.str.1, ptr noundef %15) #3
  %17 = load ptr, ptr %5, align 8, !tbaa !11
  %18 = getelementptr inbounds %struct.otl_GposCursiveEntry, ptr %17, i64 %7, i32 0, i32 2
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = tail call ptr @preserialize(ptr noundef %8)
  %21 = tail call ptr @json_object_push(ptr noundef %3, ptr noundef %19, ptr noundef %20) #3
  %22 = add i16 %.016, 1
  %23 = zext i16 %22 to i64
  %24 = load i64, ptr %0, align 8, !tbaa !5
  %25 = icmp ugt i64 %24, %23
  br i1 %25, label %6, 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

declare ptr @otl_dump_anchor(ptr noundef byval(%struct.otl_Anchor) align 8) 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 8}
!13 = !{!"", !14, i64 0, !17, i64 16, !17, i64 40}
!14 = !{!"otfcc_Handle", !15, i64 0, !16, i64 4, !10, i64 8}
!15 = !{!"int", !8, i64 0}
!16 = !{!"short", !8, i64 0}
!17 = !{!"", !18, i64 0, !19, i64 8, !19, i64 16}
!18 = !{!"_Bool", !8, i64 0}
!19 = !{!"double", !8, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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