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

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

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

; 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 ptr @otfcc_buildTSI5(ptr noundef %0, ptr noundef %1, i16 noundef zeroext %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i16, align 2
  %8 = alloca ptr, align 8
  %9 = alloca i16, align 2
  %10 = alloca ptr, align 8
  %11 = alloca i16, align 2
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i16 %2, ptr %7, align 2, !tbaa !9
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = icmp ne ptr %12, null
  br i1 %13, label %15, label %14

14:                                               ; preds = %3
  store ptr null, ptr %4, align 8
  br label %87

15:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %16 = load i16, ptr %7, align 2, !tbaa !9
  %17 = zext i16 %16 to i64
  %18 = mul i64 2, %17
  %19 = call ptr @__caryll_allocate_clean(i64 noundef %18, i64 noundef 27)
  store ptr %19, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #5
  store i16 0, ptr %9, align 2, !tbaa !9
  br label %20

20:                                               ; preds = %62, %15
  %21 = load i16, ptr %9, align 2, !tbaa !9
  %22 = zext i16 %21 to i32
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.otl_ClassDef, ptr %23, i32 0, i32 0
  %25 = load i16, ptr %24, align 8, !tbaa !11
  %26 = zext i16 %25 to i32
  %27 = icmp slt i32 %22, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #5
  br label %65

29:                                               ; preds = %20
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.otl_ClassDef, ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = load i16, ptr %9, align 2, !tbaa !9
  %34 = zext i16 %33 to i64
  %35 = getelementptr inbounds %struct.otfcc_Handle, ptr %32, i64 %34
  %36 = getelementptr inbounds %struct.otfcc_Handle, ptr %35, i32 0, i32 1
  %37 = load i16, ptr %36, align 4, !tbaa !15
  %38 = zext i16 %37 to i32
  %39 = load i16, ptr %7, align 2, !tbaa !9
  %40 = zext i16 %39 to i32
  %41 = icmp slt i32 %38, %40
  br i1 %41, label %42, label %61

42:                                               ; preds = %29
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.otl_ClassDef, ptr %43, i32 0, i32 4
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = load i16, ptr %9, align 2, !tbaa !9
  %47 = zext i16 %46 to i64
  %48 = getelementptr inbounds i16, ptr %45, i64 %47
  %49 = load i16, ptr %48, align 2, !tbaa !9
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load ptr, ptr %5, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.otl_ClassDef, ptr %51, i32 0, i32 3
  %53 = load ptr, ptr %52, align 8, !tbaa !14
  %54 = load i16, ptr %9, align 2, !tbaa !9
  %55 = zext i16 %54 to i64
  %56 = getelementptr inbounds %struct.otfcc_Handle, ptr %53, i64 %55
  %57 = getelementptr inbounds %struct.otfcc_Handle, ptr %56, i32 0, i32 1
  %58 = load i16, ptr %57, align 4, !tbaa !15
  %59 = zext i16 %58 to i64
  %60 = getelementptr inbounds i16, ptr %50, i64 %59
  store i16 %49, ptr %60, align 2, !tbaa !9
  br label %61

61:                                               ; preds = %42, %29
  br label %62

62:                                               ; preds = %61
  %63 = load i16, ptr %9, align 2, !tbaa !9
  %64 = add i16 %63, 1
  store i16 %64, ptr %9, align 2, !tbaa !9
  br label %20, !llvm.loop !18

65:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %66 = call ptr (...) @bufnew()
  store ptr %66, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %11) #5
  store i16 0, ptr %11, align 2, !tbaa !9
  br label %67

67:                                               ; preds = %81, %65
  %68 = load i16, ptr %11, align 2, !tbaa !9
  %69 = zext i16 %68 to i32
  %70 = load i16, ptr %7, align 2, !tbaa !9
  %71 = zext i16 %70 to i32
  %72 = icmp slt i32 %69, %71
  br i1 %72, label %74, label %73

73:                                               ; preds = %67
  call void @llvm.lifetime.end.p0(i64 2, ptr %11) #5
  br label %84

74:                                               ; preds = %67
  %75 = load ptr, ptr %10, align 8, !tbaa !5
  %76 = load ptr, ptr %8, align 8, !tbaa !5
  %77 = load i16, ptr %11, align 2, !tbaa !9
  %78 = zext i16 %77 to i64
  %79 = getelementptr inbounds i16, ptr %76, i64 %78
  %80 = load i16, ptr %79, align 2, !tbaa !9
  call void @bufwrite16b(ptr noundef %75, i16 noundef zeroext %80)
  br label %81

81:                                               ; preds = %74
  %82 = load i16, ptr %11, align 2, !tbaa !9
  %83 = add i16 %82, 1
  store i16 %83, ptr %11, align 2, !tbaa !9
  br label %67, !llvm.loop !20

84:                                               ; preds = %73
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %85) #5
  store ptr null, ptr %8, align 8, !tbaa !5
  %86 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %86, ptr %4, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  br label %87

87:                                               ; preds = %84, %14
  %88 = load ptr, ptr %4, align 8
  ret ptr %88
}

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

declare ptr @bufnew(...) #3

declare void @bufwrite16b(ptr noundef, i16 noundef zeroext) #3

; Function Attrs: nounwind
declare void @free(ptr noundef) #4

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


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

; Function Attrs: nounwind uwtable
define dso_local ptr @otfcc_buildTSI5(ptr noundef readonly %0, ptr nocapture noundef readnone %1, i16 noundef zeroext %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %30, label %4

4:                                                ; preds = %3
  %5 = zext i16 %2 to i64
  %6 = shl nuw nsw i64 %5, 1
  %7 = tail call ptr @__caryll_allocate_clean(i64 noundef %6, i64 noundef 27)
  %8 = load i16, ptr %0, align 8, !tbaa !5
  %.not29 = icmp eq i16 %8, 0
  br i1 %.not29, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %4
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load ptr, ptr %9, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  br label %13

._crit_edge:                                      ; preds = %24, %4
  %12 = tail call ptr (...) @bufnew() #4
  %.not30 = icmp eq i16 %2, 0
  br i1 %.not30, label %._crit_edge28, label %.lr.ph27

13:                                               ; preds = %.lr.ph, %24
  %14 = phi i16 [ %8, %.lr.ph ], [ %25, %24 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %24 ]
  %15 = getelementptr inbounds %struct.otfcc_Handle, ptr %10, i64 %indvars.iv, i32 1
  %16 = load i16, ptr %15, align 4, !tbaa !13
  %17 = icmp ult i16 %16, %2
  br i1 %17, label %18, label %24

18:                                               ; preds = %13
  %19 = load ptr, ptr %11, align 8, !tbaa !15
  %20 = getelementptr inbounds i16, ptr %19, i64 %indvars.iv
  %21 = load i16, ptr %20, align 2, !tbaa !16
  %22 = zext i16 %16 to i64
  %23 = getelementptr inbounds i16, ptr %7, i64 %22
  store i16 %21, ptr %23, align 2, !tbaa !16
  %.pre = load i16, ptr %0, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %13, %18
  %25 = phi i16 [ %14, %13 ], [ %.pre, %18 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %26 = zext i16 %25 to i64
  %27 = icmp ult i64 %indvars.iv.next, %26
  br i1 %27, label %13, label %._crit_edge, !llvm.loop !17

._crit_edge28:                                    ; preds = %.lr.ph27, %._crit_edge
  tail call void @free(ptr noundef %7) #4
  br label %30

.lr.ph27:                                         ; preds = %._crit_edge, %.lr.ph27
  %indvars.iv32 = phi i64 [ %indvars.iv.next33, %.lr.ph27 ], [ 0, %._crit_edge ]
  %28 = getelementptr inbounds i16, ptr %7, i64 %indvars.iv32
  %29 = load i16, ptr %28, align 2, !tbaa !16
  tail call void @bufwrite16b(ptr noundef %12, i16 noundef zeroext %29) #4
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next33, %5
  br i1 %exitcond.not, label %._crit_edge28, label %.lr.ph27, !llvm.loop !19

30:                                               ; preds = %3, %._crit_edge28
  %.021 = phi ptr [ %12, %._crit_edge28 ], [ null, %3 ]
  ret ptr %.021
}

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

declare ptr @bufnew(...) local_unnamed_addr #2

declare void @bufwrite16b(ptr noundef, i16 noundef zeroext) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #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 = { "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 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 4, !7, i64 8, !11, i64 16, !11, i64 24}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 16}
!13 = !{!14, !7, i64 4}
!14 = !{!"otfcc_Handle", !10, i64 0, !7, i64 4, !11, i64 8}
!15 = !{!6, !11, i64 24}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}


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