; LLVM IR from OAID/AutoKernel :: autokernel_plugin/tests/common/tengine_operations.ll (Z8gray2bgr5image)

; 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.image = type { i32, i32, i32, ptr }

; 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

; 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) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z10free_image5image(ptr noundef byval(%struct.image) align 8) #3

; Function Attrs: mustprogress uwtable
define dso_local void @_Z8gray2bgr5image(ptr dead_on_unwind noalias writable sret(%struct.image) align 8 %0, ptr noundef byval(%struct.image) align 8 %1) #4 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.image, align 8
  %8 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 2
  store i32 3, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 1
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 1
  store i32 %10, ptr %11, align 4, !tbaa !11
  %12 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %13 = load i32, ptr %12, align 8, !tbaa !12
  %14 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 0
  store i32 %13, ptr %14, align 8, !tbaa !12
  %15 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 1
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = sext i32 %16 to i64
  %18 = mul i64 12, %17
  %19 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !12
  %21 = sext i32 %20 to i64
  %22 = mul i64 %18, %21
  %23 = call noalias ptr @malloc(i64 noundef %22) #5
  %24 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 3
  store ptr %23, ptr %24, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 0, ptr %3, align 4, !tbaa !14
  br label %25

25:                                               ; preds = %79, %2
  %26 = load i32, ptr %3, align 4, !tbaa !14
  %27 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 1
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = icmp slt i32 %26, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %25
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %82

31:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !14
  br label %32

32:                                               ; preds = %75, %31
  %33 = load i32, ptr %5, align 4, !tbaa !14
  %34 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %35 = load i32, ptr %34, align 8, !tbaa !12
  %36 = icmp slt i32 %33, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %32
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %78

38:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !14
  br label %39

39:                                               ; preds = %71, %38
  %40 = load i32, ptr %6, align 4, !tbaa !14
  %41 = icmp slt i32 %40, 3
  br i1 %41, label %43, label %42

42:                                               ; preds = %39
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %74

43:                                               ; preds = %39
  %44 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 3
  %45 = load ptr, ptr %44, align 8, !tbaa !13
  %46 = load i32, ptr %3, align 4, !tbaa !14
  %47 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !12
  %49 = mul nsw i32 %46, %48
  %50 = load i32, ptr %5, align 4, !tbaa !14
  %51 = add nsw i32 %49, %50
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds float, ptr %45, i64 %52
  %54 = load float, ptr %53, align 4, !tbaa !15
  %55 = getelementptr inbounds %struct.image, ptr %0, i32 0, i32 3
  %56 = load ptr, ptr %55, align 8, !tbaa !13
  %57 = load i32, ptr %3, align 4, !tbaa !14
  %58 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 0
  %59 = load i32, ptr %58, align 8, !tbaa !12
  %60 = mul nsw i32 %57, %59
  %61 = getelementptr inbounds %struct.image, ptr %1, i32 0, i32 2
  %62 = load i32, ptr %61, align 8, !tbaa !5
  %63 = mul nsw i32 %60, %62
  %64 = load i32, ptr %5, align 4, !tbaa !14
  %65 = mul nsw i32 %64, 3
  %66 = add nsw i32 %63, %65
  %67 = load i32, ptr %6, align 4, !tbaa !14
  %68 = add nsw i32 %66, %67
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds float, ptr %56, i64 %69
  store float %54, ptr %70, align 4, !tbaa !15
  br label %71

71:                                               ; preds = %43
  %72 = load i32, ptr %6, align 4, !tbaa !14
  %73 = add nsw i32 %72, 1
  store i32 %73, ptr %6, align 4, !tbaa !14
  br label %39, !llvm.loop !17

74:                                               ; preds = %42
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %5, align 4, !tbaa !14
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %5, align 4, !tbaa !14
  br label %32, !llvm.loop !19

78:                                               ; preds = %37
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %3, align 4, !tbaa !14
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %3, align 4, !tbaa !14
  br label %25, !llvm.loop !20

82:                                               ; preds = %30
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %7, ptr align 8 %1, i64 24, i1 false), !tbaa.struct !21
  call void @_Z10free_image5image(ptr noundef byval(%struct.image) align 8 %7)
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nounwind allocsize(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 = { mustprogress 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 = { mustprogress 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 allocsize(0) }
attributes #6 = { 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 = !{!"_ZTS5image", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 16}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"float", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !18}
!21 = !{i64 0, i64 4, !14, i64 4, i64 4, !14, i64 8, i64 4, !14, i64 16, i64 8, !22}
!22 = !{!10, !10, 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"

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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z10free_image5image(ptr noundef byval(%struct.image) align 8) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z8gray2bgr5image(ptr dead_on_unwind noalias nocapture writable writeonly sret(%struct.image) align 8 %0, ptr nocapture noundef readonly byval(%struct.image) align 8 %1) local_unnamed_addr #1 {
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 3, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %1, i64 4
  %5 = load i32, ptr %4, align 4, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %5, ptr %6, align 4, !tbaa !11
  %7 = load i32, ptr %1, align 8, !tbaa !12
  store i32 %7, ptr %0, align 8, !tbaa !12
  %8 = sext i32 %5 to i64
  %9 = mul nsw i64 %8, 12
  %10 = sext i32 %7 to i64
  %11 = mul i64 %9, %10
  %12 = tail call noalias ptr @malloc(i64 noundef %11) #2
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %12, ptr %13, align 8, !tbaa !13
  %14 = icmp sgt i32 %5, 0
  br i1 %14, label %.preheader13.lr.ph, label %._crit_edge17

.preheader13.lr.ph:                               ; preds = %2
  %15 = icmp sgt i32 %7, 0
  %16 = getelementptr inbounds i8, ptr %1, i64 16
  %17 = load ptr, ptr %16, align 8
  br i1 %15, label %.preheader13.us.preheader, label %._crit_edge17

.preheader13.us.preheader:                        ; preds = %.preheader13.lr.ph
  %18 = getelementptr inbounds i8, ptr %1, i64 8
  %19 = load i32, ptr %18, align 8
  %wide.trip.count24 = zext nneg i32 %5 to i64
  %wide.trip.count = zext nneg i32 %7 to i64
  br label %.preheader13.us

.preheader13.us:                                  ; preds = %.preheader13.us.preheader, %._crit_edge.us
  %indvars.iv21 = phi i64 [ 0, %.preheader13.us.preheader ], [ %indvars.iv.next22, %._crit_edge.us ]
  %20 = mul nuw nsw i64 %indvars.iv21, %10
  %invariant.gep = getelementptr float, ptr %17, i64 %20
  %21 = trunc i64 %20 to i32
  %22 = mul i32 %19, %21
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader13.us, %.preheader.us
  %indvars.iv = phi i64 [ 0, %.preheader13.us ], [ %indvars.iv.next, %.preheader.us ]
  %gep = getelementptr float, ptr %invariant.gep, i64 %indvars.iv
  %23 = mul nuw nsw i64 %indvars.iv, 3
  %24 = load float, ptr %gep, align 4, !tbaa !14
  %25 = trunc nuw nsw i64 %23 to i32
  %26 = add i32 %22, %25
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds float, ptr %12, i64 %27
  store float %24, ptr %28, align 4, !tbaa !14
  %29 = trunc i64 %23 to i32
  %30 = add i32 %29, 1
  %31 = add i32 %30, %22
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds float, ptr %12, i64 %32
  store float %24, ptr %33, align 4, !tbaa !14
  %34 = load float, ptr %gep, align 4, !tbaa !14
  %35 = trunc i64 %23 to i32
  %36 = add i32 %35, 2
  %37 = add i32 %36, %22
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds float, ptr %12, i64 %38
  store float %34, ptr %39, align 4, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge.us, label %.preheader.us, !llvm.loop !16

._crit_edge.us:                                   ; preds = %.preheader.us
  %indvars.iv.next22 = add nuw nsw i64 %indvars.iv21, 1
  %exitcond25.not = icmp eq i64 %indvars.iv.next22, %wide.trip.count24
  br i1 %exitcond25.not, label %._crit_edge17, label %.preheader13.us, !llvm.loop !18

._crit_edge17:                                    ; preds = %._crit_edge.us, %.preheader13.lr.ph, %2
  tail call void @_Z10free_image5image(ptr noundef nonnull byval(%struct.image) align 8 %1)
  ret void
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress 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 #2 = { nounwind allocsize(0) }

!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 = !{!"_ZTS5image", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 0}
!13 = !{!6, !10, i64 16}
!14 = !{!15, !15, i64 0}
!15 = !{!"float", !8, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}


; Effective O3 passes: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass