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

; 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 }
%struct.MList = type { i32, ptr }
%struct.MImagePoint = type { float, float }

@.str = external hidden unnamed_addr constant [84 x i8], align 1
@__const.ImageHoughLineDrawImage.color = external hidden unnamed_addr constant [3 x i8], align 1
@__FUNCTION__.ImageHoughLineDrawImage = external hidden unnamed_addr constant [24 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [14 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 void @m_Exception(i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, ...) #1

; Function Attrs: nounwind uwtable
define dso_local void @ImageHoughLineDrawImage(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca [3 x i8], align 1
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.MImage, ptr %14, i32 0, i32 0
  %16 = load i32, ptr %15, align 8, !tbaa !9
  %17 = add nsw i32 %16, 0
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.MImage, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 4, !tbaa !12
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.MImage, ptr %21, i32 0, i32 2
  %23 = load i32, ptr %22, align 8, !tbaa !13
  %24 = call ptr @ImageCreate(i32 noundef %17, i32 noundef %20, i32 noundef %23, ptr noundef null)
  store ptr %24, ptr %7, align 8, !tbaa !5
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  call void @mImageCopy(ptr noundef %25, ptr noundef %26)
  call void @llvm.lifetime.start.p0(i64 3, ptr %8) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %8, ptr align 1 @__const.ImageHoughLineDrawImage.color, i64 3, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !14
  br label %27

27:                                               ; preds = %124, %3
  %28 = load i32, ptr %9, align 4, !tbaa !14
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.MList, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !15
  %32 = icmp slt i32 %28, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  br label %127

34:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.MList, ptr %35, i32 0, i32 1
  %37 = load ptr, ptr %36, align 8, !tbaa !17
  %38 = load i32, ptr %9, align 4, !tbaa !14
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds ptr, ptr %37, i64 %39
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  store ptr %41, ptr %10, align 8, !tbaa !5
  br label %42

42:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 4, ptr %11, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %43 = load i32, ptr %11, align 4, !tbaa !14
  %44 = icmp eq i32 %43, 2
  br i1 %44, label %45, label %53

45:                                               ; preds = %42
  %46 = load ptr, ptr %7, align 8, !tbaa !5
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.MImagePoint, ptr %48, i64 0
  %50 = getelementptr inbounds %struct.MImagePoint, ptr %49, i64 0
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.MImagePoint, ptr %51, i64 1
  call void @m_ImageDrawLine(ptr noundef %46, ptr noundef %47, ptr noundef %50, ptr noundef %52, ptr noundef null, i32 noundef -1)
  br label %121

53:                                               ; preds = %42
  %54 = load i32, ptr %11, align 4, !tbaa !14
  %55 = icmp eq i32 %54, 3
  br i1 %55, label %56, label %84

56:                                               ; preds = %53
  %57 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 0
  %58 = ptrtoint ptr %57 to i64
  store i64 %58, ptr %12, align 8, !tbaa !18
  %59 = load i64, ptr %12, align 8, !tbaa !18
  %60 = icmp sle i64 %59, 4
  br i1 %60, label %61, label %74

61:                                               ; preds = %56
  %62 = load i64, ptr %12, align 8, !tbaa !18
  %63 = icmp sge i64 %62, -1
  br i1 %63, label %64, label %74

64:                                               ; preds = %61
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load ptr, ptr %7, align 8, !tbaa !5
  %67 = load ptr, ptr %10, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.MImagePoint, ptr %67, i64 0
  %69 = getelementptr inbounds %struct.MImagePoint, ptr %68, i64 0
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.MImagePoint, ptr %70, i64 1
  %72 = load i64, ptr %12, align 8, !tbaa !18
  %73 = trunc i64 %72 to i32
  call void @m_ImageDrawLine(ptr noundef %65, ptr noundef %66, ptr noundef %69, ptr noundef %71, ptr noundef null, i32 noundef %73)
  br label %83

74:                                               ; preds = %61, %56
  %75 = load ptr, ptr %7, align 8, !tbaa !5
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = load ptr, ptr %10, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.MImagePoint, ptr %77, i64 0
  %79 = getelementptr inbounds %struct.MImagePoint, ptr %78, i64 0
  %80 = load ptr, ptr %10, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.MImagePoint, ptr %80, i64 1
  %82 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 0
  call void @m_ImageDrawLine(ptr noundef %75, ptr noundef %76, ptr noundef %79, ptr noundef %81, ptr noundef %82, i32 noundef -1)
  br label %83

83:                                               ; preds = %74, %64
  br label %120

84:                                               ; preds = %53
  %85 = load i32, ptr %11, align 4, !tbaa !14
  %86 = icmp eq i32 %85, 4
  br i1 %86, label %87, label %98

87:                                               ; preds = %84
  store i64 4, ptr %12, align 8, !tbaa !18
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = load ptr, ptr %7, align 8, !tbaa !5
  %90 = load ptr, ptr %10, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.MImagePoint, ptr %90, i64 0
  %92 = getelementptr inbounds %struct.MImagePoint, ptr %91, i64 0
  %93 = load ptr, ptr %10, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.MImagePoint, ptr %93, i64 1
  %95 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 0
  %96 = load i64, ptr %12, align 8, !tbaa !18
  %97 = trunc i64 %96 to i32
  call void @m_ImageDrawLine(ptr noundef %88, ptr noundef %89, ptr noundef %92, ptr noundef %94, ptr noundef %95, i32 noundef %97)
  br label %119

98:                                               ; preds = %84
  %99 = load i32, ptr %11, align 4, !tbaa !14
  %100 = icmp eq i32 %99, 5
  br i1 %100, label %101, label %109

101:                                              ; preds = %98
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = load ptr, ptr %10, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.MImagePoint, ptr %103, i64 0
  %105 = getelementptr inbounds %struct.MImagePoint, ptr %104, i64 0
  %106 = load ptr, ptr %10, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.MImagePoint, ptr %106, i64 1
  %108 = getelementptr inbounds [3 x i8], ptr %8, i64 0, i64 0
  call void @m_ImageDrawLine(ptr noundef %102, ptr noundef %105, ptr noundef %107, ptr noundef %108, ptr noundef inttoptr (i64 4 to ptr), i32 noundef -1)
  br label %118

109:                                              ; preds = %98
  br label %110

110:                                              ; preds = %109
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 1, ptr %13, align 4, !tbaa !14
  %111 = load i32, ptr %13, align 4, !tbaa !14
  %112 = icmp ne i32 %111, 0
  br i1 %112, label %113, label %115

113:                                              ; preds = %110
  %114 = load i32, ptr %13, align 4, !tbaa !14
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %114, i32 noundef -1, ptr noundef @.str, i32 noundef 266, ptr noundef @__FUNCTION__.ImageHoughLineDrawImage, ptr noundef @.str.4)
  br label %115

115:                                              ; preds = %113, %110
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %116

116:                                              ; preds = %115
  br label %117

117:                                              ; preds = %116
  br label %118

118:                                              ; preds = %117, %101
  br label %119

119:                                              ; preds = %118, %87
  br label %120

120:                                              ; preds = %119, %83
  br label %121

121:                                              ; preds = %120, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %122

122:                                              ; preds = %121
  br label %123

123:                                              ; preds = %122
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %124

124:                                              ; preds = %123
  %125 = load i32, ptr %9, align 4, !tbaa !14
  %126 = add nsw i32 %125, 1
  store i32 %126, ptr %9, align 4, !tbaa !14
  br label %27, !llvm.loop !20

127:                                              ; preds = %33
  %128 = load ptr, ptr %7, align 8, !tbaa !5
  %129 = load ptr, ptr %6, align 8, !tbaa !5
  call void @mBMPSave(ptr noundef %128, ptr noundef %129)
  %130 = load ptr, ptr %7, align 8, !tbaa !5
  call void @mImageRelease(ptr noundef %130)
  call void @llvm.lifetime.end.p0(i64 3, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

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

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

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

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

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

declare void @mImageRelease(ptr noundef) #1

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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}
!15 = !{!16, !11, i64 0}
!16 = !{!"MList", !11, i64 0, !6, i64 8}
!17 = !{!16, !6, i64 8}
!18 = !{!19, !19, i64 0}
!19 = !{!"long", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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"

@__const.ImageHoughLineDrawImage.color = external hidden unnamed_addr constant [3 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: nounwind uwtable
define dso_local void @ImageHoughLineDrawImage(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #1 {
  %4 = alloca [3 x i8], align 1
  %5 = load i32, ptr %0, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 4
  %7 = load i32, ptr %6, align 4, !tbaa !11
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = load i32, ptr %8, align 8, !tbaa !12
  %10 = tail call ptr @ImageCreate(i32 noundef %5, i32 noundef %7, i32 noundef %9, ptr noundef null) #4
  tail call void @mImageCopy(ptr noundef nonnull %0, ptr noundef %10) #4
  call void @llvm.lifetime.start.p0(i64 3, ptr nonnull %4) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(3) %4, ptr noundef nonnull align 1 dereferenceable(3) @__const.ImageHoughLineDrawImage.color, i64 3, i1 false)
  %11 = load i32, ptr %1, align 8, !tbaa !13
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3
  %13 = getelementptr inbounds i8, ptr %1, i64 8
  br label %14

._crit_edge:                                      ; preds = %14, %3
  call void @mBMPSave(ptr noundef %10, ptr noundef %2) #4
  call void @mImageRelease(ptr noundef %10) #4
  call void @llvm.lifetime.end.p0(i64 3, ptr nonnull %4) #4
  ret void

14:                                               ; preds = %.lr.ph, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %14 ]
  %15 = load ptr, ptr %13, align 8, !tbaa !15
  %16 = getelementptr inbounds ptr, ptr %15, i64 %indvars.iv
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = getelementptr inbounds i8, ptr %17, i64 8
  call void @m_ImageDrawLine(ptr noundef %10, ptr noundef %10, ptr noundef %17, ptr noundef nonnull %18, ptr noundef nonnull %4, i32 noundef 4) #4
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = load i32, ptr %1, align 8, !tbaa !13
  %20 = sext i32 %19 to i64
  %21 = icmp slt i64 %indvars.iv.next, %20
  br i1 %21, label %14, label %._crit_edge, !llvm.loop !17
}

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

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

; Function Attrs: mustprogress 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) #3

declare void @m_ImageDrawLine(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

declare void @mBMPSave(ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @mImageRelease(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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: readwrite) }
attributes #4 = { 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}
!13 = !{!14, !7, i64 0}
!14 = !{!"MList", !7, i64 0, !10, i64 8}
!15 = !{!14, !10, i64 8}
!16 = !{!10, !10, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass