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

; 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.table_meta = type { i32, i32, %struct.meta_Entries }
%struct.meta_Entries = type { i64, i64, ptr }
%struct.meta_Entry = type { i32, ptr }

; Function Attrs: nounwind uwtable
define dso_local ptr @otfcc_buildMeta(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %13, label %19

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.table_meta, ptr %14, i32 0, i32 2
  %16 = getelementptr inbounds %struct.meta_Entries, ptr %15, i32 0, i32 0
  %17 = load i64, ptr %16, align 8, !tbaa !9
  %18 = icmp ne i64 %17, 0
  br i1 %18, label %20, label %19

19:                                               ; preds = %13, %2
  store ptr null, ptr %3, align 8
  br label %93

20:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.table_meta, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !14
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.table_meta, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !15
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.table_meta, ptr %27, i32 0, i32 2
  %29 = getelementptr inbounds %struct.meta_Entries, ptr %28, i32 0, i32 0
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = trunc i64 %30 to i32
  %32 = call ptr (i32, ...) @bk_new_Block(i32 noundef 3, i32 noundef %23, i32 noundef 3, i32 noundef %26, i32 noundef 3, i32 noundef 0, i32 noundef 3, i32 noundef %31, i32 noundef 0)
  store ptr %32, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  store i64 0, ptr %7, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 1, ptr %8, align 8, !tbaa !16
  br label %33

33:                                               ; preds = %82, %20
  %34 = load i64, ptr %8, align 8, !tbaa !16
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %43

36:                                               ; preds = %33
  %37 = load i64, ptr %7, align 8, !tbaa !16
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.table_meta, ptr %38, i32 0, i32 2
  %40 = getelementptr inbounds %struct.meta_Entries, ptr %39, i32 0, i32 0
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = icmp ult i64 %37, %41
  br label %43

43:                                               ; preds = %36, %33
  %44 = phi i1 [ false, %33 ], [ %42, %36 ]
  br i1 %44, label %46, label %45

45:                                               ; preds = %43
  store i32 2, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  br label %90

46:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.table_meta, ptr %47, i32 0, i32 2
  %49 = getelementptr inbounds %struct.meta_Entries, ptr %48, i32 0, i32 2
  %50 = load ptr, ptr %49, align 8, !tbaa !17
  %51 = load i64, ptr %7, align 8, !tbaa !16
  %52 = getelementptr inbounds %struct.meta_Entry, ptr %50, i64 %51
  store ptr %52, ptr %10, align 8, !tbaa !5
  br label %53

53:                                               ; preds = %75, %46
  %54 = load i64, ptr %8, align 8, !tbaa !16
  %55 = icmp ne i64 %54, 0
  br i1 %55, label %57, label %56

56:                                               ; preds = %53
  store i32 5, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %81

57:                                               ; preds = %53
  %58 = load ptr, ptr %6, align 8, !tbaa !5
  %59 = load ptr, ptr %10, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.meta_Entry, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !18
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.meta_Entry, ptr %62, i32 0, i32 1
  %64 = load ptr, ptr %63, align 8, !tbaa !20
  %65 = call i64 @sdslen(ptr noundef %64)
  %66 = load ptr, ptr %10, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.meta_Entry, ptr %66, i32 0, i32 1
  %68 = load ptr, ptr %67, align 8, !tbaa !20
  %69 = call ptr @bk_newBlockFromStringLen(i64 noundef %65, ptr noundef %68)
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.meta_Entry, ptr %70, i32 0, i32 1
  %72 = load ptr, ptr %71, align 8, !tbaa !20
  %73 = call i64 @sdslen(ptr noundef %72)
  %74 = call ptr (ptr, i32, ...) @bk_push(ptr noundef %58, i32 noundef 3, i32 noundef %61, i32 noundef 17, ptr noundef %69, i32 noundef 3, i64 noundef %73, i32 noundef 0)
  br label %75

75:                                               ; preds = %57
  %76 = load i64, ptr %8, align 8, !tbaa !16
  %77 = icmp ne i64 %76, 0
  %78 = xor i1 %77, true
  %79 = zext i1 %78 to i32
  %80 = sext i32 %79 to i64
  store i64 %80, ptr %8, align 8, !tbaa !16
  br label %53, !llvm.loop !21

81:                                               ; preds = %56
  br label %82

82:                                               ; preds = %81
  %83 = load i64, ptr %8, align 8, !tbaa !16
  %84 = icmp ne i64 %83, 0
  %85 = xor i1 %84, true
  %86 = zext i1 %85 to i32
  %87 = sext i32 %86 to i64
  store i64 %87, ptr %8, align 8, !tbaa !16
  %88 = load i64, ptr %7, align 8, !tbaa !16
  %89 = add i64 %88, 1
  store i64 %89, ptr %7, align 8, !tbaa !16
  br label %33, !llvm.loop !23

90:                                               ; preds = %45
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  %92 = call ptr @bk_build_Block(ptr noundef %91)
  store ptr %92, ptr %3, align 8
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  br label %93

93:                                               ; preds = %90, %19
  %94 = load ptr, ptr %3, align 8
  ret ptr %94
}

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

declare ptr @bk_new_Block(i32 noundef, ...) #2

declare ptr @bk_push(ptr noundef, i32 noundef, ...) #2

declare ptr @bk_newBlockFromStringLen(i64 noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @sdslen(ptr noundef) #3

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

declare ptr @bk_build_Block(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 = { "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 = { 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, !13, i64 8}
!10 = !{!"", !11, i64 0, !11, i64 4, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 8, !6, i64 16}
!13 = !{!"long", !7, i64 0}
!14 = !{!10, !11, i64 0}
!15 = !{!10, !11, i64 4}
!16 = !{!13, !13, i64 0}
!17 = !{!10, !6, i64 24}
!18 = !{!19, !11, i64 0}
!19 = !{!"", !11, i64 0, !6, i64 8}
!20 = !{!19, !6, i64 8}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


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

; Function Attrs: nounwind uwtable
define dso_local ptr @otfcc_buildMeta(ptr noundef readonly %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %29, label %3

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  %5 = load i64, ptr %4, align 8, !tbaa !5
  %.not24 = icmp eq i64 %5, 0
  br i1 %.not24, label %29, label %6

6:                                                ; preds = %3
  %7 = load i32, ptr %0, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !14
  %10 = trunc i64 %5 to i32
  %11 = tail call ptr (i32, ...) @bk_new_Block(i32 noundef 3, i32 noundef %7, i32 noundef 3, i32 noundef %9, i32 noundef 3, i32 noundef 0, i32 noundef 3, i32 noundef %10, i32 noundef 0) #3
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %.not29 = icmp eq i64 %12, 0
  br i1 %.not29, label %.critedge, label %.critedge27.lr.ph

.critedge27.lr.ph:                                ; preds = %6
  %13 = getelementptr inbounds i8, ptr %0, i64 24
  br label %.critedge27

.critedge:                                        ; preds = %.critedge27, %6
  %14 = tail call ptr @bk_build_Block(ptr noundef %11) #3
  br label %29

.critedge27:                                      ; preds = %.critedge27.lr.ph, %.critedge27
  %.02128 = phi i64 [ 0, %.critedge27.lr.ph ], [ %26, %.critedge27 ]
  %15 = load ptr, ptr %13, align 8, !tbaa !15
  %16 = getelementptr inbounds %struct.meta_Entry, ptr %15, i64 %.02128
  %17 = load i32, ptr %16, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %16, i64 8
  %19 = load ptr, ptr %18, align 8, !tbaa !18
  %20 = tail call i64 @sdslen(ptr noundef %19)
  %21 = load ptr, ptr %18, align 8, !tbaa !18
  %22 = tail call ptr @bk_newBlockFromStringLen(i64 noundef %20, ptr noundef %21) #3
  %23 = load ptr, ptr %18, align 8, !tbaa !18
  %24 = tail call i64 @sdslen(ptr noundef %23)
  %25 = tail call ptr (ptr, i32, ...) @bk_push(ptr noundef %11, i32 noundef 3, i32 noundef %17, i32 noundef 17, ptr noundef %22, i32 noundef 3, i64 noundef %24, i32 noundef 0) #3
  %26 = add nuw i64 %.02128, 1
  %27 = load i64, ptr %4, align 8, !tbaa !5
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %.critedge27, label %.critedge, !llvm.loop !19

29:                                               ; preds = %2, %3, %.critedge
  %.0 = phi ptr [ %14, %.critedge ], [ null, %3 ], [ null, %2 ]
  ret ptr %.0
}

declare ptr @bk_new_Block(i32 noundef, ...) local_unnamed_addr #1

declare ptr @bk_push(ptr noundef, i32 noundef, ...) local_unnamed_addr #1

declare ptr @bk_newBlockFromStringLen(i64 noundef, ptr noundef) local_unnamed_addr #1

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

declare ptr @bk_build_Block(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 = { "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 = { 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, !11, i64 8}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"", !11, i64 0, !11, i64 8, !12, i64 16}
!11 = !{!"long", !8, i64 0}
!12 = !{!"any pointer", !8, i64 0}
!13 = !{!6, !7, i64 0}
!14 = !{!6, !7, i64 4}
!15 = !{!6, !12, i64 24}
!16 = !{!17, !7, i64 0}
!17 = !{!"", !7, i64 0, !12, i64 8}
!18 = !{!17, !12, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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