; LLVM IR from caryll/otfcc :: lib/libcff (cff-fdselect)

; 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.cff_FDSelect = type { i32, i32, %union.anon }
%union.anon = type { %struct.cff_FDSelectFormat3 }
%struct.cff_FDSelectFormat3 = type { i8, i16, ptr, i16 }
%struct.cff_FDSelectFormat0 = type { i8, ptr }
%struct.cff_FDSelectRangeFormat3 = type { i16, i8 }

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

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

; 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 void @cff_extract_FDSelect(ptr noundef %0, i32 noundef %1, i16 noundef zeroext %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i16, align 2
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i16 %2, ptr %7, align 2, !tbaa !11
  store ptr %3, ptr %8, align 8, !tbaa !5
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = load i32, ptr %6, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i8, ptr %11, i64 %13
  %15 = load i8, ptr %14, align 1, !tbaa !13
  %16 = zext i8 %15 to i32
  switch i32 %16, label %144 [
    i32 0, label %17
    i32 3, label %59
  ]

17:                                               ; preds = %4
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.cff_FDSelect, ptr %18, i32 0, i32 0
  store i32 0, ptr %19, align 8, !tbaa !14
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.cff_FDSelect, ptr %20, i32 0, i32 2
  %22 = getelementptr inbounds %struct.cff_FDSelectFormat0, ptr %21, i32 0, i32 0
  store i8 0, ptr %22, align 8, !tbaa !13
  %23 = load i16, ptr %7, align 2, !tbaa !11
  %24 = zext i16 %23 to i32
  %25 = load ptr, ptr %8, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.cff_FDSelect, ptr %25, i32 0, i32 1
  store i32 %24, ptr %26, align 4, !tbaa !16
  %27 = load i16, ptr %7, align 2, !tbaa !11
  %28 = zext i16 %27 to i64
  %29 = mul i64 1, %28
  %30 = call ptr @__caryll_allocate_clean(i64 noundef %29, i64 noundef 55)
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.cff_FDSelect, ptr %31, i32 0, i32 2
  %33 = getelementptr inbounds %struct.cff_FDSelectFormat0, ptr %32, i32 0, i32 1
  store ptr %30, ptr %33, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %55, %17
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = load i16, ptr %7, align 2, !tbaa !11
  %37 = zext i16 %36 to i32
  %38 = icmp ult i32 %35, %37
  br i1 %38, label %40, label %39

39:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %58

40:                                               ; preds = %34
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = add i32 %43, %44
  %46 = call i32 @gu1(ptr noundef %41, i32 noundef %45)
  %47 = trunc i32 %46 to i8
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.cff_FDSelect, ptr %48, i32 0, i32 2
  %50 = getelementptr inbounds %struct.cff_FDSelectFormat0, ptr %49, i32 0, i32 1
  %51 = load ptr, ptr %50, align 8, !tbaa !13
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds i8, ptr %51, i64 %53
  store i8 %47, ptr %54, align 1, !tbaa !13
  br label %55

55:                                               ; preds = %40
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = add i32 %56, 1
  store i32 %57, ptr %9, align 4, !tbaa !9
  br label %34, !llvm.loop !17

58:                                               ; preds = %39
  br label %147

59:                                               ; preds = %4
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.cff_FDSelect, ptr %60, i32 0, i32 0
  store i32 1, ptr %61, align 8, !tbaa !14
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.cff_FDSelect, ptr %62, i32 0, i32 2
  %64 = getelementptr inbounds %struct.cff_FDSelectFormat3, ptr %63, i32 0, i32 0
  store i8 3, ptr %64, align 8, !tbaa !13
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  %68 = call i32 @gu2(ptr noundef %65, i32 noundef %67)
  %69 = trunc i32 %68 to i16
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.cff_FDSelect, ptr %70, i32 0, i32 2
  %72 = getelementptr inbounds %struct.cff_FDSelectFormat3, ptr %71, i32 0, i32 1
  store i16 %69, ptr %72, align 2, !tbaa !13
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.cff_FDSelect, ptr %73, i32 0, i32 2
  %75 = getelementptr inbounds %struct.cff_FDSelectFormat3, ptr %74, i32 0, i32 1
  %76 = load i16, ptr %75, align 2, !tbaa !13
  %77 = zext i16 %76 to i64
  %78 = mul i64 4, %77
  %79 = call ptr @__caryll_allocate_clean(i64 noundef %78, i64 noundef 66)
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.cff_FDSelect, ptr %80, i32 0, i32 2
  %82 = getelementptr inbounds %struct.cff_FDSelectFormat3, ptr %81, i32 0, i32 2
  store ptr %79, ptr %82, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %83

83:                                               ; preds = %125, %59
  %84 = load i32, ptr %10, align 4, !tbaa !9
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.cff_FDSelect, ptr %85, i32 0, i32 2
  %87 = getelementptr inbounds %struct.cff_FDSelectFormat3, ptr %86, i32 0, i32 1
  %88 = load i16, ptr %87, align 2, !tbaa !13
  %89 = zext i16 %88 to i32
  %90 = icmp ult i32 %84, %89
  br i1 %90, label %92, label %91

91:                                               ; preds = %83
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  br label %128

92:                                               ; preds = %83
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = load i32, ptr %6, align 4, !tbaa !9
  %95 = add nsw i32 %94, 3
  %96 = load i32, ptr %10, align 4, !tbaa !9
  %97 = mul i32 %96, 3
  %98 = add i32 %95, %97
  %99 = call i32 @gu2(ptr noundef %93, i32 noundef %98)
  %100 = trunc i32 %99 to i16
  %101 = load ptr, ptr %8, align 8, !tbaa !5
  %102 = getelementptr inbounds %struct.cff_FDSelect, ptr %101, i32 0, i32 2
  %103 = getelementptr inbounds %struct.cff_FDSelectFormat3, ptr %102, i32 0, i32 2
  %104 = load ptr, ptr %103, align 8, !tbaa !13
  %105 = load i32, ptr %10, align 4, !tbaa !9
  %106 = zext i32 %105 to i64
  %107 = getelementptr inbounds %struct.cff_FDSelectRangeFormat3, ptr %104, i64 %106
  %108 = getelementptr inbounds %struct.cff_FDSelectRangeFormat3, ptr %107, i32 0, i32 0
  store i16 %100, ptr %108, align 2, !tbaa !19
  %109 = load ptr, ptr %5, align 8, !tbaa !5
  %110 = load i32, ptr %6, align 4, !tbaa !9
  %111 = add nsw i32 %110, 5
  %112 = load i32, ptr %10, align 4, !tbaa !9
  %113 = mul i32 %112, 3
  %114 = add i32 %111, %113
  %115 = call i32 @gu1(ptr noundef %109, i32 noundef %114)
  %116 = trunc i32 %115 to i8
  %117 = load ptr, ptr %8, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.cff_FDSelect, ptr %117, i32 0, i32 2
  %119 = getelementptr inbounds %struct.cff_FDSelectFormat3, ptr %118, i32 0, i32 2
  %120 = load ptr, ptr %119, align 8, !tbaa !13
  %121 = load i32, ptr %10, align 4, !tbaa !9
  %122 = zext i32 %121 to i64
  %123 = getelementptr inbounds %struct.cff_FDSelectRangeFormat3, ptr %120, i64 %122
  %124 = getelementptr inbounds %struct.cff_FDSelectRangeFormat3, ptr %123, i32 0, i32 1
  store i8 %116, ptr %124, align 2, !tbaa !21
  br label %125

125:                                              ; preds = %92
  %126 = load i32, ptr %10, align 4, !tbaa !9
  %127 = add i32 %126, 1
  store i32 %127, ptr %10, align 4, !tbaa !9
  br label %83, !llvm.loop !22

128:                                              ; preds = %91
  %129 = load ptr, ptr %5, align 8, !tbaa !5
  %130 = load i32, ptr %6, align 4, !tbaa !9
  %131 = load ptr, ptr %8, align 8, !tbaa !5
  %132 = getelementptr inbounds %struct.cff_FDSelect, ptr %131, i32 0, i32 2
  %133 = getelementptr inbounds %struct.cff_FDSelectFormat3, ptr %132, i32 0, i32 1
  %134 = load i16, ptr %133, align 2, !tbaa !13
  %135 = zext i16 %134 to i32
  %136 = add nsw i32 %135, 1
  %137 = mul nsw i32 %136, 3
  %138 = add nsw i32 %130, %137
  %139 = call i32 @gu2(ptr noundef %129, i32 noundef %138)
  %140 = trunc i32 %139 to i16
  %141 = load ptr, ptr %8, align 8, !tbaa !5
  %142 = getelementptr inbounds %struct.cff_FDSelect, ptr %141, i32 0, i32 2
  %143 = getelementptr inbounds %struct.cff_FDSelectFormat3, ptr %142, i32 0, i32 3
  store i16 %140, ptr %143, align 8, !tbaa !13
  br label %147

144:                                              ; preds = %4
  %145 = load ptr, ptr %8, align 8, !tbaa !5
  %146 = getelementptr inbounds %struct.cff_FDSelect, ptr %145, i32 0, i32 0
  store i32 2, ptr %146, align 8, !tbaa !14
  br label %147

147:                                              ; preds = %144, %128, %58
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @gu1(ptr noundef, i32 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @gu2(ptr noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { 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, !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, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"", !10, i64 0, !10, i64 4, !7, i64 8}
!16 = !{!15, !10, i64 4}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!20, !12, i64 0}
!20 = !{!"", !12, i64 0, !7, i64 2}
!21 = !{!20, !7, i64 2}
!22 = distinct !{!22, !18}


; 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.cff_FDSelectRangeFormat3 = type { i16, i8 }

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

; Function Attrs: nounwind uwtable
define dso_local void @cff_extract_FDSelect(ptr noundef %0, i32 noundef %1, i16 noundef zeroext %2, ptr nocapture noundef %3) local_unnamed_addr #1 {
  %5 = sext i32 %1 to i64
  %6 = getelementptr inbounds i8, ptr %0, i64 %5
  %7 = load i8, ptr %6, align 1, !tbaa !5
  switch i8 %7, label %57 [
    i8 0, label %8
    i8 3, label %23
  ]

8:                                                ; preds = %4
  store i32 0, ptr %3, align 8, !tbaa !8
  %9 = getelementptr inbounds i8, ptr %3, i64 8
  store i8 0, ptr %9, align 8, !tbaa !5
  %10 = zext i16 %2 to i32
  %11 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %10, ptr %11, align 4, !tbaa !11
  %12 = zext i16 %2 to i64
  %13 = tail call ptr @__caryll_allocate_clean(i64 noundef %12, i64 noundef 55)
  %14 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %13, ptr %14, align 8, !tbaa !5
  %.not46 = icmp eq i16 %2, 0
  br i1 %.not46, label %.loopexit, label %.lr.ph45

.lr.ph45:                                         ; preds = %8
  %15 = add nsw i32 %1, 1
  %wide.trip.count = zext i16 %2 to i64
  br label %16

16:                                               ; preds = %.lr.ph45, %16
  %indvars.iv49 = phi i64 [ 0, %.lr.ph45 ], [ %indvars.iv.next50, %16 ]
  %17 = trunc nuw nsw i64 %indvars.iv49 to i32
  %18 = add i32 %15, %17
  %19 = tail call i32 @gu1(ptr noundef %0, i32 noundef %18)
  %20 = trunc i32 %19 to i8
  %21 = load ptr, ptr %14, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 %indvars.iv49
  store i8 %20, ptr %22, align 1, !tbaa !5
  %indvars.iv.next50 = add nuw nsw i64 %indvars.iv49, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next50, %wide.trip.count
  br i1 %exitcond.not, label %.loopexit, label %16, !llvm.loop !12

23:                                               ; preds = %4
  store i32 1, ptr %3, align 8, !tbaa !8
  %24 = getelementptr inbounds i8, ptr %3, i64 8
  store i8 3, ptr %24, align 8, !tbaa !5
  %25 = add nsw i32 %1, 1
  %26 = tail call i32 @gu2(ptr noundef nonnull %0, i32 noundef %25)
  %27 = trunc i32 %26 to i16
  %28 = getelementptr inbounds i8, ptr %3, i64 10
  store i16 %27, ptr %28, align 2, !tbaa !5
  %.mask = shl i32 %26, 2
  %29 = and i32 %.mask, 262140
  %30 = zext nneg i32 %29 to i64
  %31 = tail call ptr @__caryll_allocate_clean(i64 noundef %30, i64 noundef 66)
  %32 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %31, ptr %32, align 8, !tbaa !5
  %33 = load i16, ptr %28, align 2, !tbaa !5
  %.not = icmp eq i16 %33, 0
  %.pre = add i32 %1, 3
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %23
  %34 = add nsw i32 %1, 5
  br label %41

._crit_edge.loopexit:                             ; preds = %41
  %35 = zext i16 %54 to i32
  %36 = mul nuw nsw i32 %35, 3
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %23
  %.lcssa.in = phi i32 [ 0, %23 ], [ %36, %._crit_edge.loopexit ]
  %37 = add i32 %.pre, %.lcssa.in
  %38 = tail call i32 @gu2(ptr noundef %0, i32 noundef %37)
  %39 = trunc i32 %38 to i16
  %40 = getelementptr inbounds i8, ptr %3, i64 24
  store i16 %39, ptr %40, align 8, !tbaa !5
  br label %.loopexit

41:                                               ; preds = %.lr.ph, %41
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %41 ]
  %42 = trunc i64 %indvars.iv to i32
  %43 = mul nuw nsw i32 %42, 3
  %44 = add i32 %.pre, %43
  %45 = tail call i32 @gu2(ptr noundef %0, i32 noundef %44)
  %46 = trunc i32 %45 to i16
  %47 = load ptr, ptr %32, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.cff_FDSelectRangeFormat3, ptr %47, i64 %indvars.iv
  store i16 %46, ptr %48, align 2, !tbaa !14
  %49 = add i32 %34, %43
  %50 = tail call i32 @gu1(ptr noundef %0, i32 noundef %49)
  %51 = trunc i32 %50 to i8
  %52 = load ptr, ptr %32, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.cff_FDSelectRangeFormat3, ptr %52, i64 %indvars.iv, i32 1
  store i8 %51, ptr %53, align 2, !tbaa !17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %54 = load i16, ptr %28, align 2, !tbaa !5
  %55 = zext i16 %54 to i64
  %56 = icmp ult i64 %indvars.iv.next, %55
  br i1 %56, label %41, label %._crit_edge.loopexit, !llvm.loop !18

57:                                               ; preds = %4
  store i32 2, ptr %3, align 8, !tbaa !8
  br label %.loopexit

.loopexit:                                        ; preds = %16, %8, %57, %._crit_edge
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @gu1(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @gu2(ptr noundef, i32 noundef) local_unnamed_addr #0

attributes #0 = { 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 #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" }

!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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 0}
!9 = !{!"", !10, i64 0, !10, i64 4, !6, i64 8}
!10 = !{!"int", !6, i64 0}
!11 = !{!9, !10, i64 4}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{!15, !16, i64 0}
!15 = !{!"", !16, i64 0, !6, i64 2}
!16 = !{!"short", !6, i64 0}
!17 = !{!15, !6, i64 2}
!18 = distinct !{!18, !13}


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