; 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"

; 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 void @bk_untangleGraph(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca i16, align 2
  %4 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 2, ptr %3) #2
  store i16 0, ptr %3, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  store i8 0, ptr %4, align 1, !tbaa !11
  %5 = load ptr, ptr %2, align 8, !tbaa !5
  call void @attract_bkgraph(ptr noundef %5)
  br label %6

6:                                                ; preds = %25, %1
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = load i16, ptr %3, align 2, !tbaa !9
  %9 = call zeroext i1 @try_untangle(ptr noundef %7, i16 noundef zeroext %8)
  %10 = zext i1 %9 to i8
  store i8 %10, ptr %4, align 1, !tbaa !11
  %11 = load i8, ptr %4, align 1, !tbaa !11, !range !13, !noundef !14
  %12 = trunc i8 %11 to i1
  br i1 %12, label %13, label %15

13:                                               ; preds = %6
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  call void @attract_bkgraph(ptr noundef %14)
  br label %15

15:                                               ; preds = %13, %6
  %16 = load i16, ptr %3, align 2, !tbaa !9
  %17 = add i16 %16, 1
  store i16 %17, ptr %3, align 2, !tbaa !9
  br label %18

18:                                               ; preds = %15
  %19 = load i8, ptr %4, align 1, !tbaa !11, !range !13, !noundef !14
  %20 = trunc i8 %19 to i1
  br i1 %20, label %21, label %25

21:                                               ; preds = %18
  %22 = load i16, ptr %3, align 2, !tbaa !9
  %23 = zext i16 %22 to i32
  %24 = icmp slt i32 %23, 16
  br label %25

25:                                               ; preds = %21, %18
  %26 = phi i1 [ false, %18 ], [ %24, %21 ]
  br i1 %26, label %6, label %27, !llvm.loop !15

27:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 2, ptr %3) #2
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @try_untangle(ptr noundef, i16 noundef zeroext) #1

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 = { 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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"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 void @bk_untangleGraph(ptr noundef %0) local_unnamed_addr #0 {
  tail call void @attract_bkgraph(ptr noundef %0)
  %2 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 0)
  br i1 %2, label %3, label %.thread

3:                                                ; preds = %1
  tail call void @attract_bkgraph(ptr noundef %0)
  %4 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 1)
  br i1 %4, label %5, label %.thread

5:                                                ; preds = %3
  tail call void @attract_bkgraph(ptr noundef %0)
  %6 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 2)
  br i1 %6, label %7, label %.thread

7:                                                ; preds = %5
  tail call void @attract_bkgraph(ptr noundef %0)
  %8 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 3)
  br i1 %8, label %9, label %.thread

9:                                                ; preds = %7
  tail call void @attract_bkgraph(ptr noundef %0)
  %10 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 4)
  br i1 %10, label %11, label %.thread

11:                                               ; preds = %9
  tail call void @attract_bkgraph(ptr noundef %0)
  %12 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 5)
  br i1 %12, label %13, label %.thread

13:                                               ; preds = %11
  tail call void @attract_bkgraph(ptr noundef %0)
  %14 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 6)
  br i1 %14, label %15, label %.thread

15:                                               ; preds = %13
  tail call void @attract_bkgraph(ptr noundef %0)
  %16 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 7)
  br i1 %16, label %17, label %.thread

17:                                               ; preds = %15
  tail call void @attract_bkgraph(ptr noundef %0)
  %18 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 8)
  br i1 %18, label %19, label %.thread

19:                                               ; preds = %17
  tail call void @attract_bkgraph(ptr noundef %0)
  %20 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 9)
  br i1 %20, label %21, label %.thread

21:                                               ; preds = %19
  tail call void @attract_bkgraph(ptr noundef %0)
  %22 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 10)
  br i1 %22, label %23, label %.thread

23:                                               ; preds = %21
  tail call void @attract_bkgraph(ptr noundef %0)
  %24 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 11)
  br i1 %24, label %25, label %.thread

25:                                               ; preds = %23
  tail call void @attract_bkgraph(ptr noundef %0)
  %26 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 12)
  br i1 %26, label %27, label %.thread

27:                                               ; preds = %25
  tail call void @attract_bkgraph(ptr noundef %0)
  %28 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 13)
  br i1 %28, label %29, label %.thread

29:                                               ; preds = %27
  tail call void @attract_bkgraph(ptr noundef %0)
  %30 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 14)
  br i1 %30, label %31, label %.thread

31:                                               ; preds = %29
  tail call void @attract_bkgraph(ptr noundef %0)
  %32 = tail call zeroext i1 @try_untangle(ptr noundef %0, i16 noundef zeroext 15)
  br i1 %32, label %33, label %.thread

33:                                               ; preds = %31
  tail call void @attract_bkgraph(ptr noundef %0)
  br label %.thread

.thread:                                          ; preds = %33, %31, %29, %27, %25, %23, %21, %19, %17, %15, %13, %11, %9, %7, %5, %3, %1
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @try_untangle(ptr noundef, i16 noundef zeroext) local_unnamed_addr #0

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" }

!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)"}


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