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

; 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_cvt = type { i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @otfcc_readCvt(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
  %16 = alloca i16, align 2
  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 %17

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

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

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

29:                                               ; preds = %23, %20, %17
  %30 = phi i1 [ false, %20 ], [ false, %17 ], [ %28, %23 ]
  br i1 %30, label %32, label %31

31:                                               ; preds = %29
  store i32 2, ptr %11, align 4
  br label %118

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

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

41:                                               ; preds = %38
  store i32 5, ptr %11, align 4
  br label %108

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

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

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

51:                                               ; preds = %48
  store i32 8, ptr %11, align 4
  br label %99

52:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %53 = getelementptr inbounds %struct.otfcc_PacketPiece, ptr %12, i32 0, i32 4
  %54 = load ptr, ptr %53, align 8, !tbaa !18
  store ptr %54, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %55 = getelementptr inbounds %struct.otfcc_PacketPiece, ptr %12, i32 0, i32 3
  %56 = load i32, ptr %55, align 4, !tbaa !19
  store i32 %56, ptr %15, align 4, !tbaa !9
  %57 = call ptr @__caryll_allocate_clean(i64 noundef 16, i64 noundef 16)
  store ptr %57, ptr %7, align 8, !tbaa !5
  %58 = load i32, ptr %15, align 4, !tbaa !9
  %59 = lshr i32 %58, 1
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.table_cvt, ptr %60, i32 0, i32 0
  store i32 %59, ptr %61, align 8, !tbaa !20
  %62 = load ptr, ptr %7, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.table_cvt, ptr %62, i32 0, i32 0
  %64 = load i32, ptr %63, align 8, !tbaa !20
  %65 = add i32 %64, 1
  %66 = zext i32 %65 to i64
  %67 = mul i64 2, %66
  %68 = call ptr @__caryll_allocate_clean(i64 noundef %67, i64 noundef 18)
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.table_cvt, ptr %69, i32 0, i32 1
  store ptr %68, ptr %70, align 8, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 2, ptr %16) #4
  store i16 0, ptr %16, align 2, !tbaa !23
  br label %71

71:                                               ; preds = %93, %52
  %72 = load i16, ptr %16, align 2, !tbaa !23
  %73 = zext i16 %72 to i32
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.table_cvt, ptr %74, i32 0, i32 0
  %76 = load i32, ptr %75, align 8, !tbaa !20
  %77 = icmp ult i32 %73, %76
  br i1 %77, label %79, label %78

78:                                               ; preds = %71
  store i32 11, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 2, ptr %16) #4
  br label %96

79:                                               ; preds = %71
  %80 = load ptr, ptr %14, align 8, !tbaa !5
  %81 = load i16, ptr %16, align 2, !tbaa !23
  %82 = zext i16 %81 to i32
  %83 = mul nsw i32 2, %82
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds i8, ptr %80, i64 %84
  %86 = call zeroext i16 @read_16u(ptr noundef %85)
  %87 = load ptr, ptr %7, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.table_cvt, ptr %87, i32 0, i32 1
  %89 = load ptr, ptr %88, align 8, !tbaa !22
  %90 = load i16, ptr %16, align 2, !tbaa !23
  %91 = zext i16 %90 to i64
  %92 = getelementptr inbounds i16, ptr %89, i64 %91
  store i16 %86, ptr %92, align 2, !tbaa !23
  br label %93

93:                                               ; preds = %79
  %94 = load i16, ptr %16, align 2, !tbaa !23
  %95 = add i16 %94, 1
  store i16 %95, ptr %16, align 2, !tbaa !23
  br label %71, !llvm.loop !24

96:                                               ; preds = %78
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %97, ptr %4, align 8
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  br label %99

98:                                               ; No predecessors!
  store i32 0, ptr %13, align 4, !tbaa !9
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %48, !llvm.loop !26

99:                                               ; preds = %96, %51
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  %100 = load i32, ptr %11, align 4
  switch i32 %100, label %108 [
    i32 8, label %101
  ]

101:                                              ; preds = %99
  br label %102

102:                                              ; preds = %101, %42
  br label %103

103:                                              ; preds = %102
  %104 = load i32, ptr %8, align 4, !tbaa !9
  %105 = icmp ne i32 %104, 0
  %106 = xor i1 %105, true
  %107 = zext i1 %106 to i32
  store i32 %107, ptr %8, align 4, !tbaa !9
  br label %38, !llvm.loop !27

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

110:                                              ; preds = %108
  br label %111

111:                                              ; preds = %110
  %112 = load i32, ptr %8, align 4, !tbaa !9
  %113 = icmp ne i32 %112, 0
  %114 = xor i1 %113, true
  %115 = zext i1 %114 to i32
  store i32 %115, ptr %8, align 4, !tbaa !9
  %116 = load i32, ptr %9, align 4, !tbaa !9
  %117 = add nsw i32 %116, 1
  store i32 %117, ptr %9, align 4, !tbaa !9
  br label %17, !llvm.loop !28

118:                                              ; preds = %108, %31
  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
  %119 = load i32, ptr %11, align 4
  switch i32 %119, label %121 [
    i32 2, label %120
  ]

120:                                              ; preds = %118
  store ptr null, ptr %4, align 8
  store i32 1, ptr %11, align 4
  br label %121

121:                                              ; preds = %120, %118
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  %122 = load ptr, ptr %4, align 8
  ret ptr %122
}

; 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 = !{!17, !10, i64 12}
!20 = !{!21, !10, i64 0}
!21 = !{!"", !10, i64 0, !6, i64 8}
!22 = !{!21, !6, i64 8}
!23 = !{!13, !13, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = distinct !{!26, !25}
!27 = distinct !{!27, !25}
!28 = distinct !{!28, !25}


; 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 noundef ptr @otfcc_readCvt(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.ph50

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

8:                                                ; preds = %.lr.ph50, %.thread
  %indvars.iv = phi i64 [ 0, %.lr.ph50 ], [ %indvars.iv.next, %.thread ]
  %9 = getelementptr inbounds %struct.otfcc_PacketPiece, ptr %7, i64 %indvars.iv
  %.sroa.0.0.copyload = load i32, ptr %9, align 8, !tbaa !12
  %.sroa.0.0.copyload.fr = freeze i32 %.sroa.0.0.copyload
  %10 = icmp eq i32 %.sroa.0.0.copyload.fr, %2
  br i1 %10, label %.split46.us, label %.thread, !llvm.loop !13

.split46.us:                                      ; preds = %8
  %.sroa.5.0..sroa_idx.le = getelementptr inbounds i8, ptr %9, i64 16
  %.sroa.5.0.copyload.le = load ptr, ptr %.sroa.5.0..sroa_idx.le, align 8, !tbaa !15
  %.sroa.49.0..sroa_idx = getelementptr inbounds i8, ptr %9, i64 12
  %.sroa.49.0.copyload = load i32, ptr %.sroa.49.0..sroa_idx, align 4, !tbaa !12
  %11 = tail call ptr @__caryll_allocate_clean(i64 noundef 16, i64 noundef 16)
  %12 = lshr i32 %.sroa.49.0.copyload, 1
  store i32 %12, ptr %11, align 8, !tbaa !16
  %13 = add nuw i32 %12, 1
  %14 = zext i32 %13 to i64
  %15 = shl nuw nsw i64 %14, 1
  %16 = tail call ptr @__caryll_allocate_clean(i64 noundef %15, i64 noundef 18)
  %17 = getelementptr inbounds i8, ptr %11, i64 8
  store ptr %16, ptr %17, align 8, !tbaa !18
  %18 = load i32, ptr %11, align 8, !tbaa !16
  %.not53 = icmp eq i32 %18, 0
  br i1 %.not53, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %.split46.us, %.lr.ph
  %19 = phi i32 [ %28, %.lr.ph ], [ 0, %.split46.us ]
  %.047 = phi i16 [ %27, %.lr.ph ], [ 0, %.split46.us ]
  %20 = shl nuw nsw i32 %19, 1
  %21 = zext nneg i32 %20 to i64
  %22 = getelementptr inbounds i8, ptr %.sroa.5.0.copyload.le, i64 %21
  %23 = tail call zeroext i16 @read_16u(ptr noundef %22)
  %24 = load ptr, ptr %17, align 8, !tbaa !18
  %25 = zext i16 %.047 to i64
  %26 = getelementptr inbounds i16, ptr %24, i64 %25
  store i16 %23, ptr %26, align 2, !tbaa !19
  %27 = add i16 %.047, 1
  %28 = zext i16 %27 to i32
  %29 = load i32, ptr %11, align 8, !tbaa !16
  %30 = icmp ugt i32 %29, %28
  br i1 %30, label %.lr.ph, label %.critedge, !llvm.loop !20

.thread:                                          ; preds = %8
  %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 %8, !llvm.loop !21

.critedge:                                        ; preds = %.thread, %.lr.ph, %.split46.us, %3
  %31 = phi ptr [ null, %3 ], [ %11, %.split46.us ], [ %11, %.lr.ph ], [ null, %.thread ]
  ret ptr %31
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @read_16u(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 = { 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 = !{!7, !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!11, !11, i64 0}
!16 = !{!17, !7, i64 0}
!17 = !{!"", !7, i64 0, !11, i64 8}
!18 = !{!17, !11, i64 8}
!19 = !{!10, !10, i64 0}
!20 = distinct !{!20, !14}
!21 = distinct !{!21, !14}


; 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