; LLVM IR from jingweizhanghuai/Morn :: src/image (morn_image_convert)

; 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.MImage = type { i32, i32, i32, [4 x ptr], ptr }

@.str = external hidden unnamed_addr constant [86 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@__FUNCTION__.m_ImageToGray = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 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

declare void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #1

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

; Function Attrs: nounwind uwtable
declare dso_local void @m_ImageYUVToGray(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @m_ImageRGBToGray(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @m_ImageToGray(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = icmp eq ptr %9, null
  br i1 %10, label %15, label %11

11:                                               ; preds = %8
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = ptrtoint ptr %12 to i64
  %14 = icmp eq i64 %13, -1
  br i1 %14, label %15, label %16

15:                                               ; preds = %11, %8
  br label %45

16:                                               ; preds = %11
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.MImage, ptr %17, i32 0, i32 3
  %19 = getelementptr inbounds [4 x ptr], ptr %18, i64 0, i64 0
  %20 = icmp eq ptr %19, null
  br i1 %20, label %42, label %21

21:                                               ; preds = %16
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.MImage, ptr %22, i32 0, i32 3
  %24 = getelementptr inbounds [4 x ptr], ptr %23, i64 0, i64 0
  %25 = ptrtoint ptr %24 to i64
  %26 = icmp eq i64 %25, -1
  br i1 %26, label %42, label %27

27:                                               ; preds = %21
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.MImage, ptr %28, i32 0, i32 0
  %30 = load i32, ptr %29, align 8, !tbaa !9
  %31 = icmp sle i32 %30, 0
  br i1 %31, label %42, label %32

32:                                               ; preds = %27
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.MImage, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !12
  %36 = icmp sle i32 %35, 0
  br i1 %36, label %42, label %37

37:                                               ; preds = %32
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.MImage, ptr %38, i32 0, i32 2
  %40 = load i32, ptr %39, align 8, !tbaa !13
  %41 = icmp sle i32 %40, 0
  br label %42

42:                                               ; preds = %37, %32, %27, %21, %16
  %43 = phi i1 [ true, %32 ], [ true, %27 ], [ true, %21 ], [ true, %16 ], [ %41, %37 ]
  %44 = zext i1 %43 to i32
  br label %45

45:                                               ; preds = %42, %15
  %46 = phi i32 [ 1, %15 ], [ %44, %42 ]
  store i32 %46, ptr %5, align 4, !tbaa !14
  %47 = load i32, ptr %5, align 4, !tbaa !14
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %51

49:                                               ; preds = %45
  %50 = load i32, ptr %5, align 4, !tbaa !14
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %50, i32 noundef -1, ptr noundef @.str, i32 noundef 156, ptr noundef @__FUNCTION__.m_ImageToGray, ptr noundef @.str.1)
  br label %51

51:                                               ; preds = %49, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %52

52:                                               ; preds = %51
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = call ptr @m_PropertyRead(ptr noundef %53, ptr noundef @.str.3, ptr noundef %6, ptr noundef null)
  %55 = load i32, ptr %6, align 4, !tbaa !14
  %56 = icmp eq i32 %55, 1
  br i1 %56, label %57, label %60

57:                                               ; preds = %52
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mImageCopy(ptr noundef %58, ptr noundef %59)
  br label %96

60:                                               ; preds = %52
  %61 = load i32, ptr %6, align 4, !tbaa !14
  %62 = icmp eq i32 %61, 3
  br i1 %62, label %66, label %63

63:                                               ; preds = %60
  %64 = load i32, ptr %6, align 4, !tbaa !14
  %65 = icmp eq i32 %64, 4
  br i1 %65, label %66, label %69

66:                                               ; preds = %63, %60
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  call void @m_ImageRGBToGray(ptr noundef %67, ptr noundef %68)
  br label %95

69:                                               ; preds = %63
  %70 = load i32, ptr %6, align 4, !tbaa !14
  %71 = icmp eq i32 %70, 5
  br i1 %71, label %72, label %75

72:                                               ; preds = %69
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = load ptr, ptr %4, align 8, !tbaa !5
  call void @m_ImageYUVToGray(ptr noundef %73, ptr noundef %74)
  br label %94

75:                                               ; preds = %69
  %76 = load i32, ptr %6, align 4, !tbaa !14
  %77 = icmp eq i32 %76, 6
  br i1 %77, label %78, label %83

78:                                               ; preds = %75
  %79 = load ptr, ptr %3, align 8, !tbaa !5
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  call void @m_ImageHSVToRGB(ptr noundef %79, ptr noundef %80)
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = load ptr, ptr %4, align 8, !tbaa !5
  call void @m_ImageRGBToGray(ptr noundef %81, ptr noundef %82)
  br label %93

83:                                               ; preds = %75
  br label %84

84:                                               ; preds = %83
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !14
  %85 = load i32, ptr %7, align 4, !tbaa !14
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %87, label %90

87:                                               ; preds = %84
  %88 = load i32, ptr %7, align 4, !tbaa !14
  %89 = load i32, ptr %6, align 4, !tbaa !14
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %88, i32 noundef -1, ptr noundef @.str, i32 noundef 171, ptr noundef @__FUNCTION__.m_ImageToGray, ptr noundef @.str.4, i32 noundef %89)
  br label %90

90:                                               ; preds = %87, %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %91

91:                                               ; preds = %90
  br label %92

92:                                               ; preds = %91
  br label %93

93:                                               ; preds = %92, %78
  br label %94

94:                                               ; preds = %93, %72
  br label %95

95:                                               ; preds = %94, %66
  br label %96

96:                                               ; preds = %95, %57
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  ret void
}

declare ptr @m_PropertyRead(ptr noundef, ptr noundef, ptr noundef, ptr noundef) #1

declare void @mImageCopy(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @m_ImageHSVToRGB(ptr noundef, ptr noundef) #2

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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"MImage", !11, i64 0, !11, i64 4, !11, i64 8, !7, i64 16, !6, i64 48}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !11, i64 8}
!14 = !{!11, !11, 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 [86 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@__FUNCTION__.m_ImageToGray = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [22 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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @m_ImageYUVToGray(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @m_ImageRGBToGray(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @m_ImageToGray(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca i32, align 4
  %magicptr = ptrtoint ptr %0 to i64
  switch i64 %magicptr, label %4 [
    i64 -1, label %.critedge
    i64 0, label %.critedge
  ]

4:                                                ; preds = %2
  %5 = getelementptr inbounds i8, ptr %0, i64 16
  %6 = icmp eq ptr %5, inttoptr (i64 -1 to ptr)
  br i1 %6, label %.critedge, label %7

7:                                                ; preds = %4
  %8 = load i32, ptr %0, align 8, !tbaa !5
  %9 = icmp slt i32 %8, 1
  br i1 %9, label %.critedge, label %10

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %0, i64 4
  %12 = load i32, ptr %11, align 4, !tbaa !11
  %13 = icmp slt i32 %12, 1
  br i1 %13, label %.critedge, label %14

14:                                               ; preds = %10
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i32, ptr %15, align 8, !tbaa !12
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %18, label %.critedge

.critedge:                                        ; preds = %2, %2, %10, %7, %4, %14
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 156, ptr noundef nonnull @__FUNCTION__.m_ImageToGray, ptr noundef nonnull @.str.1) #3
  br label %18

18:                                               ; preds = %.critedge, %14
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %19 = call ptr @m_PropertyRead(ptr noundef %0, ptr noundef nonnull @.str.3, ptr noundef nonnull %3, ptr noundef null) #3
  %20 = load i32, ptr %3, align 4
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %22, label %23

22:                                               ; preds = %18
  call void @mImageCopy(ptr noundef %0, ptr noundef %1) #3
  br label %30

23:                                               ; preds = %18
  %24 = add i32 %20, -3
  %or.cond9 = icmp ult i32 %24, 2
  br i1 %or.cond9, label %25, label %26

25:                                               ; preds = %23
  call void @m_ImageRGBToGray(ptr noundef %0, ptr noundef %1)
  br label %30

26:                                               ; preds = %23
  switch i32 %20, label %29 [
    i32 5, label %27
    i32 6, label %28
  ]

27:                                               ; preds = %26
  call void @m_ImageYUVToGray(ptr noundef %0, ptr noundef %1)
  br label %30

28:                                               ; preds = %26
  call void @m_ImageHSVToRGB(ptr noundef %0, ptr noundef %1)
  call void @m_ImageRGBToGray(ptr noundef %1, ptr noundef %1)
  br label %30

29:                                               ; preds = %26
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 171, ptr noundef nonnull @__FUNCTION__.m_ImageToGray, ptr noundef nonnull @.str.4, i32 noundef %20) #3
  br label %30

30:                                               ; preds = %25, %28, %29, %27, %22
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret void
}

declare ptr @m_PropertyRead(ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @mImageCopy(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @m_ImageHSVToRGB(ptr noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { 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 #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, !7, i64 0}
!6 = !{!"MImage", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 16, !10, i64 48}
!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 4}
!12 = !{!6, !7, i64 8}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass