; LLVM IR from jgaeddert/liquid-dsp :: examples (interleaver_scatterplot_example)

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

@stderr = external global ptr, align 8
@.str.25 = external hidden unnamed_addr constant [46 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @interleaver_find_bit(ptr noundef %0, i32 noundef %1) #2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %23, %2
  %10 = load i32, ptr %6, align 4, !tbaa !9
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = icmp ult i32 %10, %11
  br i1 %12, label %13, label %26

13:                                               ; preds = %9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = load i32, ptr %6, align 4, !tbaa !9
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds i8, ptr %14, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = zext i8 %18 to i32
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %22

21:                                               ; preds = %13
  br label %26

22:                                               ; preds = %13
  br label %23

23:                                               ; preds = %22
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = add i32 %24, 1
  store i32 %25, ptr %6, align 4, !tbaa !9
  br label %9, !llvm.loop !12

26:                                               ; preds = %21, %9
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #4
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds i8, ptr %27, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !11
  store i8 %31, ptr %7, align 1, !tbaa !11
  %32 = load i8, ptr %7, align 1, !tbaa !11
  %33 = zext i8 %32 to i32
  switch i32 %33, label %66 [
    i32 128, label %34
    i32 64, label %38
    i32 32, label %42
    i32 16, label %46
    i32 8, label %50
    i32 4, label %54
    i32 2, label %58
    i32 1, label %62
  ]

34:                                               ; preds = %26
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = mul i32 8, %35
  %37 = add i32 %36, 0
  store i32 %37, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %69

38:                                               ; preds = %26
  %39 = load i32, ptr %6, align 4, !tbaa !9
  %40 = mul i32 8, %39
  %41 = add i32 %40, 1
  store i32 %41, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %69

42:                                               ; preds = %26
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = mul i32 8, %43
  %45 = add i32 %44, 2
  store i32 %45, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %69

46:                                               ; preds = %26
  %47 = load i32, ptr %6, align 4, !tbaa !9
  %48 = mul i32 8, %47
  %49 = add i32 %48, 3
  store i32 %49, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %69

50:                                               ; preds = %26
  %51 = load i32, ptr %6, align 4, !tbaa !9
  %52 = mul i32 8, %51
  %53 = add i32 %52, 4
  store i32 %53, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %69

54:                                               ; preds = %26
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = mul i32 8, %55
  %57 = add i32 %56, 5
  store i32 %57, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %69

58:                                               ; preds = %26
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = mul i32 8, %59
  %61 = add i32 %60, 6
  store i32 %61, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %69

62:                                               ; preds = %26
  %63 = load i32, ptr %6, align 4, !tbaa !9
  %64 = mul i32 8, %63
  %65 = add i32 %64, 7
  store i32 %65, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %69

66:                                               ; preds = %26
  %67 = load ptr, ptr @stderr, align 8, !tbaa !5
  %68 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %67, ptr noundef @.str.25) #4
  call void @exit(i32 noundef 1) #5
  unreachable

69:                                               ; preds = %62, %58, %54, %50, %46, %42, %38, %34
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %70 = load i32, ptr %3, align 4
  ret i32 %70
}

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn 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 #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 = { 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 }
attributes #5 = { noreturn 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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@.str.25 = external hidden unnamed_addr constant [46 x i8], align 1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local i32 @interleaver_find_bit(ptr nocapture noundef readonly %0, i32 noundef %1) local_unnamed_addr #1 {
  %.not20 = icmp eq i32 %1, 0
  br i1 %.not20, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %wide.trip.count = zext i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %5
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %5 ]
  %3 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %5, label %._crit_edge.loopexit.split.loop.exit

5:                                                ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge.loopexit.split.loop.exit:             ; preds = %.lr.ph
  %6 = trunc nuw i64 %indvars.iv to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %5, %._crit_edge.loopexit.split.loop.exit, %2
  %.016.lcssa = phi i32 [ 0, %2 ], [ %6, %._crit_edge.loopexit.split.loop.exit ], [ %1, %5 ]
  %7 = zext i32 %.016.lcssa to i64
  %8 = getelementptr inbounds i8, ptr %0, i64 %7
  %9 = load i8, ptr %8, align 1, !tbaa !5
  switch i8 %9, label %33 [
    i8 -128, label %10
    i8 64, label %12
    i8 32, label %15
    i8 16, label %18
    i8 8, label %21
    i8 4, label %24
    i8 2, label %27
    i8 1, label %30
  ]

10:                                               ; preds = %._crit_edge
  %11 = shl i32 %.016.lcssa, 3
  br label %36

12:                                               ; preds = %._crit_edge
  %13 = shl i32 %.016.lcssa, 3
  %14 = or disjoint i32 %13, 1
  br label %36

15:                                               ; preds = %._crit_edge
  %16 = shl i32 %.016.lcssa, 3
  %17 = or disjoint i32 %16, 2
  br label %36

18:                                               ; preds = %._crit_edge
  %19 = shl i32 %.016.lcssa, 3
  %20 = or disjoint i32 %19, 3
  br label %36

21:                                               ; preds = %._crit_edge
  %22 = shl i32 %.016.lcssa, 3
  %23 = or disjoint i32 %22, 4
  br label %36

24:                                               ; preds = %._crit_edge
  %25 = shl i32 %.016.lcssa, 3
  %26 = or disjoint i32 %25, 5
  br label %36

27:                                               ; preds = %._crit_edge
  %28 = shl i32 %.016.lcssa, 3
  %29 = or disjoint i32 %28, 6
  br label %36

30:                                               ; preds = %._crit_edge
  %31 = shl i32 %.016.lcssa, 3
  %32 = or disjoint i32 %31, 7
  br label %36

33:                                               ; preds = %._crit_edge
  %34 = load ptr, ptr @stderr, align 8, !tbaa !10
  %35 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %34, ptr noundef nonnull @.str.25) #3
  tail call void @exit(i32 noundef 1) #4
  unreachable

36:                                               ; preds = %30, %27, %24, %21, %18, %15, %12, %10
  %.0 = phi i32 [ %32, %30 ], [ %29, %27 ], [ %26, %24 ], [ %23, %21 ], [ %20, %18 ], [ %17, %15 ], [ %14, %12 ], [ %11, %10 ]
  ret i32 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #2

attributes #0 = { noreturn 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 #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 = { nofree 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 = { cold nounwind }
attributes #4 = { noreturn 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !6, i64 0}


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