; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare ptr @bsc_zero_malloc(i64 noundef) #1

declare void @bsc_free(ptr 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: mustprogress uwtable
define dso_local i32 @bsc_st_decode(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #2 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca [256 x i32], align 16
  %15 = alloca i8, align 1
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store i32 %4, ptr %11, align 4, !tbaa !9
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %22, label %19

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

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

23:                                               ; preds = %19
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = icmp slt i32 %24, 0
  br i1 %25, label %30, label %26

26:                                               ; preds = %23
  %27 = load i32, ptr %10, align 4, !tbaa !9
  %28 = load i32, ptr %8, align 4, !tbaa !9
  %29 = icmp sge i32 %27, %28
  br i1 %29, label %30, label %31

30:                                               ; preds = %26, %23
  store i32 -1, ptr %6, align 4
  br label %81

31:                                               ; preds = %26
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = icmp slt i32 %32, 3
  br i1 %33, label %37, label %34

34:                                               ; preds = %31
  %35 = load i32, ptr %9, align 4, !tbaa !9
  %36 = icmp sgt i32 %35, 8
  br i1 %36, label %37, label %38

37:                                               ; preds = %34, %31
  store i32 -1, ptr %6, align 4
  br label %81

38:                                               ; preds = %34
  %39 = load i32, ptr %8, align 4, !tbaa !9
  %40 = icmp sle i32 %39, 1
  br i1 %40, label %41, label %42

41:                                               ; preds = %38
  store i32 0, ptr %6, align 4
  br label %81

42:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %43 = load i32, ptr %8, align 4, !tbaa !9
  %44 = sext i32 %43 to i64
  %45 = mul i64 %44, 4
  %46 = call ptr @bsc_zero_malloc(i64 noundef %45)
  store ptr %46, ptr %12, align 8, !tbaa !5
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %77

49:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #5
  %50 = call ptr @bsc_zero_malloc(i64 noundef 262144)
  store ptr %50, ptr %13, align 8, !tbaa !5
  %51 = load ptr, ptr %13, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %72

53:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 1024, ptr %14) #5
  %54 = getelementptr inbounds [256 x i32], ptr %14, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %54, i8 0, i64 1024, i1 false)
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #5
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = getelementptr inbounds [256 x i32], ptr %14, i64 0, i64 0
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load i32, ptr %8, align 4, !tbaa !9
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = call noundef zeroext i1 @_ZL20bsc_unst_sort_serialPhPjS0_S0_ii(ptr noundef %55, ptr noundef %56, ptr noundef %57, ptr noundef %58, i32 noundef %59, i32 noundef %60)
  %62 = zext i1 %61 to i8
  store i8 %62, ptr %15, align 1, !tbaa !11
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = getelementptr inbounds [256 x i32], ptr %14, i64 0, i64 0
  %66 = load i32, ptr %8, align 4, !tbaa !9
  %67 = load i32, ptr %10, align 4, !tbaa !9
  %68 = load i8, ptr %15, align 1, !tbaa !11, !range !13, !noundef !14
  %69 = trunc i8 %68 to i1
  call void @_ZL27bsc_unst_reconstruct_serialPhPjS0_iib(ptr noundef %63, ptr noundef %64, ptr noundef %65, i32 noundef %66, i32 noundef %67, i1 noundef zeroext %69)
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #5
  %70 = load ptr, ptr %13, align 8, !tbaa !5
  call void @bsc_free(ptr noundef %70)
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  call void @bsc_free(ptr noundef %71)
  store i32 0, ptr %6, align 4
  store i32 1, ptr %16, align 4
  call void @llvm.lifetime.end.p0(i64 1024, ptr %14) #5
  br label %73

72:                                               ; preds = %49
  store i32 0, ptr %16, align 4
  br label %73

73:                                               ; preds = %72, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #5
  %74 = load i32, ptr %16, align 4
  switch i32 %74, label %78 [
    i32 0, label %75
  ]

75:                                               ; preds = %73
  %76 = load ptr, ptr %12, align 8, !tbaa !5
  call void @bsc_free(ptr noundef %76)
  br label %77

77:                                               ; preds = %75, %42
  store i32 0, ptr %16, align 4
  br label %78

78:                                               ; preds = %77, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %79 = load i32, ptr %16, align 4
  switch i32 %79, label %83 [
    i32 0, label %80
    i32 1, label %81
  ]

80:                                               ; preds = %78
  store i32 -2, ptr %6, align 4
  br label %81

81:                                               ; preds = %80, %78, %41, %37, %30, %22
  %82 = load i32, ptr %6, align 4
  ret i32 %82

83:                                               ; preds = %78
  unreachable
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL20bsc_unst_sort_serialPhPjS0_S0_ii(ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, i32 noundef, i32 noundef) #4

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL27bsc_unst_reconstruct_serialPhPjS0_iib(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, i1 noundef zeroext) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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" }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { mustprogress 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


; 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

declare ptr @bsc_zero_malloc(i64 noundef) local_unnamed_addr #1

declare void @bsc_free(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress uwtable
define dso_local range(i32 -2, 1) i32 @bsc_st_decode(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca [256 x i32], align 16
  %7 = icmp eq ptr %0, null
  %8 = icmp slt i32 %1, 0
  %or.cond = or i1 %7, %8
  br i1 %or.cond, label %21, label %9

9:                                                ; preds = %5
  %or.cond39 = icmp uge i32 %3, %1
  %10 = add i32 %2, -9
  %or.cond3 = icmp ult i32 %10, -6
  %or.cond40 = or i1 %or.cond39, %or.cond3
  br i1 %or.cond40, label %21, label %11

11:                                               ; preds = %9
  %12 = icmp ult i32 %1, 2
  br i1 %12, label %21, label %13

13:                                               ; preds = %11
  %14 = zext nneg i32 %1 to i64
  %15 = shl nuw nsw i64 %14, 2
  %16 = tail call ptr @bsc_zero_malloc(i64 noundef %15)
  %.not37 = icmp eq ptr %16, null
  br i1 %.not37, label %21, label %17

17:                                               ; preds = %13
  %18 = tail call ptr @bsc_zero_malloc(i64 noundef 262144)
  %.not38 = icmp eq ptr %18, null
  br i1 %.not38, label %.critedge, label %19

.critedge:                                        ; preds = %17
  tail call void @bsc_free(ptr noundef nonnull %16)
  br label %21

19:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %6) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1024) %6, i8 0, i64 1024, i1 false)
  %20 = call noundef zeroext i1 @_ZL20bsc_unst_sort_serialPhPjS0_S0_ii(ptr noundef nonnull %0, ptr noundef nonnull %16, ptr noundef nonnull %6, ptr noundef nonnull %18, i32 noundef %1, i32 noundef %2)
  call void @_ZL27bsc_unst_reconstruct_serialPhPjS0_iib(ptr noundef nonnull %0, ptr noundef nonnull %16, ptr noundef nonnull %6, i32 noundef %1, i32 noundef %3, i1 noundef zeroext %20)
  call void @bsc_free(ptr noundef nonnull %18)
  call void @bsc_free(ptr noundef nonnull %16)
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %6) #5
  br label %21

21:                                               ; preds = %19, %.critedge, %13, %11, %9, %5
  %.3 = phi i32 [ -1, %5 ], [ -1, %9 ], [ 0, %11 ], [ 0, %19 ], [ -2, %.critedge ], [ -2, %13 ]
  ret i32 %.3
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZL20bsc_unst_sort_serialPhPjS0_S0_ii(ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, ptr noalias noundef, i32 noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL27bsc_unst_reconstruct_serialPhPjS0_iib(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, i1 noundef zeroext) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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" }
attributes #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { mustprogress 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 #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)"}


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