; 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.subtable_gsub_single = type { i64, i64, ptr }
%struct.otl_GsubSingleEntry = type { %struct.otfcc_Handle, %struct.otfcc_Handle }
%struct.otfcc_Handle = type { i32, i16, ptr }

; 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_gsub_dump_single(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  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_gsub_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 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !12
  br label %11

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

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

18:                                               ; preds = %11
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.subtable_gsub_single, ptr %20, i32 0, i32 2
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = load i64, ptr %5, align 8, !tbaa !12
  %24 = getelementptr inbounds %struct.otl_GsubSingleEntry, ptr %22, i64 %23
  %25 = getelementptr inbounds %struct.otl_GsubSingleEntry, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds %struct.otfcc_Handle, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !14
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.subtable_gsub_single, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = load i64, ptr %5, align 8, !tbaa !12
  %32 = getelementptr inbounds %struct.otl_GsubSingleEntry, ptr %30, i64 %31
  %33 = getelementptr inbounds %struct.otl_GsubSingleEntry, ptr %32, i32 0, i32 1
  %34 = getelementptr inbounds %struct.otfcc_Handle, ptr %33, i32 0, i32 2
  %35 = load ptr, ptr %34, align 8, !tbaa !19
  %36 = call ptr @json_string_new(ptr noundef %35)
  %37 = call ptr @json_object_push(ptr noundef %19, ptr noundef %27, ptr noundef %36)
  br label %38

38:                                               ; preds = %18
  %39 = load i64, ptr %5, align 8, !tbaa !12
  %40 = add i64 %39, 1
  store i64 %40, ptr %5, align 8, !tbaa !12
  br label %11, !llvm.loop !20

41:                                               ; preds = %17
  %42 = 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 %42
}

declare ptr @json_object_new(i64 noundef) #2

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

declare ptr @json_string_new(ptr noundef) #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 = !{!11, !11, i64 0}
!13 = !{!10, !6, i64 16}
!14 = !{!15, !6, i64 8}
!15 = !{!"", !16, i64 0, !16, i64 16}
!16 = !{!"otfcc_Handle", !17, i64 0, !18, i64 4, !6, i64 8}
!17 = !{!"int", !7, i64 0}
!18 = !{!"short", !7, i64 0}
!19 = !{!15, !6, i64 24}
!20 = distinct !{!20, !21}
!21 = !{!"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_GsubSingleEntry = type { %struct.otfcc_Handle, %struct.otfcc_Handle }
%struct.otfcc_Handle = type { i32, i16, ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @otl_gsub_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
  %.010 = phi i64 [ 0, %.lr.ph ], [ %15, %6 ]
  %7 = load ptr, ptr %5, align 8, !tbaa !11
  %8 = getelementptr inbounds %struct.otl_GsubSingleEntry, ptr %7, i64 %.010
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %8, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !17
  %13 = tail call ptr @json_string_new(ptr noundef %12) #2
  %14 = tail call ptr @json_object_push(ptr noundef %3, ptr noundef %10, ptr noundef %13) #2
  %15 = add nuw i64 %.010, 1
  %16 = load i64, ptr %0, align 8, !tbaa !5
  %17 = icmp ult i64 %15, %16
  br i1 %17, label %6, label %._crit_edge, !llvm.loop !18
}

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 @json_string_new(ptr 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 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, !14, 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 = !{!13, !10, i64 24}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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