; LLVM IR from caryll/otfcc :: lib/table/otl/subtables (gpos-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.subtable_gpos_single = type { i64, i64, ptr }
%struct.otl_GposSingleEntry = type { %struct.otfcc_Handle, %struct.otl_PositionValue }
%struct.otfcc_Handle = type { i32, i16, ptr }
%struct.otl_PositionValue = type { double, double, double, double }

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

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

18:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #3
  br label %42

19:                                               ; preds = %11
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.subtable_gpos_single, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !14
  %24 = load i16, ptr %5, align 2, !tbaa !12
  %25 = zext i16 %24 to i64
  %26 = getelementptr inbounds %struct.otl_GposSingleEntry, ptr %23, i64 %25
  %27 = getelementptr inbounds %struct.otl_GposSingleEntry, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.otfcc_Handle, ptr %27, i32 0, i32 2
  %29 = load ptr, ptr %28, align 8, !tbaa !15
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.subtable_gpos_single, ptr %30, i32 0, i32 2
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = load i16, ptr %5, align 2, !tbaa !12
  %34 = zext i16 %33 to i64
  %35 = getelementptr inbounds %struct.otl_GposSingleEntry, ptr %32, i64 %34
  %36 = getelementptr inbounds %struct.otl_GposSingleEntry, ptr %35, i32 0, i32 1
  %37 = call ptr @gpos_dump_value(ptr noundef byval(%struct.otl_PositionValue) align 8 %36)
  %38 = call ptr @json_object_push(ptr noundef %20, ptr noundef %29, ptr noundef %37)
  br label %39

39:                                               ; preds = %19
  %40 = load i16, ptr %5, align 2, !tbaa !12
  %41 = add i16 %40, 1
  store i16 %41, ptr %5, align 2, !tbaa !12
  br label %11, !llvm.loop !21

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

declare ptr @json_object_new(i64 noundef) #2

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

declare ptr @gpos_dump_value(ptr noundef byval(%struct.otl_PositionValue) align 8) #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, !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}
!17 = !{!"otfcc_Handle", !18, i64 0, !13, i64 4, !6, i64 8}
!18 = !{!"int", !7, i64 0}
!19 = !{!"", !20, i64 0, !20, i64 8, !20, i64 16, !20, i64 24}
!20 = !{!"double", !7, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"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_GposSingleEntry = type { %struct.otfcc_Handle, %struct.otl_PositionValue }
%struct.otfcc_Handle = type { i32, i16, ptr }
%struct.otl_PositionValue = type { double, double, double, double }

; Function Attrs: nounwind uwtable
define dso_local ptr @otl_gpos_dump_single(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) #2
  %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 ], [ %16, %6 ]
  %.011 = phi i16 [ 0, %.lr.ph ], [ %15, %6 ]
  %8 = load ptr, ptr %5, align 8, !tbaa !11
  %9 = getelementptr inbounds %struct.otl_GposSingleEntry, ptr %8, i64 %7
  %10 = getelementptr inbounds i8, ptr %9, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %9, i64 16
  %13 = tail call ptr @gpos_dump_value(ptr noundef nonnull byval(%struct.otl_PositionValue) align 8 %12) #2
  %14 = tail call ptr @json_object_push(ptr noundef %3, ptr noundef %11, ptr noundef %13) #2
  %15 = add i16 %.011, 1
  %16 = zext i16 %15 to i64
  %17 = load i64, ptr %0, align 8, !tbaa !5
  %18 = icmp ugt i64 %17, %16
  br i1 %18, label %6, label %._crit_edge, !llvm.loop !19
}

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 @gpos_dump_value(ptr noundef byval(%struct.otl_PositionValue) align 8) 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 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}
!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, !18, i64 8, !18, i64 16, !18, i64 24}
!18 = !{!"double", !8, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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