; LLVM IR from caryll/otfcc :: lib/table (fpgm-prep)

; 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_table_fpgm_prep = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.otfcc_Packet = type { i32, i16, i16, i16, i16, ptr }
%struct.otfcc_PacketPiece = type { i32, i32, i32, i32, ptr }
%struct.table_fpgm_prep = type { ptr, i32, ptr }

@table_iFpgm_prep = external dso_local constant %struct.__caryll_elementinterface_table_fpgm_prep, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @otfcc_readFpgmPrep(ptr noundef byval(%struct.otfcc_Packet) align 8 %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.otfcc_PacketPiece, align 8
  %13 = alloca i32, align 4
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 1, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %16

16:                                               ; preds = %101, %3
  %17 = load i32, ptr %10, align 4, !tbaa !9
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %28

19:                                               ; preds = %16
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %28

22:                                               ; preds = %19
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = getelementptr inbounds %struct.otfcc_Packet, ptr %0, i32 0, i32 1
  %25 = load i16, ptr %24, align 4, !tbaa !11
  %26 = zext i16 %25 to i32
  %27 = icmp slt i32 %23, %26
  br label %28

28:                                               ; preds = %22, %19, %16
  %29 = phi i1 [ false, %19 ], [ false, %16 ], [ %27, %22 ]
  br i1 %29, label %31, label %30

30:                                               ; preds = %28
  store i32 2, ptr %11, align 4
  br label %108

31:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 24, ptr %12) #4
  %32 = getelementptr inbounds %struct.otfcc_Packet, ptr %0, i32 0, i32 5
  %33 = load ptr, ptr %32, align 8, !tbaa !14
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %struct.otfcc_PacketPiece, ptr %33, i64 %35
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %36, i64 24, i1 false), !tbaa.struct !15
  br label %37

37:                                               ; preds = %93, %31
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %41, label %40

40:                                               ; preds = %37
  store i32 5, ptr %11, align 4
  br label %98

41:                                               ; preds = %37
  %42 = getelementptr inbounds %struct.otfcc_PacketPiece, ptr %12, i32 0, i32 0
  %43 = load i32, ptr %42, align 8, !tbaa !16
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = icmp eq i32 %43, %44
  br i1 %45, label %46, label %92

46:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 1, ptr %13, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %88, %46
  %48 = load i32, ptr %13, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  store i32 8, ptr %11, align 4
  br label %89

51:                                               ; preds = %47
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %52 = getelementptr inbounds %struct.otfcc_PacketPiece, ptr %12, i32 0, i32 4
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  store ptr %53, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %54 = getelementptr inbounds %struct.otfcc_PacketPiece, ptr %12, i32 0, i32 3
  %55 = load i32, ptr %54, align 4, !tbaa !19
  store i32 %55, ptr %15, align 4, !tbaa !9
  %56 = load ptr, ptr getelementptr inbounds (%struct.__caryll_elementinterface_table_fpgm_prep, ptr @table_iFpgm_prep, i32 0, i32 6), align 8, !tbaa !20
  %57 = call ptr (...) %56()
  store ptr %57, ptr %7, align 8, !tbaa !5
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.table_fpgm_prep, ptr %58, i32 0, i32 0
  store ptr null, ptr %59, align 8, !tbaa !22
  %60 = load i32, ptr %15, align 4, !tbaa !9
  %61 = load ptr, ptr %7, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.table_fpgm_prep, ptr %61, i32 0, i32 1
  store i32 %60, ptr %62, align 8, !tbaa !24
  %63 = load i32, ptr %15, align 4, !tbaa !9
  %64 = zext i32 %63 to i64
  %65 = mul i64 1, %64
  %66 = call ptr @__caryll_allocate_clean(i64 noundef %65, i64 noundef 22)
  %67 = load ptr, ptr %7, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.table_fpgm_prep, ptr %67, i32 0, i32 2
  store ptr %66, ptr %68, align 8, !tbaa !25
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.table_fpgm_prep, ptr %69, i32 0, i32 2
  %71 = load ptr, ptr %70, align 8, !tbaa !25
  %72 = icmp ne ptr %71, null
  br i1 %72, label %74, label %73

73:                                               ; preds = %51
  br label %82

74:                                               ; preds = %51
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.table_fpgm_prep, ptr %75, i32 0, i32 2
  %77 = load ptr, ptr %76, align 8, !tbaa !25
  %78 = load ptr, ptr %14, align 8, !tbaa !5
  %79 = load i32, ptr %15, align 4, !tbaa !9
  %80 = zext i32 %79 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %77, ptr align 1 %78, i64 %80, i1 false)
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %81, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %85

82:                                               ; preds = %73
  %83 = load ptr, ptr getelementptr inbounds (%struct.__caryll_elementinterface_table_fpgm_prep, ptr @table_iFpgm_prep, i32 0, i32 7), align 8, !tbaa !26
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  call void %83(ptr noundef %84)
  store ptr null, ptr %7, align 8, !tbaa !5
  store i32 0, ptr %11, align 4
  br label %85

85:                                               ; preds = %82, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %86 = load i32, ptr %11, align 4
  switch i32 %86, label %89 [
    i32 0, label %87
  ]

87:                                               ; preds = %85
  br label %88

88:                                               ; preds = %87
  store i32 0, ptr %13, align 4, !tbaa !9
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %47, !llvm.loop !27

89:                                               ; preds = %85, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  %90 = load i32, ptr %11, align 4
  switch i32 %90, label %98 [
    i32 8, label %91
  ]

91:                                               ; preds = %89
  br label %92

92:                                               ; preds = %91, %41
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr %8, align 4, !tbaa !9
  %95 = icmp ne i32 %94, 0
  %96 = xor i1 %95, true
  %97 = zext i1 %96 to i32
  store i32 %97, ptr %8, align 4, !tbaa !9
  br label %37, !llvm.loop !29

98:                                               ; preds = %89, %40
  call void @llvm.lifetime.end.p0(i64 24, ptr %12) #4
  %99 = load i32, ptr %11, align 4
  switch i32 %99, label %108 [
    i32 5, label %100
  ]

100:                                              ; preds = %98
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %8, align 4, !tbaa !9
  %103 = icmp ne i32 %102, 0
  %104 = xor i1 %103, true
  %105 = zext i1 %104 to i32
  store i32 %105, ptr %8, align 4, !tbaa !9
  %106 = load i32, ptr %9, align 4, !tbaa !9
  %107 = add nsw i32 %106, 1
  store i32 %107, ptr %9, align 4, !tbaa !9
  br label %16, !llvm.loop !30

108:                                              ; preds = %98, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %109 = load i32, ptr %11, align 4
  switch i32 %109, label %111 [
    i32 2, label %110
  ]

110:                                              ; preds = %108
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %111

111:                                              ; preds = %110, %108
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %112 = load ptr, ptr %4, align 8
  ret ptr %112
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 4}
!12 = !{!"", !10, i64 0, !13, i64 4, !13, i64 6, !13, i64 8, !13, i64 10, !6, i64 16}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !6, i64 16}
!15 = !{i64 0, i64 4, !9, i64 4, i64 4, !9, i64 8, i64 4, !9, i64 12, i64 4, !9, i64 16, i64 8, !5}
!16 = !{!17, !10, i64 0}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !6, i64 16}
!18 = !{!17, !6, i64 16}
!19 = !{!17, !10, i64 12}
!20 = !{!21, !6, i64 48}
!21 = !{!"__caryll_elementinterface_table_fpgm_prep", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56}
!22 = !{!23, !6, i64 0}
!23 = !{!"", !6, i64 0, !10, i64 8, !6, i64 16}
!24 = !{!23, !10, i64 8}
!25 = !{!23, !6, i64 16}
!26 = !{!21, !6, i64 56}
!27 = distinct !{!27, !28}
!28 = !{!"llvm.loop.mustprogress"}
!29 = distinct !{!29, !28}
!30 = distinct !{!30, !28}


; 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_table_fpgm_prep = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.otfcc_Packet = type { i32, i16, i16, i16, i16, ptr }
%struct.otfcc_PacketPiece = type { i32, i32, i32, i32, ptr }

@table_iFpgm_prep = external dso_local local_unnamed_addr constant %struct.__caryll_elementinterface_table_fpgm_prep, align 8

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @otfcc_readFpgmPrep(ptr nocapture noundef readonly byval(%struct.otfcc_Packet) align 8 %0, ptr nocapture noundef readnone %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 4
  %5 = load i16, ptr %4, align 4
  %.not = icmp eq i16 %5, 0
  br i1 %.not, label %.critedge, label %.lr.ph93

.lr.ph93:                                         ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 16
  %7 = load ptr, ptr getelementptr inbounds (i8, ptr @table_iFpgm_prep, i64 48), align 8
  %8 = load ptr, ptr getelementptr inbounds (i8, ptr @table_iFpgm_prep, i64 56), align 8
  %.pre = load ptr, ptr %6, align 8, !tbaa !5
  %9 = zext i16 %5 to i64
  br label %10

10:                                               ; preds = %.lr.ph93, %.thread53
  %indvars.iv = phi i64 [ 0, %.lr.ph93 ], [ %indvars.iv.next, %.thread53 ]
  %11 = getelementptr inbounds %struct.otfcc_PacketPiece, ptr %.pre, i64 %indvars.iv
  %.sroa.0.0.copyload = load i32, ptr %11, align 8, !tbaa !12
  %.not108 = icmp eq i32 %.sroa.0.0.copyload, %2
  br i1 %.not108, label %.split.us, label %.thread53

.split.us:                                        ; preds = %10
  %.sroa.48.0..sroa_idx.le = getelementptr inbounds i8, ptr %11, i64 12
  %.sroa.48.0.copyload.le = load i32, ptr %.sroa.48.0..sroa_idx.le, align 4, !tbaa !12
  %.sroa.5.0..sroa_idx.le = getelementptr inbounds i8, ptr %11, i64 16
  %.sroa.5.0.copyload.le = load ptr, ptr %.sroa.5.0..sroa_idx.le, align 8, !tbaa !13
  %12 = zext i32 %.sroa.48.0.copyload.le to i64
  %13 = tail call ptr (...) %7() #3
  store ptr null, ptr %13, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %13, i64 8
  store i32 %.sroa.48.0.copyload.le, ptr %14, align 8, !tbaa !16
  %15 = tail call ptr @__caryll_allocate_clean(i64 noundef %12, i64 noundef 22)
  %16 = getelementptr inbounds i8, ptr %13, i64 16
  store ptr %15, ptr %16, align 8, !tbaa !17
  %.not45.us7585 = icmp eq ptr %15, null
  br i1 %.not45.us7585, label %.thread53.thread, label %.split69.us

.thread53.thread:                                 ; preds = %.split.us
  tail call void %8(ptr noundef nonnull %13) #3
  br label %.critedge

.split69.us:                                      ; preds = %.split.us
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %15, ptr align 1 %.sroa.5.0.copyload.le, i64 %12, i1 false)
  br label %.critedge

.thread53:                                        ; preds = %10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %17 = icmp ult i64 %indvars.iv.next, %9
  br i1 %17, label %10, label %.critedge, !llvm.loop !18

.critedge:                                        ; preds = %.thread53, %.thread53.thread, %.split69.us, %3
  %18 = phi ptr [ %13, %.split69.us ], [ null, %3 ], [ null, %.thread53.thread ], [ null, %.thread53 ]
  ret ptr %18
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @__caryll_allocate_clean(i64 noundef, i64 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 16}
!6 = !{!"", !7, i64 0, !10, i64 4, !10, i64 6, !10, i64 8, !10, i64 10, !11, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !11, i64 0}
!15 = !{!"", !11, i64 0, !7, i64 8, !11, i64 16}
!16 = !{!15, !7, i64 8}
!17 = !{!15, !11, i64 16}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


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