; LLVM IR from jgaeddert/liquid-dsp :: src/utility/tests (pack_bytes_autotest)

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

@.str = external hidden unnamed_addr constant [94 x i8], align 1
@liquid_autotest_verbose = external global i32, align 4
@.str.3 = external hidden unnamed_addr constant [27 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

declare i32 @liquid_pack_array(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i8 noundef zeroext) #1

declare i32 @liquid_autotest_same_data(ptr noundef, ptr noundef, i32 noundef) #1

declare void @liquid_autotest_failed_msg(ptr noundef, i32 noundef, ptr noundef) #1

declare void @liquid_autotest_print_array(ptr noundef, i32 noundef) #1

declare void @liquid_autotest_passed(...) #1

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

declare i32 @liquid_unpack_array(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @autotest_repack_array() #2 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i8, align 1
  %8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #5
  store i32 512, ptr %1, align 4, !tbaa !5
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %10 = zext i32 %9 to i64
  %11 = call ptr @llvm.stacksave.p0()
  store ptr %11, ptr %2, align 8
  %12 = alloca i8, i64 %10, align 16
  store i64 %10, ptr %3, align 8
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = zext i32 %13 to i64
  %15 = alloca i8, i64 %14, align 16
  store i64 %14, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %30, %0
  %17 = load i32, ptr %5, align 4, !tbaa !5
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = icmp ult i32 %17, %18
  br i1 %19, label %20, label %33

20:                                               ; preds = %16
  %21 = call i32 @rand() #5
  %22 = and i32 %21, 255
  %23 = trunc i32 %22 to i8
  %24 = load i32, ptr %5, align 4, !tbaa !5
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %12, i64 %25
  store i8 %23, ptr %26, align 1, !tbaa !9
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = zext i32 %27 to i64
  %29 = getelementptr inbounds i8, ptr %15, i64 %28
  store i8 0, ptr %29, align 1, !tbaa !9
  br label %30

30:                                               ; preds = %20
  %31 = load i32, ptr %5, align 4, !tbaa !5
  %32 = add i32 %31, 1
  store i32 %32, ptr %5, align 4, !tbaa !5
  br label %16, !llvm.loop !10

33:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #5
  store i8 0, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %39, %33
  %35 = load i32, ptr %6, align 4, !tbaa !5
  %36 = load i32, ptr %1, align 4, !tbaa !5
  %37 = mul i32 8, %36
  %38 = icmp ult i32 %35, %37
  br i1 %38, label %39, label %55

39:                                               ; preds = %34
  %40 = call i32 @rand() #5
  %41 = srem i32 %40, 8
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %8, align 4, !tbaa !5
  %43 = load i32, ptr %1, align 4, !tbaa !5
  %44 = load i32, ptr %6, align 4, !tbaa !5
  %45 = load i32, ptr %8, align 4, !tbaa !5
  %46 = call i32 @liquid_unpack_array(ptr noundef %12, i32 noundef %43, i32 noundef %44, i32 noundef %45, ptr noundef %7)
  %47 = load i32, ptr %1, align 4, !tbaa !5
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = load i8, ptr %7, align 1, !tbaa !9
  %51 = call i32 @liquid_pack_array(ptr noundef %15, i32 noundef %47, i32 noundef %48, i32 noundef %49, i8 noundef zeroext %50)
  %52 = load i32, ptr %8, align 4, !tbaa !5
  %53 = load i32, ptr %6, align 4, !tbaa !5
  %54 = add i32 %53, %52
  store i32 %54, ptr %6, align 4, !tbaa !5
  br label %34, !llvm.loop !12

55:                                               ; preds = %34
  %56 = load i32, ptr %1, align 4, !tbaa !5
  %57 = call i32 @liquid_autotest_same_data(ptr noundef %12, ptr noundef %15, i32 noundef %56)
  %58 = icmp ne i32 %57, 0
  br i1 %58, label %66, label %59

59:                                               ; preds = %55
  call void @liquid_autotest_failed_msg(ptr noundef @.str, i32 noundef 127, ptr noundef @.str.3)
  %60 = load i32, ptr @liquid_autotest_verbose, align 4, !tbaa !5
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %65

62:                                               ; preds = %59
  %63 = load i32, ptr %1, align 4, !tbaa !5
  call void @liquid_autotest_print_array(ptr noundef %12, i32 noundef %63)
  %64 = load i32, ptr %1, align 4, !tbaa !5
  call void @liquid_autotest_print_array(ptr noundef %15, i32 noundef %64)
  br label %65

65:                                               ; preds = %62, %59
  br label %67

66:                                               ; preds = %55
  call void (...) @liquid_autotest_passed()
  br label %67

67:                                               ; preds = %66, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  %68 = load ptr, ptr %2, align 8
  call void @llvm.stackrestore.p0(ptr %68)
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #5
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

; Function Attrs: nounwind
declare i32 @rand() #4

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

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 = { 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 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

@.str = external hidden unnamed_addr constant [94 x i8], align 1
@liquid_autotest_verbose = external local_unnamed_addr global i32, align 4
@.str.3 = external hidden unnamed_addr constant [27 x i8], align 1

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

declare i32 @liquid_pack_array(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i8 noundef zeroext) local_unnamed_addr #1

declare i32 @liquid_autotest_same_data(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @liquid_autotest_failed_msg(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare void @liquid_autotest_print_array(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @liquid_autotest_passed(...) 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

declare i32 @liquid_unpack_array(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @autotest_repack_array() local_unnamed_addr #2 {
  %1 = alloca i8, align 1
  %2 = alloca [512 x i8], align 16
  %3 = alloca [512 x i8], align 16
  br label %4

4:                                                ; preds = %0, %4
  %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %4 ]
  %5 = tail call i32 @rand() #4
  %6 = trunc i32 %5 to i8
  %7 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv
  store i8 %6, ptr %7, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %3, i64 %indvars.iv
  store i8 0, ptr %8, align 1, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 512
  br i1 %exitcond.not, label %9, label %4, !llvm.loop !8

9:                                                ; preds = %4
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %1) #4
  store i8 0, ptr %1, align 1, !tbaa !5
  br label %10

10:                                               ; preds = %9, %10
  %.023 = phi i32 [ 0, %9 ], [ %17, %10 ]
  %11 = call i32 @rand() #4
  %12 = srem i32 %11, 8
  %13 = add nsw i32 %12, 1
  %14 = call i32 @liquid_unpack_array(ptr noundef nonnull %2, i32 noundef 512, i32 noundef %.023, i32 noundef %13, ptr noundef nonnull %1) #4
  %15 = load i8, ptr %1, align 1, !tbaa !5
  %16 = call i32 @liquid_pack_array(ptr noundef nonnull %3, i32 noundef 512, i32 noundef %.023, i32 noundef %13, i8 noundef zeroext %15) #4
  %17 = add nsw i32 %13, %.023
  %18 = icmp ult i32 %17, 4096
  br i1 %18, label %10, label %19, !llvm.loop !10

19:                                               ; preds = %10
  %20 = call i32 @liquid_autotest_same_data(ptr noundef nonnull %2, ptr noundef nonnull %3, i32 noundef 512) #4
  %.not = icmp eq i32 %20, 0
  br i1 %.not, label %21, label %24

21:                                               ; preds = %19
  call void @liquid_autotest_failed_msg(ptr noundef nonnull @.str, i32 noundef 127, ptr noundef nonnull @.str.3) #4
  %22 = load i32, ptr @liquid_autotest_verbose, align 4, !tbaa !11
  %.not21 = icmp eq i32 %22, 0
  br i1 %.not21, label %25, label %23

23:                                               ; preds = %21
  call void @liquid_autotest_print_array(ptr noundef nonnull %2, i32 noundef 512) #4
  call void @liquid_autotest_print_array(ptr noundef nonnull %3, i32 noundef 512) #4
  br label %25

24:                                               ; preds = %19
  call void (...) @liquid_autotest_passed() #4
  br label %25

25:                                               ; preds = %21, %23, %24
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %1) #4
  ret void
}

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #3

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 = { 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 }

!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 = distinct !{!10, !9}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !6, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass