; LLVM IR from IlyaGrebnov/libbsc :: libbsc/st (st)

; 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: mustprogress uwtable
declare dso_local noundef i32 @_Z14bsc_st3_encodePhii(ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z14bsc_st4_encodePhii(ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z14bsc_st5_encodePhii(ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z14bsc_st6_encodePhii(ptr noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local i32 @bsc_st_encode(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  %10 = load ptr, ptr %6, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %15, label %12

12:                                               ; preds = %4
  %13 = load i32, ptr %7, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %12, %4
  store i32 -1, ptr %5, align 4
  br label %60

16:                                               ; preds = %12
  %17 = load i32, ptr %8, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 3
  br i1 %18, label %22, label %19

19:                                               ; preds = %16
  %20 = load i32, ptr %8, align 4, !tbaa !9
  %21 = icmp sgt i32 %20, 8
  br i1 %21, label %22, label %23

22:                                               ; preds = %19, %16
  store i32 -1, ptr %5, align 4
  br label %60

23:                                               ; preds = %19
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = icmp sle i32 %24, 1
  br i1 %25, label %26, label %27

26:                                               ; preds = %23
  store i32 0, ptr %5, align 4
  br label %60

27:                                               ; preds = %23
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = icmp eq i32 %28, 3
  br i1 %29, label %30, label %35

30:                                               ; preds = %27
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = call noundef i32 @_Z14bsc_st3_encodePhii(ptr noundef %31, i32 noundef %32, i32 noundef %33)
  store i32 %34, ptr %5, align 4
  br label %60

35:                                               ; preds = %27
  %36 = load i32, ptr %8, align 4, !tbaa !9
  %37 = icmp eq i32 %36, 4
  br i1 %37, label %38, label %43

38:                                               ; preds = %35
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load i32, ptr %7, align 4, !tbaa !9
  %41 = load i32, ptr %9, align 4, !tbaa !9
  %42 = call noundef i32 @_Z14bsc_st4_encodePhii(ptr noundef %39, i32 noundef %40, i32 noundef %41)
  store i32 %42, ptr %5, align 4
  br label %60

43:                                               ; preds = %35
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = icmp eq i32 %44, 5
  br i1 %45, label %46, label %51

46:                                               ; preds = %43
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = load i32, ptr %9, align 4, !tbaa !9
  %50 = call noundef i32 @_Z14bsc_st5_encodePhii(ptr noundef %47, i32 noundef %48, i32 noundef %49)
  store i32 %50, ptr %5, align 4
  br label %60

51:                                               ; preds = %43
  %52 = load i32, ptr %8, align 4, !tbaa !9
  %53 = icmp eq i32 %52, 6
  br i1 %53, label %54, label %59

54:                                               ; preds = %51
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !9
  %57 = load i32, ptr %9, align 4, !tbaa !9
  %58 = call noundef i32 @_Z14bsc_st6_encodePhii(ptr noundef %55, i32 noundef %56, i32 noundef %57)
  store i32 %58, ptr %5, align 4
  br label %60

59:                                               ; preds = %51
  store i32 -4, ptr %5, align 4
  br label %60

60:                                               ; preds = %59, %54, %46, %38, %30, %26, %22, %15
  %61 = load i32, ptr %5, align 4
  ret i32 %61
}

attributes #0 = { mustprogress 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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; 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: mustprogress uwtable
declare dso_local noundef i32 @_Z14bsc_st3_encodePhii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z14bsc_st4_encodePhii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z14bsc_st5_encodePhii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z14bsc_st6_encodePhii(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @bsc_st_encode(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %0, null
  %6 = icmp slt i32 %1, 0
  %or.cond = or i1 %5, %6
  %7 = add i32 %2, -9
  %or.cond3 = icmp ult i32 %7, -6
  %or.cond27 = or i1 %or.cond, %or.cond3
  br i1 %or.cond27, label %19, label %8

8:                                                ; preds = %4
  %9 = icmp ult i32 %1, 2
  br i1 %9, label %19, label %10

10:                                               ; preds = %8
  switch i32 %2, label %19 [
    i32 3, label %11
    i32 4, label %13
    i32 5, label %15
    i32 6, label %17
  ]

11:                                               ; preds = %10
  %12 = tail call noundef i32 @_Z14bsc_st3_encodePhii(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %3)
  br label %19

13:                                               ; preds = %10
  %14 = tail call noundef i32 @_Z14bsc_st4_encodePhii(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %3)
  br label %19

15:                                               ; preds = %10
  %16 = tail call noundef i32 @_Z14bsc_st5_encodePhii(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %3)
  br label %19

17:                                               ; preds = %10
  %18 = tail call noundef i32 @_Z14bsc_st6_encodePhii(ptr noundef nonnull %0, i32 noundef %1, i32 noundef %3)
  br label %19

19:                                               ; preds = %10, %8, %4, %17, %15, %13, %11
  %.0 = phi i32 [ %12, %11 ], [ %14, %13 ], [ %16, %15 ], [ %18, %17 ], [ -1, %4 ], [ 0, %8 ], [ -4, %10 ]
  ret i32 %.0
}

attributes #0 = { mustprogress 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,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass