; LLVM IR from ljm941004/HYPERCV_PUBLIC :: modules/process/src/c_src (colortransform)

; 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.5 = external hidden unnamed_addr constant [31 x i8], align 1

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

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

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

declare ptr @create_simple_mat(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #0

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

; Function Attrs: nounwind uwtable
define dso_local ptr @sm_gray2rgb(ptr noundef %0) #3 {
  %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 ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %13 = load ptr, ptr %2, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.SIMPLE_MAT, ptr %13, i32 0, i32 3
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %18

17:                                               ; preds = %1
  br label %22

18:                                               ; preds = %1
  %19 = call i32 (ptr, ...) @printf(ptr noundef @.str)
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.5)
  %21 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  call void @exit(i32 noundef 1) #4
  unreachable

22:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.SIMPLE_MAT, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 8, !tbaa !12
  store i32 %25, ptr %3, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.SIMPLE_MAT, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !14
  store i32 %28, ptr %4, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 3, ptr %5, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  %29 = load i32, ptr %3, align 4, !tbaa !13
  %30 = load i32, ptr %4, align 4, !tbaa !13
  %31 = load i32, ptr %5, align 4, !tbaa !13
  %32 = call ptr @create_simple_mat(i32 noundef %29, i32 noundef %30, i32 noundef 1, i32 noundef %31)
  store ptr %32, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.SIMPLE_MAT, ptr %33, i32 0, i32 5
  %35 = load ptr, ptr %34, align 8, !tbaa !15
  store ptr %35, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SIMPLE_MAT, ptr %36, i32 0, i32 5
  %38 = load ptr, ptr %37, align 8, !tbaa !15
  store ptr %38, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !13
  br label %39

39:                                               ; preds = %86, %22
  %40 = load i32, ptr %9, align 4, !tbaa !13
  %41 = load i32, ptr %3, align 4, !tbaa !13
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  store i32 2, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %89

44:                                               ; preds = %39
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !13
  br label %45

45:                                               ; preds = %82, %44
  %46 = load i32, ptr %11, align 4, !tbaa !13
  %47 = load i32, ptr %4, align 4, !tbaa !13
  %48 = icmp slt i32 %46, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %45
  store i32 5, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  br label %85

50:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  store i32 0, ptr %12, align 4, !tbaa !13
  br label %51

51:                                               ; preds = %78, %50
  %52 = load i32, ptr %12, align 4, !tbaa !13
  %53 = load i32, ptr %5, align 4, !tbaa !13
  %54 = icmp slt i32 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  store i32 8, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  br label %81

56:                                               ; preds = %51
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = load i32, ptr %9, align 4, !tbaa !13
  %59 = load i32, ptr %4, align 4, !tbaa !13
  %60 = mul nsw i32 %58, %59
  %61 = load i32, ptr %11, align 4, !tbaa !13
  %62 = add nsw i32 %60, %61
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i8, ptr %57, i64 %63
  %65 = load i8, ptr %64, align 1, !tbaa !16
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = load i32, ptr %9, align 4, !tbaa !13
  %68 = load i32, ptr %4, align 4, !tbaa !13
  %69 = mul nsw i32 %67, %68
  %70 = mul nsw i32 %69, 3
  %71 = load i32, ptr %11, align 4, !tbaa !13
  %72 = mul nsw i32 %71, 3
  %73 = add nsw i32 %70, %72
  %74 = load i32, ptr %12, align 4, !tbaa !13
  %75 = add nsw i32 %73, %74
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds i8, ptr %66, i64 %76
  store i8 %65, ptr %77, align 1, !tbaa !16
  br label %78

78:                                               ; preds = %56
  %79 = load i32, ptr %12, align 4, !tbaa !13
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %12, align 4, !tbaa !13
  br label %51, !llvm.loop !17

81:                                               ; preds = %55
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %11, align 4, !tbaa !13
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %11, align 4, !tbaa !13
  br label %45, !llvm.loop !19

85:                                               ; preds = %49
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %9, align 4, !tbaa !13
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %9, align 4, !tbaa !13
  br label %39, !llvm.loop !20

89:                                               ; preds = %43
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  ret ptr %90
}

attributes #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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { noreturn nounwind }
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, !11, i64 12}
!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, !6, i64 24}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !18}


; 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.5 = external hidden unnamed_addr constant [31 x i8], align 1

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

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

declare ptr @create_simple_mat(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local ptr @sm_gray2rgb(ptr nocapture noundef readonly %0) local_unnamed_addr #3 {
  %2 = getelementptr inbounds i8, ptr %0, i64 12
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %9, label %5

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

9:                                                ; preds = %1
  %10 = load i32, ptr %0, align 8, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = tail call ptr @create_simple_mat(i32 noundef %10, i32 noundef %12, i32 noundef 1, i32 noundef 3) #5
  %14 = getelementptr inbounds i8, ptr %0, i64 24
  %15 = load ptr, ptr %14, align 8, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %13, i64 24
  %17 = load ptr, ptr %16, align 8, !tbaa !13
  %18 = icmp sgt i32 %10, 0
  %19 = icmp sgt i32 %12, 0
  %or.cond = and i1 %18, %19
  br i1 %or.cond, label %.preheader29.us.preheader, label %._crit_edge33

.preheader29.us.preheader:                        ; preds = %9
  %20 = zext nneg i32 %12 to i64
  %wide.trip.count40 = zext nneg i32 %10 to i64
  %invariant.gep = getelementptr i8, ptr %17, i64 1
  %invariant.gep42 = getelementptr i8, ptr %17, i64 2
  %xtraiter = and i64 %20, 1
  %21 = icmp eq i32 %12, 1
  %unroll_iter = and i64 %20, 2147483646
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader29.us

.preheader29.us:                                  ; preds = %.preheader29.us.preheader, %._crit_edge.us
  %indvars.iv37 = phi i64 [ 0, %.preheader29.us.preheader ], [ %indvars.iv.next38, %._crit_edge.us ]
  %22 = mul nuw nsw i64 %indvars.iv37, %20
  br i1 %21, label %._crit_edge.us.unr-lcssa, label %.preheader.us

.preheader.us:                                    ; preds = %.preheader29.us, %.preheader.us
  %indvars.iv = phi i64 [ %indvars.iv.next.1, %.preheader.us ], [ 0, %.preheader29.us ]
  %niter = phi i64 [ %niter.next.1, %.preheader.us ], [ 0, %.preheader29.us ]
  %23 = add nuw nsw i64 %indvars.iv, %22
  %24 = getelementptr inbounds i8, ptr %15, i64 %23
  %sext = mul i64 %23, 12884901888
  %25 = ashr exact i64 %sext, 32
  %26 = load i8, ptr %24, align 1, !tbaa !14
  %27 = getelementptr inbounds i8, ptr %17, i64 %25
  store i8 %26, ptr %27, align 1, !tbaa !14
  %gep = getelementptr i8, ptr %invariant.gep, i64 %25
  store i8 %26, ptr %gep, align 1, !tbaa !14
  %28 = load i8, ptr %24, align 1, !tbaa !14
  %gep43 = getelementptr i8, ptr %invariant.gep42, i64 %25
  store i8 %28, ptr %gep43, align 1, !tbaa !14
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %29 = add nuw nsw i64 %indvars.iv.next, %22
  %30 = getelementptr inbounds i8, ptr %15, i64 %29
  %sext.1 = mul i64 %29, 12884901888
  %31 = ashr exact i64 %sext.1, 32
  %32 = load i8, ptr %30, align 1, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %17, i64 %31
  store i8 %32, ptr %33, align 1, !tbaa !14
  %gep.1 = getelementptr i8, ptr %invariant.gep, i64 %31
  store i8 %32, ptr %gep.1, align 1, !tbaa !14
  %34 = load i8, ptr %30, align 1, !tbaa !14
  %gep43.1 = getelementptr i8, ptr %invariant.gep42, i64 %31
  store i8 %34, ptr %gep43.1, align 1, !tbaa !14
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us, !llvm.loop !15

._crit_edge.us.unr-lcssa:                         ; preds = %.preheader.us, %.preheader29.us
  %indvars.iv.unr = phi i64 [ 0, %.preheader29.us ], [ %indvars.iv.next.1, %.preheader.us ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.preheader.us.epil

.preheader.us.epil:                               ; preds = %._crit_edge.us.unr-lcssa
  %35 = add nuw nsw i64 %indvars.iv.unr, %22
  %36 = getelementptr inbounds i8, ptr %15, i64 %35
  %sext.epil = mul i64 %35, 12884901888
  %37 = ashr exact i64 %sext.epil, 32
  %38 = load i8, ptr %36, align 1, !tbaa !14
  %39 = getelementptr inbounds i8, ptr %17, i64 %37
  store i8 %38, ptr %39, align 1, !tbaa !14
  %gep.epil = getelementptr i8, ptr %invariant.gep, i64 %37
  store i8 %38, ptr %gep.epil, align 1, !tbaa !14
  %40 = load i8, ptr %36, align 1, !tbaa !14
  %gep43.epil = getelementptr i8, ptr %invariant.gep42, i64 %37
  store i8 %40, ptr %gep43.epil, align 1, !tbaa !14
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %._crit_edge.us.unr-lcssa, %.preheader.us.epil
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %exitcond41.not = icmp eq i64 %indvars.iv.next38, %wide.trip.count40
  br i1 %exitcond41.not, label %._crit_edge33, label %.preheader29.us, !llvm.loop !17

._crit_edge33:                                    ; preds = %._crit_edge.us, %9
  ret ptr %13
}

attributes #0 = { 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 #1 = { 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 #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 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 #4 = { noreturn nounwind }
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, !7, i64 12}
!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, !10, i64 24}
!14 = !{!8, !8, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


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