; LLVM IR from caryll/otfcc :: lib/font (caryll-sfnt)

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

; Function Attrs: nounwind uwtable
define dso_local ptr @otfcc_readSFNT(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %9, label %8

8:                                                ; preds = %1
  store ptr null, ptr %2, align 8
  br label %99

9:                                                ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %10 = call ptr @__caryll_allocate_clean(i64 noundef 24, i64 noundef 34)
  store ptr %10, ptr %4, align 8, !tbaa !5
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = call i32 @otfcc_get32u(ptr noundef %11)
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %13, i32 0, i32 0
  store i32 %12, ptr %14, align 8, !tbaa !9
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !9
  switch i32 %17, label %88 [
    i32 1330926671, label %18
    i32 65536, label %18
    i32 1953658213, label %18
    i32 1954115633, label %18
    i32 1953784678, label %43
  ]

18:                                               ; preds = %9, %9, %9, %9
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %19, i32 0, i32 1
  store i32 1, ptr %20, align 4, !tbaa !12
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 4, !tbaa !12
  %24 = zext i32 %23 to i64
  %25 = mul i64 4, %24
  %26 = call ptr @__caryll_allocate_clean(i64 noundef %25, i64 noundef 44)
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %27, i32 0, i32 2
  store ptr %26, ptr %28, align 8, !tbaa !13
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 4, !tbaa !12
  %32 = zext i32 %31 to i64
  %33 = mul i64 24, %32
  %34 = call ptr @__caryll_allocate_clean(i64 noundef %33, i64 noundef 45)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %35, i32 0, i32 3
  store ptr %34, ptr %36, align 8, !tbaa !14
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = getelementptr inbounds i32, ptr %39, i64 0
  store i32 0, ptr %40, align 4, !tbaa !15
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = load ptr, ptr %3, align 8, !tbaa !5
  call void @otfcc_read_packets(ptr noundef %41, ptr noundef %42)
  br label %95

43:                                               ; preds = %9
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = call i32 @otfcc_get32u(ptr noundef %44)
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = call i32 @otfcc_get32u(ptr noundef %46)
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %48, i32 0, i32 1
  store i32 %47, ptr %49, align 4, !tbaa !12
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %50, i32 0, i32 1
  %52 = load i32, ptr %51, align 4, !tbaa !12
  %53 = zext i32 %52 to i64
  %54 = mul i64 4, %53
  %55 = call ptr @__caryll_allocate_clean(i64 noundef %54, i64 noundef 53)
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %56, i32 0, i32 2
  store ptr %55, ptr %57, align 8, !tbaa !13
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %58, i32 0, i32 1
  %60 = load i32, ptr %59, align 4, !tbaa !12
  %61 = zext i32 %60 to i64
  %62 = mul i64 24, %61
  %63 = call ptr @__caryll_allocate_clean(i64 noundef %62, i64 noundef 54)
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %64, i32 0, i32 3
  store ptr %63, ptr %65, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !15
  br label %66

66:                                               ; preds = %82, %43
  %67 = load i32, ptr %5, align 4, !tbaa !15
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 4, !tbaa !12
  %71 = icmp ult i32 %67, %70
  br i1 %71, label %73, label %72

72:                                               ; preds = %66
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %85

73:                                               ; preds = %66
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = call i32 @otfcc_get32u(ptr noundef %74)
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %76, i32 0, i32 2
  %78 = load ptr, ptr %77, align 8, !tbaa !13
  %79 = load i32, ptr %5, align 4, !tbaa !15
  %80 = zext i32 %79 to i64
  %81 = getelementptr inbounds i32, ptr %78, i64 %80
  store i32 %75, ptr %81, align 4, !tbaa !15
  br label %82

82:                                               ; preds = %73
  %83 = load i32, ptr %5, align 4, !tbaa !15
  %84 = add i32 %83, 1
  store i32 %84, ptr %5, align 4, !tbaa !15
  br label %66, !llvm.loop !16

85:                                               ; preds = %72
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = load ptr, ptr %3, align 8, !tbaa !5
  call void @otfcc_read_packets(ptr noundef %86, ptr noundef %87)
  br label %95

88:                                               ; preds = %9
  %89 = load ptr, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %89, i32 0, i32 1
  store i32 0, ptr %90, align 4, !tbaa !12
  %91 = load ptr, ptr %4, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %91, i32 0, i32 2
  store ptr null, ptr %92, align 8, !tbaa !13
  %93 = load ptr, ptr %4, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.otfcc_SplineFontContainer, ptr %93, i32 0, i32 3
  store ptr null, ptr %94, align 8, !tbaa !14
  br label %95

95:                                               ; preds = %88, %85, %18
  %96 = load ptr, ptr %3, align 8, !tbaa !5
  %97 = call i32 @fclose(ptr noundef %96)
  %98 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %98, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  br label %99

99:                                               ; preds = %95, %8
  %100 = load ptr, ptr %2, align 8
  ret ptr %100
}

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @otfcc_get32u(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @otfcc_read_packets(ptr noundef, ptr noundef) #0

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

declare i32 @fclose(ptr noundef) #3

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 = { 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 = { "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, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !6, i64 8}
!14 = !{!10, !6, i64 16}
!15 = !{!11, !11, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; Function Attrs: nounwind uwtable
define dso_local ptr @otfcc_readSFNT(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %39, label %2

2:                                                ; preds = %1
  %3 = tail call ptr @__caryll_allocate_clean(i64 noundef 24, i64 noundef 34)
  %4 = tail call i32 @otfcc_get32u(ptr noundef nonnull %0)
  store i32 %4, ptr %3, align 8, !tbaa !5
  switch i32 %4, label %35 [
    i32 1330926671, label %5
    i32 65536, label %5
    i32 1953658213, label %5
    i32 1954115633, label %5
    i32 1953784678, label %15
  ]

5:                                                ; preds = %2, %2, %2, %2
  %6 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 1, ptr %6, align 4, !tbaa !11
  %7 = tail call ptr @__caryll_allocate_clean(i64 noundef 4, i64 noundef 44)
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %7, ptr %8, align 8, !tbaa !12
  %9 = load i32, ptr %6, align 4, !tbaa !11
  %10 = zext i32 %9 to i64
  %11 = mul nuw nsw i64 %10, 24
  %12 = tail call ptr @__caryll_allocate_clean(i64 noundef %11, i64 noundef 45)
  %13 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %12, ptr %13, align 8, !tbaa !13
  %14 = load ptr, ptr %8, align 8, !tbaa !12
  store i32 0, ptr %14, align 4, !tbaa !14
  tail call void @otfcc_read_packets(ptr noundef nonnull %3, ptr noundef nonnull %0)
  br label %37

15:                                               ; preds = %2
  %16 = tail call i32 @otfcc_get32u(ptr noundef nonnull %0)
  %17 = tail call i32 @otfcc_get32u(ptr noundef nonnull %0)
  %18 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %17, ptr %18, align 4, !tbaa !11
  %19 = zext i32 %17 to i64
  %20 = shl nuw nsw i64 %19, 2
  %21 = tail call ptr @__caryll_allocate_clean(i64 noundef %20, i64 noundef 53)
  %22 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %21, ptr %22, align 8, !tbaa !12
  %23 = load i32, ptr %18, align 4, !tbaa !11
  %24 = zext i32 %23 to i64
  %25 = mul nuw nsw i64 %24, 24
  %26 = tail call ptr @__caryll_allocate_clean(i64 noundef %25, i64 noundef 54)
  %27 = getelementptr inbounds i8, ptr %3, i64 16
  store ptr %26, ptr %27, align 8, !tbaa !13
  %28 = load i32, ptr %18, align 4, !tbaa !11
  %.not35 = icmp eq i32 %28, 0
  br i1 %.not35, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %15
  tail call void @otfcc_read_packets(ptr noundef nonnull %3, ptr noundef nonnull %0)
  br label %37

.lr.ph:                                           ; preds = %15, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %15 ]
  %29 = tail call i32 @otfcc_get32u(ptr noundef nonnull %0)
  %30 = load ptr, ptr %22, align 8, !tbaa !12
  %31 = getelementptr inbounds i32, ptr %30, i64 %indvars.iv
  store i32 %29, ptr %31, align 4, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %32 = load i32, ptr %18, align 4, !tbaa !11
  %33 = zext i32 %32 to i64
  %34 = icmp ult i64 %indvars.iv.next, %33
  br i1 %34, label %.lr.ph, label %._crit_edge, !llvm.loop !15

35:                                               ; preds = %2
  %36 = getelementptr inbounds i8, ptr %3, i64 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(20) %36, i8 0, i64 20, i1 false)
  br label %37

37:                                               ; preds = %35, %._crit_edge, %5
  %38 = tail call i32 @fclose(ptr noundef nonnull %0)
  br label %39

39:                                               ; preds = %1, %37
  %.032 = phi ptr [ %3, %37 ], [ null, %1 ]
  ret ptr %.032
}

; 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 i32 @otfcc_get32u(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden void @otfcc_read_packets(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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" }
attributes #2 = { nofree nounwind "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,SROAPass,SimplifyCFGPass,TailCallElimPass