; LLVM IR from caryll/otfcc :: lib/table/glyf (glyf)

; 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.table_glyf = type { i64, i64, ptr }
%struct.glyf_Glyph = type { ptr, %struct.VQ, %struct.VQ, %struct.VQ, %struct.VQ, %struct.glyf_ContourList, %struct.glyf_ReferenceList, %struct.glyf_StemDefList, %struct.glyf_StemDefList, %struct.glyf_MaskList, %struct.glyf_MaskList, i16, ptr, i8, %struct.otfcc_Handle, i16, %struct.glyf_GlyphStat }
%struct.VQ = type { double, %struct.vq_SegList }
%struct.vq_SegList = type { i64, i64, ptr }
%struct.glyf_ContourList = type { i64, i64, ptr }
%struct.glyf_ReferenceList = type { i64, i64, ptr }
%struct.glyf_StemDefList = type { i64, i64, ptr }
%struct.glyf_MaskList = type { i64, i64, ptr }
%struct.otfcc_Handle = type { i32, i16, ptr }
%struct.glyf_GlyphStat = type { double, double, double, double, i16, i16, i16, i16, i16 }

@.str = external hidden unnamed_addr constant [12 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 void @otfcc_dump_glyphorder(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
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %10, label %9

9:                                                ; preds = %2
  br label %55

10:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.table_glyf, ptr %11, i32 0, i32 0
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = call ptr @json_array_new(i64 noundef %13)
  store ptr %14, 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 !12
  br label %15

15:                                               ; preds = %47, %10
  %16 = load i16, ptr %6, align 2, !tbaa !12
  %17 = zext i16 %16 to i64
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.table_glyf, ptr %18, i32 0, i32 0
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = icmp ult i64 %17, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #4
  br label %50

23:                                               ; preds = %15
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.table_glyf, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = load i16, ptr %6, align 2, !tbaa !12
  %29 = zext i16 %28 to i64
  %30 = getelementptr inbounds ptr, ptr %27, i64 %29
  %31 = load ptr, ptr %30, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.glyf_Glyph, ptr %31, i32 0, i32 0
  %33 = load ptr, ptr %32, align 8, !tbaa !15
  %34 = call i64 @sdslen(ptr noundef %33)
  %35 = trunc i64 %34 to i32
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.table_glyf, ptr %36, i32 0, i32 2
  %38 = load ptr, ptr %37, align 8, !tbaa !14
  %39 = load i16, ptr %6, align 2, !tbaa !12
  %40 = zext i16 %39 to i64
  %41 = getelementptr inbounds ptr, ptr %38, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.glyf_Glyph, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = call ptr @json_string_new_length(i32 noundef %35, ptr noundef %44)
  %46 = call ptr @json_array_push(ptr noundef %24, ptr noundef %45)
  br label %47

47:                                               ; preds = %23
  %48 = load i16, ptr %6, align 2, !tbaa !12
  %49 = add i16 %48, 1
  store i16 %49, ptr %6, align 2, !tbaa !12
  br label %15, !llvm.loop !22

50:                                               ; preds = %22
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = call ptr @preserialize(ptr noundef %52)
  %54 = call ptr @json_object_push(ptr noundef %51, ptr noundef @.str, ptr noundef %53)
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %55

55:                                               ; preds = %50, %9
  ret void
}

declare ptr @json_array_new(i64 noundef) #2

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

declare ptr @json_string_new_length(i32 noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @sdslen(ptr noundef) #3

declare ptr @json_object_push(ptr noundef, ptr noundef, ptr noundef) #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 0}
!16 = !{!"", !6, i64 0, !17, i64 8, !17, i64 40, !17, i64 72, !17, i64 104, !10, i64 136, !10, i64 160, !10, i64 184, !10, i64 208, !10, i64 232, !10, i64 256, !13, i64 280, !6, i64 288, !7, i64 296, !19, i64 304, !13, i64 320, !21, i64 328}
!17 = !{!"", !18, i64 0, !10, i64 8}
!18 = !{!"double", !7, i64 0}
!19 = !{!"otfcc_Handle", !20, i64 0, !13, i64 4, !6, i64 8}
!20 = !{!"int", !7, i64 0}
!21 = !{!"", !18, i64 0, !18, i64 8, !18, i64 16, !18, i64 24, !13, i64 32, !13, i64 34, !13, i64 36, !13, i64 38, !13, i64 40}
!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"

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

; Function Attrs: nounwind uwtable
define dso_local void @otfcc_dump_glyphorder(ptr noundef readonly %0, ptr noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %28, label %3

3:                                                ; preds = %2
  %4 = load i64, ptr %0, align 8, !tbaa !5
  %5 = tail call ptr @json_array_new(i64 noundef %4) #3
  %6 = load i64, ptr %0, align 8, !tbaa !5
  %.not14 = icmp eq i64 %6, 0
  br i1 %.not14, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  br label %10

._crit_edge:                                      ; preds = %10, %3
  %8 = tail call ptr @preserialize(ptr noundef %5)
  %9 = tail call ptr @json_object_push(ptr noundef %1, ptr noundef nonnull @.str, ptr noundef %8) #3
  br label %28

10:                                               ; preds = %.lr.ph, %10
  %11 = phi i64 [ 0, %.lr.ph ], [ %25, %10 ]
  %.013 = phi i16 [ 0, %.lr.ph ], [ %24, %10 ]
  %12 = load ptr, ptr %7, align 8, !tbaa !11
  %13 = getelementptr inbounds ptr, ptr %12, i64 %11
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = tail call i64 @sdslen(ptr noundef %15)
  %17 = trunc i64 %16 to i32
  %18 = load ptr, ptr %7, align 8, !tbaa !11
  %19 = getelementptr inbounds ptr, ptr %18, i64 %11
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  %22 = tail call ptr @json_string_new_length(i32 noundef %17, ptr noundef %21) #3
  %23 = tail call ptr @json_array_push(ptr noundef %5, ptr noundef %22) #3
  %24 = add i16 %.013, 1
  %25 = zext i16 %24 to i64
  %26 = load i64, ptr %0, align 8, !tbaa !5
  %27 = icmp ugt i64 %26, %25
  br i1 %27, label %10, label %._crit_edge, !llvm.loop !21

28:                                               ; preds = %2, %._crit_edge
  ret void
}

declare ptr @json_array_new(i64 noundef) local_unnamed_addr #1

declare ptr @json_array_push(ptr noundef, ptr noundef) local_unnamed_addr #1

declare ptr @json_string_new_length(i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @sdslen(ptr noundef) local_unnamed_addr #2

declare ptr @json_object_push(ptr noundef, ptr noundef, ptr noundef) 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 = !{!10, !10, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !15, i64 8, !15, i64 40, !15, i64 72, !15, i64 104, !6, i64 136, !6, i64 160, !6, i64 184, !6, i64 208, !6, i64 232, !6, i64 256, !17, i64 280, !10, i64 288, !8, i64 296, !18, i64 304, !17, i64 320, !20, i64 328}
!15 = !{!"", !16, i64 0, !6, i64 8}
!16 = !{!"double", !8, i64 0}
!17 = !{!"short", !8, i64 0}
!18 = !{!"otfcc_Handle", !19, i64 0, !17, i64 4, !10, i64 8}
!19 = !{!"int", !8, i64 0}
!20 = !{!"", !16, i64 0, !16, i64 8, !16, i64 16, !16, i64 24, !17, i64 32, !17, i64 34, !17, i64 36, !17, i64 38, !17, i64 40}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


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