; LLVM IR from jgaeddert/liquid-dsp :: src/random/tests (scramble_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 [91 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [46 x i8], align 1
@liquid_autotest_verbose = external global i32, align 4
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local float @liquid_scramble_test_entropy(ptr noundef, i32 noundef) #0

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

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

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

19:                                               ; preds = %27, %1
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = icmp ult i32 %20, %21
  br i1 %22, label %23, label %30

23:                                               ; preds = %19
  %24 = load i32, ptr %7, align 4, !tbaa !5
  %25 = zext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %12, i64 %25
  store i8 0, ptr %26, align 1, !tbaa !9
  br label %27

27:                                               ; preds = %23
  %28 = load i32, ptr %7, align 4, !tbaa !5
  %29 = add i32 %28, 1
  store i32 %29, ptr %7, align 4, !tbaa !5
  br label %19, !llvm.loop !10

30:                                               ; preds = %19
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = zext i32 %31 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 16 %15, ptr align 16 %12, i64 %32, i1 false)
  %33 = load i32, ptr %2, align 4, !tbaa !5
  call void @scramble_data(ptr noundef %15, i32 noundef %33)
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = zext i32 %34 to i64
  call void @llvm.memmove.p0.p0.i64(ptr align 16 %18, ptr align 16 %15, i64 %35, i1 false)
  %36 = load i32, ptr %2, align 4, !tbaa !5
  call void @unscramble_data(ptr noundef %18, i32 noundef %36)
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = zext i32 %37 to i64
  %39 = mul i64 %38, 1
  %40 = trunc i64 %39 to i32
  %41 = call i32 @liquid_autotest_same_data(ptr noundef %12, ptr noundef %18, i32 noundef %40)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %56, label %43

43:                                               ; preds = %30
  call void @liquid_autotest_failed_msg(ptr noundef @.str, i32 noundef 70, ptr noundef @.str.1)
  %44 = load i32, ptr @liquid_autotest_verbose, align 4, !tbaa !5
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %55

46:                                               ; preds = %43
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = zext i32 %47 to i64
  %49 = mul i64 %48, 1
  %50 = trunc i64 %49 to i32
  call void @liquid_autotest_print_array(ptr noundef %12, i32 noundef %50)
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = zext i32 %51 to i64
  %53 = mul i64 %52, 1
  %54 = trunc i64 %53 to i32
  call void @liquid_autotest_print_array(ptr noundef %18, i32 noundef %54)
  br label %55

55:                                               ; preds = %46, %43
  br label %57

56:                                               ; preds = %30
  call void (...) @liquid_autotest_passed()
  br label %57

57:                                               ; preds = %56, %55
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %58 = load i32, ptr %2, align 4, !tbaa !5
  %59 = call float @liquid_scramble_test_entropy(ptr noundef %15, i32 noundef %58)
  store float %59, ptr %8, align 4, !tbaa !12
  %60 = load float, ptr %8, align 4, !tbaa !12
  %61 = fcmp ogt float %60, 0x3FE99999A0000000
  br i1 %61, label %67, label %62

62:                                               ; preds = %57
  %63 = load float, ptr %8, align 4, !tbaa !12
  %64 = fcmp ogt float %63, 0x3FE99999A0000000
  %65 = zext i1 %64 to i32
  %66 = sitofp i32 %65 to double
  call void @liquid_autotest_failed_expr(ptr noundef @.str, i32 noundef 74, ptr noundef @.str.2, double noundef %66, ptr noundef @.str.3, ptr noundef @.str.4, double noundef 1.000000e+00)
  br label %68

67:                                               ; preds = %57
  call void (...) @liquid_autotest_passed()
  br label %68

68:                                               ; preds = %67, %62
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  %69 = load ptr, ptr %3, align 8
  call void @llvm.stackrestore.p0(ptr %69)
  ret void
}

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

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

declare void @scramble_data(ptr noundef, i32 noundef) #4

declare void @unscramble_data(ptr noundef, i32 noundef) #4

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

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

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

declare void @liquid_autotest_passed(...) #4

declare void @liquid_autotest_failed_expr(ptr noundef, i32 noundef, ptr noundef, double noundef, ptr noundef, ptr noundef, double noundef) #4

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 = !{!13, !13, i64 0}
!13 = !{!"float", !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"

@.str = external hidden unnamed_addr constant [91 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [46 x i8], align 1
@liquid_autotest_verbose = external local_unnamed_addr global i32, align 4
@.str.2 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local float @liquid_scramble_test_entropy(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @liquid_scramble_test(i32 noundef %0) local_unnamed_addr #0 {
  %2 = zext i32 %0 to i64
  %3 = alloca i8, i64 %2, align 16
  %4 = alloca i8, i64 %2, align 16
  %5 = alloca i8, i64 %2, align 16
  %.not20 = icmp eq i32 %0, 0
  br i1 %.not20, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  call void @llvm.memset.p0.i64(ptr nonnull align 16 %3, i8 0, i64 %2, i1 false), !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %1
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %4, ptr nonnull align 16 %3, i64 %2, i1 false)
  call void @scramble_data(ptr noundef nonnull %4, i32 noundef %0) #4
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %5, ptr nonnull align 16 %4, i64 %2, i1 false)
  call void @unscramble_data(ptr noundef nonnull %5, i32 noundef %0) #4
  %6 = call i32 @liquid_autotest_same_data(ptr noundef nonnull %3, ptr noundef nonnull %5, i32 noundef %0) #4
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %7, label %10

7:                                                ; preds = %._crit_edge
  call void @liquid_autotest_failed_msg(ptr noundef nonnull @.str, i32 noundef 70, ptr noundef nonnull @.str.1) #4
  %8 = load i32, ptr @liquid_autotest_verbose, align 4, !tbaa !8
  %.not18 = icmp eq i32 %8, 0
  br i1 %.not18, label %11, label %9

9:                                                ; preds = %7
  call void @liquid_autotest_print_array(ptr noundef nonnull %3, i32 noundef %0) #4
  call void @liquid_autotest_print_array(ptr noundef nonnull %5, i32 noundef %0) #4
  br label %11

10:                                               ; preds = %._crit_edge
  call void (...) @liquid_autotest_passed() #4
  br label %11

11:                                               ; preds = %7, %9, %10
  %12 = call float @liquid_scramble_test_entropy(ptr noundef nonnull %4, i32 noundef %0)
  %13 = fcmp ogt float %12, 0x3FE99999A0000000
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  call void @liquid_autotest_failed_expr(ptr noundef nonnull @.str, i32 noundef 74, ptr noundef nonnull @.str.2, double noundef 0.000000e+00, ptr noundef nonnull @.str.3, ptr noundef nonnull @.str.4, double noundef 1.000000e+00) #4
  br label %16

15:                                               ; preds = %11
  call void (...) @liquid_autotest_passed() #4
  br label %16

16:                                               ; preds = %15, %14
  ret void
}

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

declare void @unscramble_data(ptr noundef, i32 noundef) 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

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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" }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,MemCpyOptPass,SROAPass,SimplifyCFGPass