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

; 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 [87 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [19 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__.mImageCanny = external hidden unnamed_addr constant [12 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

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

declare void @ImageRedefine(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) #1

declare void @mImageRelease(ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @mImageCanny(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  br label %16

16:                                               ; preds = %4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %23, label %19

19:                                               ; preds = %16
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = ptrtoint ptr %20 to i64
  %22 = icmp eq i64 %21, -1
  br i1 %22, label %23, label %24

23:                                               ; preds = %19, %16
  br label %53

24:                                               ; preds = %19
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.MImage, ptr %25, i32 0, i32 3
  %27 = getelementptr inbounds [4 x ptr], ptr %26, i64 0, i64 0
  %28 = icmp eq ptr %27, null
  br i1 %28, label %50, label %29

29:                                               ; preds = %24
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.MImage, ptr %30, i32 0, i32 3
  %32 = getelementptr inbounds [4 x ptr], ptr %31, i64 0, i64 0
  %33 = ptrtoint ptr %32 to i64
  %34 = icmp eq i64 %33, -1
  br i1 %34, label %50, label %35

35:                                               ; preds = %29
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.MImage, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !11
  %39 = icmp sle i32 %38, 0
  br i1 %39, label %50, label %40

40:                                               ; preds = %35
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.MImage, ptr %41, i32 0, i32 1
  %43 = load i32, ptr %42, align 4, !tbaa !13
  %44 = icmp sle i32 %43, 0
  br i1 %44, label %50, label %45

45:                                               ; preds = %40
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.MImage, ptr %46, i32 0, i32 2
  %48 = load i32, ptr %47, align 8, !tbaa !14
  %49 = icmp sle i32 %48, 0
  br label %50

50:                                               ; preds = %45, %40, %35, %29, %24
  %51 = phi i1 [ true, %40 ], [ true, %35 ], [ true, %29 ], [ true, %24 ], [ %49, %45 ]
  %52 = zext i1 %51 to i32
  br label %53

53:                                               ; preds = %50, %23
  %54 = phi i32 [ 1, %23 ], [ %52, %50 ]
  store i32 %54, ptr %13, align 4, !tbaa !9
  %55 = load i32, ptr %13, align 4, !tbaa !9
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %59

57:                                               ; preds = %53
  %58 = load i32, ptr %13, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %58, i32 noundef -1, ptr noundef @.str, i32 noundef 332, ptr noundef @__FUNCTION__.mImageCanny, ptr noundef @.str.3)
  br label %59

59:                                               ; preds = %57, %53
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %60

60:                                               ; preds = %59
  br label %61

61:                                               ; preds = %60
  %62 = load ptr, ptr %5, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.MImage, ptr %62, i32 0, i32 2
  %64 = load i32, ptr %63, align 8, !tbaa !14
  store i32 %64, ptr %10, align 4, !tbaa !9
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.MImage, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 4, !tbaa !13
  store i32 %67, ptr %9, align 4, !tbaa !9
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = icmp eq ptr %68, null
  br i1 %69, label %70, label %72

70:                                               ; preds = %61
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %71, ptr %6, align 8, !tbaa !5
  br label %72

72:                                               ; preds = %70, %61
  %73 = load i32, ptr %9, align 4, !tbaa !9
  %74 = load i32, ptr %10, align 4, !tbaa !9
  %75 = call ptr @ImageCreate(i32 noundef 1, i32 noundef %73, i32 noundef %74, ptr noundef null)
  store ptr %75, ptr %11, align 8, !tbaa !5
  %76 = load i32, ptr %9, align 4, !tbaa !9
  %77 = load i32, ptr %10, align 4, !tbaa !9
  %78 = call ptr @ImageCreate(i32 noundef 1, i32 noundef %76, i32 noundef %77, ptr noundef null)
  store ptr %78, ptr %12, align 8, !tbaa !5
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = load i32, ptr %8, align 4, !tbaa !9
  call void @mImageGradient(ptr noundef %79, ptr noundef %80, ptr noundef %81, i32 noundef %82, i32 noundef %83)
  br label %84

84:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  store i32 4, ptr %14, align 4, !tbaa !9
  %85 = load i32, ptr %14, align 4, !tbaa !9
  %86 = icmp eq i32 %85, 2
  br i1 %86, label %87, label %93

87:                                               ; preds = %84
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = load i32, ptr %9, align 4, !tbaa !9
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.MImage, ptr %90, i32 0, i32 3
  %92 = getelementptr inbounds [4 x ptr], ptr %91, i64 0, i64 0
  call void @ImageRedefine(ptr noundef %88, i32 noundef -1, i32 noundef 1, i32 noundef %89, ptr noundef %92)
  br label %124

93:                                               ; preds = %84
  %94 = load i32, ptr %14, align 4, !tbaa !9
  %95 = icmp eq i32 %94, 3
  br i1 %95, label %96, label %103

96:                                               ; preds = %93
  %97 = load ptr, ptr %6, align 8, !tbaa !5
  %98 = load i32, ptr %9, align 4, !tbaa !9
  %99 = load i32, ptr %10, align 4, !tbaa !9
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.MImage, ptr %100, i32 0, i32 3
  %102 = getelementptr inbounds [4 x ptr], ptr %101, i64 0, i64 0
  call void @ImageRedefine(ptr noundef %97, i32 noundef 1, i32 noundef %98, i32 noundef %99, ptr noundef %102)
  br label %123

103:                                              ; preds = %93
  %104 = load i32, ptr %14, align 4, !tbaa !9
  %105 = icmp eq i32 %104, 4
  br i1 %105, label %106, label %113

106:                                              ; preds = %103
  %107 = load ptr, ptr %6, align 8, !tbaa !5
  %108 = load i32, ptr %9, align 4, !tbaa !9
  %109 = load i32, ptr %10, align 4, !tbaa !9
  %110 = load ptr, ptr %6, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.MImage, ptr %110, i32 0, i32 3
  %112 = getelementptr inbounds [4 x ptr], ptr %111, i64 0, i64 0
  call void @ImageRedefine(ptr noundef %107, i32 noundef 1, i32 noundef %108, i32 noundef %109, ptr noundef %112)
  br label %122

113:                                              ; preds = %103
  br label %114

114:                                              ; preds = %113
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  store i32 1, ptr %15, align 4, !tbaa !9
  %115 = load i32, ptr %15, align 4, !tbaa !9
  %116 = icmp ne i32 %115, 0
  br i1 %116, label %117, label %119

117:                                              ; preds = %114
  %118 = load i32, ptr %15, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %118, i32 noundef -1, ptr noundef @.str, i32 noundef 359, ptr noundef @__FUNCTION__.mImageCanny, ptr noundef @.str.2)
  br label %119

119:                                              ; preds = %117, %114
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %120

120:                                              ; preds = %119
  br label %121

121:                                              ; preds = %120
  br label %122

122:                                              ; preds = %121, %106
  br label %123

123:                                              ; preds = %122, %96
  br label %124

124:                                              ; preds = %123, %87
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  br label %125

125:                                              ; preds = %124
  br label %126

126:                                              ; preds = %125
  %127 = load ptr, ptr %11, align 8, !tbaa !5
  %128 = load ptr, ptr %12, align 8, !tbaa !5
  %129 = load ptr, ptr %6, align 8, !tbaa !5
  %130 = load i32, ptr %7, align 4, !tbaa !9
  %131 = add nsw i32 %130, 1
  call void @mImageGradientSuppression(ptr noundef %127, ptr noundef %128, ptr noundef %129, i32 noundef %131)
  %132 = load ptr, ptr %11, align 8, !tbaa !5
  call void @mImageRelease(ptr noundef %132)
  %133 = load ptr, ptr %12, align 8, !tbaa !5
  call void @mImageRelease(ptr noundef %133)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  ret void
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"MImage", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 16, !6, i64 48}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 8}


; 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 [87 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__.mImageCanny = external hidden unnamed_addr constant [12 x i8], align 1

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

declare ptr @ImageCreate(i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare void @ImageRedefine(ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

declare void @mImageRelease(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @mImageGradient(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @mImageGradientSuppression(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

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

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

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

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

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

.critedge:                                        ; preds = %4, %4, %11, %8, %5, %15
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 332, ptr noundef nonnull @__FUNCTION__.mImageCanny, ptr noundef nonnull @.str.3) #2
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 8
  %.pre = load i32, ptr %.phi.trans.insert, align 8, !tbaa !12
  %.phi.trans.insert53 = getelementptr inbounds i8, ptr %0, i64 4
  %.pre54 = load i32, ptr %.phi.trans.insert53, align 4, !tbaa !11
  br label %19

19:                                               ; preds = %.critedge, %15
  %20 = phi i32 [ %.pre54, %.critedge ], [ %13, %15 ]
  %21 = phi i32 [ %.pre, %.critedge ], [ %17, %15 ]
  %22 = icmp eq ptr %1, null
  %spec.select = select i1 %22, ptr %0, ptr %1
  %23 = tail call ptr @ImageCreate(i32 noundef 1, i32 noundef %20, i32 noundef %21, ptr noundef null) #2
  %24 = tail call ptr @ImageCreate(i32 noundef 1, i32 noundef %20, i32 noundef %21, ptr noundef null) #2
  tail call void @mImageGradient(ptr noundef nonnull %0, ptr noundef %23, ptr noundef %24, i32 noundef %2, i32 noundef %3)
  %25 = getelementptr inbounds i8, ptr %spec.select, i64 16
  tail call void @ImageRedefine(ptr noundef %spec.select, i32 noundef 1, i32 noundef %20, i32 noundef %21, ptr noundef nonnull %25) #2
  %26 = add nsw i32 %2, 1
  tail call void @mImageGradientSuppression(ptr noundef %23, ptr noundef %24, ptr noundef %spec.select, i32 noundef %26)
  tail call void @mImageRelease(ptr noundef %23) #2
  tail call void @mImageRelease(ptr noundef %24) #2
  ret void
}

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 = { 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 }

!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: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass