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

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

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

13:                                               ; preds = %91, %2
  %14 = load i32, ptr %7, align 4, !tbaa !9
  %15 = icmp ne i32 %14, 0
  br i1 %15, label %16, label %25

16:                                               ; preds = %13
  %17 = load i32, ptr %5, align 4, !tbaa !9
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %19, label %25

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

25:                                               ; preds = %19, %16, %13
  %26 = phi i1 [ false, %16 ], [ false, %13 ], [ %24, %19 ]
  br i1 %26, label %28, label %27

27:                                               ; preds = %25
  store i32 2, ptr %8, align 4
  br label %98

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

34:                                               ; preds = %83, %28
  %35 = load i32, ptr %5, align 4, !tbaa !9
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %38, label %37

37:                                               ; preds = %34
  store i32 5, ptr %8, align 4
  br label %88

38:                                               ; preds = %34
  %39 = getelementptr inbounds %struct.otfcc_PacketPiece, ptr %9, i32 0, i32 0
  %40 = load i32, ptr %39, align 8, !tbaa !16
  %41 = icmp eq i32 %40, 1280594760
  br i1 %41, label %42, label %82

42:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %78, %42
  %44 = load i32, ptr %10, align 4, !tbaa !9
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %47, label %46

46:                                               ; preds = %43
  store i32 8, ptr %8, align 4
  br label %79

47:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %48 = getelementptr inbounds %struct.otfcc_PacketPiece, ptr %9, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !18
  store ptr %49, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %50 = call ptr @__caryll_allocate_clean(i64 noundef 16, i64 noundef 15)
  store ptr %50, ptr %12, align 8, !tbaa !5
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = call zeroext i16 @read_16u(ptr noundef %51)
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.table_LTSH, ptr %53, i32 0, i32 0
  store i16 %52, ptr %54, align 8, !tbaa !19
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = getelementptr inbounds i8, ptr %55, i64 2
  %57 = call zeroext i16 @read_16u(ptr noundef %56)
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.table_LTSH, ptr %58, i32 0, i32 1
  store i16 %57, ptr %59, align 2, !tbaa !21
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.table_LTSH, ptr %60, i32 0, i32 1
  %62 = load i16, ptr %61, align 2, !tbaa !21
  %63 = zext i16 %62 to i64
  %64 = mul i64 1, %63
  %65 = call ptr @__caryll_allocate_clean(i64 noundef %64, i64 noundef 18)
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.table_LTSH, ptr %66, i32 0, i32 2
  store ptr %65, ptr %67, align 8, !tbaa !22
  %68 = load ptr, ptr %12, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.table_LTSH, ptr %68, i32 0, i32 2
  %70 = load ptr, ptr %69, align 8, !tbaa !22
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = getelementptr inbounds i8, ptr %71, i64 4
  %73 = load ptr, ptr %12, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.table_LTSH, ptr %73, i32 0, i32 1
  %75 = load i16, ptr %74, align 2, !tbaa !21
  %76 = zext i16 %75 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %70, ptr align 1 %72, i64 %76, i1 false)
  %77 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %77, ptr %3, align 8
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %79

78:                                               ; No predecessors!
  store i32 0, ptr %10, align 4, !tbaa !9
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %43, !llvm.loop !23

79:                                               ; preds = %47, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  %80 = load i32, ptr %8, align 4
  switch i32 %80, label %88 [
    i32 8, label %81
  ]

81:                                               ; preds = %79
  br label %82

82:                                               ; preds = %81, %38
  br label %83

83:                                               ; preds = %82
  %84 = load i32, ptr %5, align 4, !tbaa !9
  %85 = icmp ne i32 %84, 0
  %86 = xor i1 %85, true
  %87 = zext i1 %86 to i32
  store i32 %87, ptr %5, align 4, !tbaa !9
  br label %34, !llvm.loop !25

88:                                               ; preds = %79, %37
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #4
  %89 = load i32, ptr %8, align 4
  switch i32 %89, label %98 [
    i32 5, label %90
  ]

90:                                               ; preds = %88
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %5, align 4, !tbaa !9
  %93 = icmp ne i32 %92, 0
  %94 = xor i1 %93, true
  %95 = zext i1 %94 to i32
  store i32 %95, ptr %5, align 4, !tbaa !9
  %96 = load i32, ptr %6, align 4, !tbaa !9
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %6, align 4, !tbaa !9
  br label %13, !llvm.loop !26

98:                                               ; preds = %88, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %99 = load i32, ptr %8, align 4
  switch i32 %99, label %103 [
    i32 2, label %100
    i32 1, label %101
  ]

100:                                              ; preds = %98
  store ptr null, ptr %3, align 8
  br label %101

101:                                              ; preds = %100, %98
  %102 = load ptr, ptr %3, align 8
  ret ptr %102

103:                                              ; preds = %98
  unreachable
}

; 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: inlinehint nounwind uwtable
declare hidden zeroext i16 @read_16u(ptr 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 = !{!20, !13, i64 0}
!20 = !{!"", !13, i64 0, !13, i64 2, !6, i64 8}
!21 = !{!20, !13, i64 2}
!22 = !{!20, !6, i64 8}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}
!25 = distinct !{!25, !24}
!26 = distinct !{!26, !24}


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

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

.critedge37.lr.ph:                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !5
  %wide.trip.count = zext i16 %4 to i64
  br label %.critedge37

7:                                                ; preds = %.critedge37
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge, label %.critedge37, !llvm.loop !12

.critedge37:                                      ; preds = %.critedge37.lr.ph, %7
  %indvars.iv = phi i64 [ 0, %.critedge37.lr.ph ], [ %indvars.iv.next, %7 ]
  %8 = getelementptr inbounds %struct.otfcc_PacketPiece, ptr %6, i64 %indvars.iv
  %.sroa.0.0.copyload = load i32, ptr %8, align 8, !tbaa !14
  %9 = icmp eq i32 %.sroa.0.0.copyload, 1280594760
  br i1 %9, label %.thread, label %7, !llvm.loop !15

.thread:                                          ; preds = %.critedge37
  %.sroa.412.0..sroa_idx = getelementptr inbounds i8, ptr %8, i64 16
  %.sroa.412.0.copyload = load ptr, ptr %.sroa.412.0..sroa_idx, align 8, !tbaa !16
  %10 = tail call ptr @__caryll_allocate_clean(i64 noundef 16, i64 noundef 15)
  %11 = tail call zeroext i16 @read_16u(ptr noundef %.sroa.412.0.copyload)
  store i16 %11, ptr %10, align 8, !tbaa !17
  %12 = getelementptr inbounds i8, ptr %.sroa.412.0.copyload, i64 2
  %13 = tail call zeroext i16 @read_16u(ptr noundef nonnull %12)
  %14 = getelementptr inbounds i8, ptr %10, i64 2
  store i16 %13, ptr %14, align 2, !tbaa !19
  %15 = zext i16 %13 to i64
  %16 = tail call ptr @__caryll_allocate_clean(i64 noundef %15, i64 noundef 18)
  %17 = getelementptr inbounds i8, ptr %10, i64 8
  store ptr %16, ptr %17, align 8, !tbaa !20
  %18 = getelementptr inbounds i8, ptr %.sroa.412.0.copyload, i64 4
  %19 = load i16, ptr %14, align 2, !tbaa !19
  %20 = zext i16 %19 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %16, ptr nonnull align 1 %18, i64 %20, i1 false)
  br label %.critedge

.critedge:                                        ; preds = %7, %2, %.thread
  %spec.select = phi ptr [ %10, %.thread ], [ null, %2 ], [ null, %7 ]
  ret ptr %spec.select
}

; 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @read_16u(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 = { 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" }

!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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !13}
!16 = !{!11, !11, i64 0}
!17 = !{!18, !10, i64 0}
!18 = !{!"", !10, i64 0, !10, i64 2, !11, i64 8}
!19 = !{!18, !10, i64 2}
!20 = !{!18, !11, i64 8}


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