; LLVM IR from caryll/otfcc :: lib/bk (bkgraph)

; 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.bk_Graph = type { i32, i32, ptr }
%struct.bk_GraphNode = type { i32, i32, i32, i32, ptr }
%struct.__caryll_bkblock = type { i32, i32, i32, i32, i32, i32, ptr }

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

; Function Attrs: nounwind uwtable
define dso_local ptr @bk_build_Graph(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %7 = call ptr (...) @bufnew()
  store ptr %7, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  %8 = load ptr, ptr %2, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.bk_Graph, ptr %8, i32 0, i32 0
  %10 = load i32, ptr %9, align 8, !tbaa !9
  %11 = add i32 %10, 1
  %12 = zext i32 %11 to i64
  %13 = mul i64 8, %12
  %14 = call ptr @__caryll_allocate_clean(i64 noundef %13, i64 noundef 349)
  store ptr %14, ptr %4, align 8, !tbaa !5
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds i64, ptr %15, i64 0
  store i64 0, ptr %16, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %17

17:                                               ; preds = %69, %1
  %18 = load i32, ptr %5, align 4, !tbaa !14
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.bk_Graph, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = icmp ult i32 %18, %21
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %17
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.bk_Graph, ptr %25, i32 0, i32 2
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = load i32, ptr %5, align 4, !tbaa !14
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds %struct.bk_GraphNode, ptr %27, i64 %29
  %31 = getelementptr inbounds %struct.bk_GraphNode, ptr %30, i32 0, i32 4
  %32 = load ptr, ptr %31, align 8, !tbaa !16
  %33 = getelementptr inbounds %struct.__caryll_bkblock, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 8, !tbaa !18
  %35 = icmp eq i32 %34, 2
  br i1 %35, label %36, label %57

36:                                               ; preds = %24
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !14
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds i64, ptr %37, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !12
  %42 = load ptr, ptr %2, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.bk_Graph, ptr %42, i32 0, i32 2
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = load i32, ptr %5, align 4, !tbaa !14
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds %struct.bk_GraphNode, ptr %44, i64 %46
  %48 = getelementptr inbounds %struct.bk_GraphNode, ptr %47, i32 0, i32 4
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = call i64 @otfcc_bkblock_size(ptr noundef %49)
  %51 = add i64 %41, %50
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = load i32, ptr %5, align 4, !tbaa !14
  %54 = add i32 %53, 1
  %55 = zext i32 %54 to i64
  %56 = getelementptr inbounds i64, ptr %52, i64 %55
  store i64 %51, ptr %56, align 8, !tbaa !12
  br label %68

57:                                               ; preds = %24
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = load i32, ptr %5, align 4, !tbaa !14
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds i64, ptr %58, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !12
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = load i32, ptr %5, align 4, !tbaa !14
  %65 = add i32 %64, 1
  %66 = zext i32 %65 to i64
  %67 = getelementptr inbounds i64, ptr %63, i64 %66
  store i64 %62, ptr %67, align 8, !tbaa !12
  br label %68

68:                                               ; preds = %57, %36
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %5, align 4, !tbaa !14
  %71 = add i32 %70, 1
  store i32 %71, ptr %5, align 4, !tbaa !14
  br label %17, !llvm.loop !20

72:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !14
  br label %73

73:                                               ; preds = %104, %72
  %74 = load i32, ptr %6, align 4, !tbaa !14
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.bk_Graph, ptr %75, i32 0, i32 0
  %77 = load i32, ptr %76, align 8, !tbaa !9
  %78 = icmp ult i32 %74, %77
  br i1 %78, label %80, label %79

79:                                               ; preds = %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %107

80:                                               ; preds = %73
  %81 = load ptr, ptr %2, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.bk_Graph, ptr %81, i32 0, i32 2
  %83 = load ptr, ptr %82, align 8, !tbaa !15
  %84 = load i32, ptr %6, align 4, !tbaa !14
  %85 = zext i32 %84 to i64
  %86 = getelementptr inbounds %struct.bk_GraphNode, ptr %83, i64 %85
  %87 = getelementptr inbounds %struct.bk_GraphNode, ptr %86, i32 0, i32 4
  %88 = load ptr, ptr %87, align 8, !tbaa !16
  %89 = getelementptr inbounds %struct.__caryll_bkblock, ptr %88, i32 0, i32 0
  %90 = load i32, ptr %89, align 8, !tbaa !18
  %91 = icmp eq i32 %90, 2
  br i1 %91, label %92, label %103

92:                                               ; preds = %80
  %93 = load ptr, ptr %3, align 8, !tbaa !5
  %94 = load ptr, ptr %2, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.bk_Graph, ptr %94, i32 0, i32 2
  %96 = load ptr, ptr %95, align 8, !tbaa !15
  %97 = load i32, ptr %6, align 4, !tbaa !14
  %98 = zext i32 %97 to i64
  %99 = getelementptr inbounds %struct.bk_GraphNode, ptr %96, i64 %98
  %100 = getelementptr inbounds %struct.bk_GraphNode, ptr %99, i32 0, i32 4
  %101 = load ptr, ptr %100, align 8, !tbaa !16
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  call void @otfcc_build_bkblock(ptr noundef %93, ptr noundef %101, ptr noundef %102)
  br label %103

103:                                              ; preds = %92, %80
  br label %104

104:                                              ; preds = %103
  %105 = load i32, ptr %6, align 4, !tbaa !14
  %106 = add i32 %105, 1
  store i32 %106, ptr %6, align 4, !tbaa !14
  br label %73, !llvm.loop !22

107:                                              ; preds = %79
  %108 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %108) #5
  store ptr null, ptr %4, align 8, !tbaa !5
  %109 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret ptr %109
}

declare ptr @bufnew(...) #4

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

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

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


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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @bk_build_Graph(ptr nocapture noundef readonly %0) local_unnamed_addr #2 {
  %2 = tail call ptr (...) @bufnew() #4
  %3 = load i32, ptr %0, align 8, !tbaa !5
  %4 = add i32 %3, 1
  %5 = zext i32 %4 to i64
  %6 = shl nuw nsw i64 %5, 3
  %7 = tail call ptr @__caryll_allocate_clean(i64 noundef %6, i64 noundef 349)
  store i64 0, ptr %7, align 8, !tbaa !11
  %8 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  br label %11

.preheader:                                       ; preds = %28
  %.not31 = icmp eq i32 %29, 0
  br i1 %.not31, label %._crit_edge, label %.lr.ph30

.lr.ph30:                                         ; preds = %.preheader
  %10 = getelementptr inbounds i8, ptr %0, i64 8
  br label %32

11:                                               ; preds = %.lr.ph, %28
  %12 = phi i32 [ %8, %.lr.ph ], [ %29, %28 ]
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next.pre-phi, %28 ]
  %13 = load ptr, ptr %9, align 8, !tbaa !13
  %14 = getelementptr inbounds %struct.bk_GraphNode, ptr %13, i64 %indvars.iv, i32 4
  %15 = load ptr, ptr %14, align 8, !tbaa !14
  %16 = load i32, ptr %15, align 8, !tbaa !16
  %17 = icmp eq i32 %16, 2
  %18 = getelementptr inbounds i64, ptr %7, i64 %indvars.iv
  %19 = load i64, ptr %18, align 8, !tbaa !11
  br i1 %17, label %20, label %25

20:                                               ; preds = %11
  %21 = tail call i64 @otfcc_bkblock_size(ptr noundef nonnull %15)
  %22 = add i64 %21, %19
  %23 = add nuw nsw i64 %indvars.iv, 1
  %24 = getelementptr inbounds i64, ptr %7, i64 %23
  store i64 %22, ptr %24, align 8, !tbaa !11
  %.pre = load i32, ptr %0, align 8, !tbaa !5
  br label %28

25:                                               ; preds = %11
  %26 = add nuw nsw i64 %indvars.iv, 1
  %27 = getelementptr inbounds i64, ptr %7, i64 %26
  store i64 %19, ptr %27, align 8, !tbaa !11
  br label %28

28:                                               ; preds = %20, %25
  %indvars.iv.next.pre-phi = phi i64 [ %23, %20 ], [ %26, %25 ]
  %29 = phi i32 [ %.pre, %20 ], [ %12, %25 ]
  %30 = zext i32 %29 to i64
  %31 = icmp ult i64 %indvars.iv.next.pre-phi, %30
  br i1 %31, label %11, label %.preheader, !llvm.loop !18

._crit_edge:                                      ; preds = %40, %1, %.preheader
  tail call void @free(ptr noundef %7) #4
  ret ptr %2

32:                                               ; preds = %.lr.ph30, %40
  %33 = phi i32 [ %29, %.lr.ph30 ], [ %41, %40 ]
  %indvars.iv33 = phi i64 [ 0, %.lr.ph30 ], [ %indvars.iv.next34, %40 ]
  %34 = load ptr, ptr %10, align 8, !tbaa !13
  %35 = getelementptr inbounds %struct.bk_GraphNode, ptr %34, i64 %indvars.iv33, i32 4
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = load i32, ptr %36, align 8, !tbaa !16
  %38 = icmp eq i32 %37, 2
  br i1 %38, label %39, label %40

39:                                               ; preds = %32
  tail call void @otfcc_build_bkblock(ptr noundef %2, ptr noundef nonnull %36, ptr noundef nonnull %7)
  %.pre36 = load i32, ptr %0, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %32, %39
  %41 = phi i32 [ %33, %32 ], [ %.pre36, %39 ]
  %indvars.iv.next34 = add nuw nsw i64 %indvars.iv33, 1
  %42 = zext i32 %41 to i64
  %43 = icmp ult i64 %indvars.iv.next34, %42
  br i1 %43, label %32, label %._crit_edge, !llvm.loop !20
}

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

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

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

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


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