; LLVM IR from jgaeddert/liquid-dsp :: src/fec/bench (crc_benchmark)

; 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: nounwind uwtable
define dso_local void @crc_bench(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %15 = load i32, ptr %9, align 4, !tbaa !9
  %16 = icmp ne i32 %15, 2
  br i1 %16, label %17, label %21

17:                                               ; preds = %5
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = udiv i64 %19, 100
  store i64 %20, ptr %18, align 8, !tbaa !11
  br label %21

21:                                               ; preds = %17, %5
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load i64, ptr %22, align 8, !tbaa !11
  %24 = icmp ult i64 %23, 1
  br i1 %24, label %25, label %27

25:                                               ; preds = %21
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 1, ptr %26, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %25, %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %28 = load i32, ptr %10, align 4, !tbaa !9
  %29 = zext i32 %28 to i64
  %30 = call ptr @llvm.stacksave.p0()
  store ptr %30, ptr %12, align 8
  %31 = alloca i8, i64 %29, align 16
  store i64 %29, ptr %13, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  store i32 0, ptr %14, align 4, !tbaa !9
  store i64 0, ptr %11, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %43, %27
  %33 = load i64, ptr %11, align 8, !tbaa !11
  %34 = load i32, ptr %10, align 4, !tbaa !9
  %35 = zext i32 %34 to i64
  %36 = icmp ult i64 %33, %35
  br i1 %36, label %37, label %46

37:                                               ; preds = %32
  %38 = call i32 @rand() #5
  %39 = and i32 %38, 255
  %40 = trunc i32 %39 to i8
  %41 = load i64, ptr %11, align 8, !tbaa !11
  %42 = getelementptr inbounds i8, ptr %31, i64 %41
  store i8 %40, ptr %42, align 1, !tbaa !13
  br label %43

43:                                               ; preds = %37
  %44 = load i64, ptr %11, align 8, !tbaa !11
  %45 = add i64 %44, 1
  store i64 %45, ptr %11, align 8, !tbaa !11
  br label %32, !llvm.loop !14

46:                                               ; preds = %32
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = call i32 @getrusage(i32 noundef 0, ptr noundef %47) #5
  store i64 0, ptr %11, align 8, !tbaa !11
  br label %49

49:                                               ; preds = %82, %46
  %50 = load i64, ptr %11, align 8, !tbaa !11
  %51 = load ptr, ptr %8, align 8, !tbaa !5
  %52 = load i64, ptr %51, align 8, !tbaa !11
  %53 = icmp ult i64 %50, %52
  br i1 %53, label %54, label %85

54:                                               ; preds = %49
  %55 = load i32, ptr %9, align 4, !tbaa !9
  %56 = load i32, ptr %10, align 4, !tbaa !9
  %57 = call i32 @crc_generate_key(i32 noundef %55, ptr noundef %31, i32 noundef %56)
  %58 = load i32, ptr %14, align 4, !tbaa !9
  %59 = xor i32 %58, %57
  store i32 %59, ptr %14, align 4, !tbaa !9
  %60 = load i32, ptr %9, align 4, !tbaa !9
  %61 = load i32, ptr %10, align 4, !tbaa !9
  %62 = call i32 @crc_generate_key(i32 noundef %60, ptr noundef %31, i32 noundef %61)
  %63 = load i32, ptr %14, align 4, !tbaa !9
  %64 = xor i32 %63, %62
  store i32 %64, ptr %14, align 4, !tbaa !9
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = load i32, ptr %10, align 4, !tbaa !9
  %67 = call i32 @crc_generate_key(i32 noundef %65, ptr noundef %31, i32 noundef %66)
  %68 = load i32, ptr %14, align 4, !tbaa !9
  %69 = xor i32 %68, %67
  store i32 %69, ptr %14, align 4, !tbaa !9
  %70 = load i32, ptr %9, align 4, !tbaa !9
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = call i32 @crc_generate_key(i32 noundef %70, ptr noundef %31, i32 noundef %71)
  %73 = load i32, ptr %14, align 4, !tbaa !9
  %74 = xor i32 %73, %72
  store i32 %74, ptr %14, align 4, !tbaa !9
  %75 = load i32, ptr %14, align 4, !tbaa !9
  %76 = and i32 %75, 255
  %77 = getelementptr inbounds i8, ptr %31, i64 0
  %78 = load i8, ptr %77, align 16, !tbaa !13
  %79 = zext i8 %78 to i32
  %80 = xor i32 %79, %76
  %81 = trunc i32 %80 to i8
  store i8 %81, ptr %77, align 16, !tbaa !13
  br label %82

82:                                               ; preds = %54
  %83 = load i64, ptr %11, align 8, !tbaa !11
  %84 = add i64 %83, 1
  store i64 %84, ptr %11, align 8, !tbaa !11
  br label %49, !llvm.loop !16

85:                                               ; preds = %49
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = call i32 @getrusage(i32 noundef 0, ptr noundef %86) #5
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = load i64, ptr %88, align 8, !tbaa !11
  %90 = mul i64 %89, 4
  store i64 %90, ptr %88, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  %91 = load ptr, ptr %12, align 8
  call void @llvm.stackrestore.p0(ptr %91)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  ret void
}

; 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
declare ptr @llvm.stacksave.p0() #2

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

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

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

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

; 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 = { 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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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: nounwind uwtable
define dso_local void @crc_bench(ptr noundef %0, ptr noundef %1, ptr nocapture noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %.not = icmp eq i32 %3, 2
  %.pr = load i64, ptr %2, align 8, !tbaa !5
  br i1 %.not, label %thread-pre-split, label %6

6:                                                ; preds = %5
  %7 = udiv i64 %.pr, 100
  store i64 %7, ptr %2, align 8, !tbaa !5
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %5, %6
  %8 = phi i64 [ %7, %6 ], [ %.pr, %5 ]
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %thread-pre-split
  store i64 1, ptr %2, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %10, %thread-pre-split
  %12 = zext i32 %4 to i64
  %13 = alloca i8, i64 %12, align 16
  %.not35 = icmp eq i32 %4, 0
  br i1 %.not35, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %11, %.lr.ph
  %.02829 = phi i64 [ %17, %.lr.ph ], [ 0, %11 ]
  %14 = tail call i32 @rand() #3
  %15 = trunc i32 %14 to i8
  %16 = getelementptr inbounds i8, ptr %13, i64 %.02829
  store i8 %15, ptr %16, align 1, !tbaa !9
  %17 = add nuw nsw i64 %.02829, 1
  %exitcond.not = icmp eq i64 %17, %12
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %.lr.ph, %11
  %18 = tail call i32 @getrusage(i32 noundef 0, ptr noundef %0) #3
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %.not36 = icmp eq i64 %19, 0
  br i1 %.not36, label %._crit_edge34, label %.lr.ph33

.lr.ph33:                                         ; preds = %._crit_edge, %.lr.ph33
  %.031 = phi i32 [ %27, %.lr.ph33 ], [ 0, %._crit_edge ]
  %.130 = phi i64 [ %31, %.lr.ph33 ], [ 0, %._crit_edge ]
  %20 = call i32 @crc_generate_key(i32 noundef %3, ptr noundef nonnull %13, i32 noundef %4) #3
  %21 = xor i32 %20, %.031
  %22 = call i32 @crc_generate_key(i32 noundef %3, ptr noundef nonnull %13, i32 noundef %4) #3
  %23 = xor i32 %21, %22
  %24 = call i32 @crc_generate_key(i32 noundef %3, ptr noundef nonnull %13, i32 noundef %4) #3
  %25 = xor i32 %23, %24
  %26 = call i32 @crc_generate_key(i32 noundef %3, ptr noundef nonnull %13, i32 noundef %4) #3
  %27 = xor i32 %25, %26
  %28 = load i8, ptr %13, align 16, !tbaa !9
  %29 = trunc i32 %27 to i8
  %30 = xor i8 %28, %29
  store i8 %30, ptr %13, align 16, !tbaa !9
  %31 = add nuw i64 %.130, 1
  %32 = load i64, ptr %2, align 8, !tbaa !5
  %33 = icmp ult i64 %31, %32
  br i1 %33, label %.lr.ph33, label %._crit_edge34, !llvm.loop !12

._crit_edge34:                                    ; preds = %.lr.ph33, %._crit_edge
  %34 = call i32 @getrusage(i32 noundef 0, ptr noundef %1) #3
  %35 = load i64, ptr %2, align 8, !tbaa !5
  %36 = shl i64 %35, 2
  store i64 %36, ptr %2, align 8, !tbaa !5
  ret void
}

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

; Function Attrs: nounwind
declare i32 @getrusage(i32 noundef, ptr noundef) local_unnamed_addr #1

declare i32 @crc_generate_key(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #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 = { 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 = { "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 }

!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 = !{!"long", !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}


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