; LLVM IR from ljm941004/HYPERCV_PUBLIC :: modules/core/src/c_src (simplemat)

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

%struct.SIMPLE_MAT = type { i32, i32, i32, i32, i32, ptr }

@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [32 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

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

declare i32 @printf(ptr noundef, ...) #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #2

; 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: nounwind uwtable
declare dso_local void @simple_mat_grayscale_statistics(ptr noundef, ptr noundef) #4

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

; Function Attrs: nounwind uwtable
define dso_local float @simple_mat_entropy(ptr noundef %0) #4 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca [256 x i32], align 16
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca float, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %16

15:                                               ; preds = %1
  br label %20

16:                                               ; preds = %1
  %17 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %18 = call i32 (ptr, ...) @printf(ptr noundef @.str.17)
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  call void @exit(i32 noundef 1) #7
  unreachable

20:                                               ; preds = %15
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.SIMPLE_MAT, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = icmp eq i32 %23, 1
  br i1 %24, label %25, label %26

25:                                               ; preds = %20
  br label %30

26:                                               ; preds = %20
  %27 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %28 = call i32 (ptr, ...) @printf(ptr noundef @.str.18)
  %29 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  call void @exit(i32 noundef 1) #7
  unreachable

30:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #8
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.SIMPLE_MAT, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !12
  store i32 %33, ptr %3, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #8
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.SIMPLE_MAT, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !14
  store i32 %36, ptr %4, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #8
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.SIMPLE_MAT, ptr %37, i32 0, i32 3
  %39 = load i32, ptr %38, align 4, !tbaa !15
  store i32 %39, ptr %5, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #8
  %40 = load i32, ptr %5, align 4, !tbaa !13
  %41 = icmp ne i32 %40, 1
  br i1 %41, label %42, label %45

42:                                               ; preds = %30
  %43 = load ptr, ptr %2, align 8, !tbaa !5
  %44 = call ptr @sm_rgb2gray(ptr noundef %43, i32 noundef 0)
  store ptr %44, ptr %6, align 8, !tbaa !5
  br label %47

45:                                               ; preds = %30
  %46 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %46, ptr %6, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %45, %42
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #8
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.SIMPLE_MAT, ptr %48, i32 0, i32 5
  %50 = load ptr, ptr %49, align 8, !tbaa !16
  store ptr %50, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  store float 0.000000e+00, ptr %8, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 1024, ptr %9) #8
  call void @llvm.memset.p0.i64(ptr align 16 %9, i8 0, i64 1024, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #8
  %51 = getelementptr inbounds [256 x i32], ptr %9, i64 0, i64 0
  store ptr %51, ptr %10, align 8, !tbaa !5
  %52 = load ptr, ptr %2, align 8, !tbaa !5
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  call void @simple_mat_grayscale_statistics(ptr noundef %52, ptr noundef %53)
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #8
  store i32 0, ptr %11, align 4, !tbaa !13
  br label %54

54:                                               ; preds = %89, %47
  %55 = load i32, ptr %11, align 4, !tbaa !13
  %56 = icmp slt i32 %55, 256
  br i1 %56, label %58, label %57

57:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #8
  br label %92

58:                                               ; preds = %54
  %59 = load i32, ptr %11, align 4, !tbaa !13
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [256 x i32], ptr %9, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !13
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %88

64:                                               ; preds = %58
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #8
  %65 = load i32, ptr %11, align 4, !tbaa !13
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [256 x i32], ptr %9, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !13
  %69 = sitofp i32 %68 to float
  %70 = load i32, ptr %3, align 4, !tbaa !13
  %71 = sitofp i32 %70 to float
  %72 = fdiv float %69, %71
  %73 = load i32, ptr %4, align 4, !tbaa !13
  %74 = sitofp i32 %73 to float
  %75 = fdiv float %72, %74
  store float %75, ptr %12, align 4, !tbaa !17
  %76 = load float, ptr %8, align 4, !tbaa !17
  %77 = fpext float %76 to double
  %78 = load float, ptr %12, align 4, !tbaa !17
  %79 = fpext float %78 to double
  %80 = load float, ptr %12, align 4, !tbaa !17
  %81 = fpext float %80 to double
  %82 = call double @log(double noundef %81) #8
  %83 = call double @log(double noundef 2.000000e+00) #8
  %84 = fdiv double %82, %83
  %85 = fneg double %79
  %86 = call double @llvm.fmuladd.f64(double %85, double %84, double %77)
  %87 = fptrunc double %86 to float
  store float %87, ptr %8, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #8
  br label %88

88:                                               ; preds = %64, %58
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %11, align 4, !tbaa !13
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %11, align 4, !tbaa !13
  br label %54, !llvm.loop !19

92:                                               ; preds = %57
  %93 = load float, ptr %8, align 4, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #8
  call void @llvm.lifetime.end.p0(i64 1024, ptr %9) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #8
  ret float %93
}

; Function Attrs: nounwind
declare double @log(double noundef) #5

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #6

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 = { noreturn 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 "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 #6 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { noreturn nounwind }
attributes #8 = { 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, !11, i64 8}
!10 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 0}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 4}
!15 = !{!10, !11, i64 12}
!16 = !{!10, !6, i64 24}
!17 = !{!18, !18, i64 0}
!18 = !{!"float", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


; 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 [8 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [25 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [32 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

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #2

; 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: nounwind uwtable
declare dso_local void @simple_mat_grayscale_statistics(ptr noundef, ptr noundef) local_unnamed_addr #4

declare ptr @sm_rgb2gray(ptr noundef, i32 noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
define dso_local float @simple_mat_entropy(ptr noundef %0) local_unnamed_addr #4 {
  %2 = alloca [256 x i32], align 16
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %3, label %7

3:                                                ; preds = %1
  %4 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %5 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.17)
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  tail call void @exit(i32 noundef 1) #8
  unreachable

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !5
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %15, label %11

11:                                               ; preds = %7
  %12 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str)
  %13 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.18)
  %14 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  tail call void @exit(i32 noundef 1) #8
  unreachable

15:                                               ; preds = %7
  %16 = load i32, ptr %0, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %0, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !12
  %19 = getelementptr inbounds i8, ptr %0, i64 12
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %.not24 = icmp eq i32 %20, 1
  br i1 %.not24, label %23, label %21

21:                                               ; preds = %15
  %22 = tail call ptr @sm_rgb2gray(ptr noundef nonnull %0, i32 noundef 0) #9
  br label %23

23:                                               ; preds = %15, %21
  call void @llvm.lifetime.start.p0(i64 1024, ptr nonnull %2) #9
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(1024) %2, i8 0, i64 1024, i1 false)
  call void @simple_mat_grayscale_statistics(ptr noundef nonnull %0, ptr noundef nonnull %2)
  %24 = sitofp i32 %16 to float
  %25 = sitofp i32 %18 to float
  br label %27

26:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 1024, ptr nonnull %2) #9
  ret float %.1

27:                                               ; preds = %23, %41
  %indvars.iv = phi i64 [ 0, %23 ], [ %indvars.iv.next, %41 ]
  %.02126 = phi float [ 0.000000e+00, %23 ], [ %.1, %41 ]
  %28 = getelementptr inbounds [256 x i32], ptr %2, i64 0, i64 %indvars.iv
  %29 = load i32, ptr %28, align 4, !tbaa !14
  %.not25 = icmp eq i32 %29, 0
  br i1 %.not25, label %41, label %30

30:                                               ; preds = %27
  %31 = sitofp i32 %29 to float
  %32 = fdiv float %31, %24
  %33 = fdiv float %32, %25
  %34 = fpext float %.02126 to double
  %35 = fpext float %33 to double
  %36 = call double @log(double noundef %35) #9
  %37 = fdiv double %36, 0x3FE62E42FEFA39EF
  %38 = fneg double %35
  %39 = call double @llvm.fmuladd.f64(double %38, double %37, double %34)
  %40 = fptrunc double %39 to float
  br label %41

41:                                               ; preds = %27, %30
  %.1 = phi float [ %40, %30 ], [ %.02126, %27 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 256
  br i1 %exitcond.not, label %26, label %27, !llvm.loop !15
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #6

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #7

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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 = { noreturn 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 = { "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 #6 = { mustprogress nofree nounwind willreturn memory(write) "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 #7 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #8 = { noreturn nounwind }
attributes #9 = { 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, !7, i64 8}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!6, !7, i64 12}
!14 = !{!7, !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass