; LLVM IR from caryll/otfcc :: lib/table/otl/subtables/chaining (common)

; 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_IClassDef = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.subtable_chaining = type { i32, %union.anon }
%union.anon = type { %struct.anon }
%struct.anon = type { i16, ptr, ptr, ptr, ptr }

@otl_iClassDef = external constant %struct.__otfcc_IClassDef, align 8

; Function Attrs: nounwind uwtable
define dso_local void @otl_dispose_chaining(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i16, align 2
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.subtable_chaining, ptr %4, i32 0, i32 0
  %6 = load i32, ptr %5, align 8, !tbaa !9
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %8, label %82

8:                                                ; preds = %1
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.subtable_chaining, ptr %9, i32 0, i32 1
  %11 = getelementptr inbounds %struct.anon, ptr %10, i32 0, i32 1
  %12 = load ptr, ptr %11, align 8, !tbaa !12
  %13 = icmp ne ptr %12, null
  br i1 %13, label %14, label %45

14:                                               ; preds = %8
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #4
  store i16 0, ptr %3, align 2, !tbaa !13
  br label %15

15:                                               ; preds = %34, %14
  %16 = load i16, ptr %3, align 2, !tbaa !13
  %17 = zext i16 %16 to i32
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.subtable_chaining, ptr %18, i32 0, i32 1
  %20 = getelementptr inbounds %struct.anon, ptr %19, i32 0, i32 0
  %21 = load i16, ptr %20, align 8, !tbaa !12
  %22 = zext i16 %21 to i32
  %23 = icmp slt i32 %17, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %15
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #4
  br label %37

25:                                               ; preds = %15
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.subtable_chaining, ptr %26, i32 0, i32 1
  %28 = getelementptr inbounds %struct.anon, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !12
  %30 = load i16, ptr %3, align 2, !tbaa !13
  %31 = zext i16 %30 to i64
  %32 = getelementptr inbounds ptr, ptr %29, i64 %31
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  call void @deleteRule(ptr noundef %33)
  br label %34

34:                                               ; preds = %25
  %35 = load i16, ptr %3, align 2, !tbaa !13
  %36 = add i16 %35, 1
  store i16 %36, ptr %3, align 2, !tbaa !13
  br label %15, !llvm.loop !15

37:                                               ; preds = %24
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.subtable_chaining, ptr %38, i32 0, i32 1
  %40 = getelementptr inbounds %struct.anon, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !12
  call void @free(ptr noundef %41) #4
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.subtable_chaining, ptr %42, i32 0, i32 1
  %44 = getelementptr inbounds %struct.anon, ptr %43, i32 0, i32 1
  store ptr null, ptr %44, align 8, !tbaa !12
  br label %45

45:                                               ; preds = %37, %8
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.subtable_chaining, ptr %46, i32 0, i32 1
  %48 = getelementptr inbounds %struct.anon, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !12
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %57

51:                                               ; preds = %45
  %52 = load ptr, ptr getelementptr inbounds (%struct.__otfcc_IClassDef, ptr @otl_iClassDef, i32 0, i32 7), align 8, !tbaa !17
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.subtable_chaining, ptr %53, i32 0, i32 1
  %55 = getelementptr inbounds %struct.anon, ptr %54, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !12
  call void %52(ptr noundef %56)
  br label %57

57:                                               ; preds = %51, %45
  %58 = load ptr, ptr %2, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.subtable_chaining, ptr %58, i32 0, i32 1
  %60 = getelementptr inbounds %struct.anon, ptr %59, i32 0, i32 3
  %61 = load ptr, ptr %60, align 8, !tbaa !12
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %69

63:                                               ; preds = %57
  %64 = load ptr, ptr getelementptr inbounds (%struct.__otfcc_IClassDef, ptr @otl_iClassDef, i32 0, i32 7), align 8, !tbaa !17
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.subtable_chaining, ptr %65, i32 0, i32 1
  %67 = getelementptr inbounds %struct.anon, ptr %66, i32 0, i32 3
  %68 = load ptr, ptr %67, align 8, !tbaa !12
  call void %64(ptr noundef %68)
  br label %69

69:                                               ; preds = %63, %57
  %70 = load ptr, ptr %2, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.subtable_chaining, ptr %70, i32 0, i32 1
  %72 = getelementptr inbounds %struct.anon, ptr %71, i32 0, i32 4
  %73 = load ptr, ptr %72, align 8, !tbaa !12
  %74 = icmp ne ptr %73, null
  br i1 %74, label %75, label %81

75:                                               ; preds = %69
  %76 = load ptr, ptr getelementptr inbounds (%struct.__otfcc_IClassDef, ptr @otl_iClassDef, i32 0, i32 7), align 8, !tbaa !17
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.subtable_chaining, ptr %77, i32 0, i32 1
  %79 = getelementptr inbounds %struct.anon, ptr %78, i32 0, i32 4
  %80 = load ptr, ptr %79, align 8, !tbaa !12
  call void %76(ptr noundef %80)
  br label %81

81:                                               ; preds = %75, %69
  br label %85

82:                                               ; preds = %1
  %83 = load ptr, ptr %2, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.subtable_chaining, ptr %83, i32 0, i32 1
  call void @closeRule(ptr noundef %84)
  br label %85

85:                                               ; preds = %82, %81
  ret void
}

; 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 void @deleteRule(ptr noundef) #2

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

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @closeRule(ptr noundef) #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 = { 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 = { 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 #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, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !6, i64 56}
!18 = !{!"__otfcc_IClassDef", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112}


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

@otl_iClassDef = external local_unnamed_addr constant %struct.__otfcc_IClassDef, align 8

; Function Attrs: nounwind uwtable
define dso_local void @otl_dispose_chaining(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %2, 0
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  br i1 %.not, label %30, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = load ptr, ptr %5, align 8, !tbaa !10
  %.not18 = icmp eq ptr %6, null
  br i1 %.not18, label %15, label %.preheader

.preheader:                                       ; preds = %4
  %7 = load i16, ptr %3, align 8, !tbaa !10
  %.not23 = icmp eq i16 %7, 0
  br i1 %.not23, label %._crit_edge, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load ptr, ptr %5, align 8, !tbaa !10
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %8 = phi ptr [ %.pre, %._crit_edge.loopexit ], [ %6, %.preheader ]
  tail call void @free(ptr noundef %8) #3
  store ptr null, ptr %5, align 8, !tbaa !10
  br label %15

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader ]
  %9 = load ptr, ptr %5, align 8, !tbaa !10
  %10 = getelementptr inbounds ptr, ptr %9, i64 %indvars.iv
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  tail call void @deleteRule(ptr noundef %11)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i16, ptr %3, align 8, !tbaa !10
  %13 = zext i16 %12 to i64
  %14 = icmp ult i64 %indvars.iv.next, %13
  br i1 %14, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !13

15:                                               ; preds = %._crit_edge, %4
  %16 = getelementptr inbounds i8, ptr %0, i64 24
  %17 = load ptr, ptr %16, align 8, !tbaa !10
  %.not19 = icmp eq ptr %17, null
  br i1 %.not19, label %20, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @otl_iClassDef, i64 56), align 8, !tbaa !15
  tail call void %19(ptr noundef nonnull %17) #3
  br label %20

20:                                               ; preds = %18, %15
  %21 = getelementptr inbounds i8, ptr %0, i64 32
  %22 = load ptr, ptr %21, align 8, !tbaa !10
  %.not20 = icmp eq ptr %22, null
  br i1 %.not20, label %25, label %23

23:                                               ; preds = %20
  %24 = load ptr, ptr getelementptr inbounds (i8, ptr @otl_iClassDef, i64 56), align 8, !tbaa !15
  tail call void %24(ptr noundef nonnull %22) #3
  br label %25

25:                                               ; preds = %23, %20
  %26 = getelementptr inbounds i8, ptr %0, i64 40
  %27 = load ptr, ptr %26, align 8, !tbaa !10
  %.not21 = icmp eq ptr %27, null
  br i1 %.not21, label %31, label %28

28:                                               ; preds = %25
  %29 = load ptr, ptr getelementptr inbounds (i8, ptr @otl_iClassDef, i64 56), align 8, !tbaa !15
  tail call void %29(ptr noundef nonnull %27) #3
  br label %31

30:                                               ; preds = %1
  tail call void @closeRule(ptr noundef nonnull %3)
  br label %31

31:                                               ; preds = %25, %28, %30
  ret void
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @deleteRule(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @closeRule(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" }
attributes #2 = { 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 #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, !7, i64 0}
!6 = !{!"", !7, i64 0, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = !{!16, !12, i64 56}
!16 = !{!"__otfcc_IClassDef", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !12, i64 96, !12, i64 104, !12, i64 112}


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