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

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

@morn_default_color = external hidden global [4 x i8], align 1
@.str = external hidden unnamed_addr constant [83 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__.m_ImageDrawRect = external hidden unnamed_addr constant [16 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
declare dso_local void @PointDraw(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
define dso_local void @m_ImageDrawRect(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca %struct.MImagePoint, align 4
  %13 = alloca %struct.MImagePoint, align 4
  %14 = alloca %struct.MImagePoint, align 4
  %15 = alloca %struct.MImagePoint, align 4
  %16 = alloca %struct.DrawPara, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !9
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %23, label %19

19:                                               ; preds = %5
  %20 = load ptr, ptr %9, 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, %5
  store ptr @morn_default_color, ptr %9, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %23, %19
  br label %25

25:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = icmp slt i32 %26, -1
  br i1 %27, label %31, label %28

28:                                               ; preds = %25
  %29 = load i32, ptr %10, align 4, !tbaa !9
  %30 = icmp sgt i32 %29, 4
  br label %31

31:                                               ; preds = %28, %25
  %32 = phi i1 [ true, %25 ], [ %30, %28 ]
  %33 = zext i1 %32 to i32
  store i32 %33, ptr %11, align 4, !tbaa !9
  %34 = load i32, ptr %11, align 4, !tbaa !9
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %31
  %37 = load i32, ptr %11, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %37, i32 noundef -1, ptr noundef @.str, i32 noundef 87, ptr noundef @__FUNCTION__.m_ImageDrawRect, ptr noundef @.str.1)
  br label %38

38:                                               ; preds = %36, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = icmp sle i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %39
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %42, %39
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.MImageRect, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !11
  %47 = sitofp i32 %46 to float
  %48 = getelementptr inbounds %struct.MImagePoint, ptr %12, i32 0, i32 0
  store float %47, ptr %48, align 4, !tbaa !13
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.MImageRect, ptr %49, i32 0, i32 2
  %51 = load i32, ptr %50, align 4, !tbaa !16
  %52 = sitofp i32 %51 to float
  %53 = getelementptr inbounds %struct.MImagePoint, ptr %12, i32 0, i32 1
  store float %52, ptr %53, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.MImageRect, ptr %54, i32 0, i32 1
  %56 = load i32, ptr %55, align 4, !tbaa !18
  %57 = sub nsw i32 %56, 1
  %58 = sitofp i32 %57 to float
  %59 = getelementptr inbounds %struct.MImagePoint, ptr %13, i32 0, i32 0
  store float %58, ptr %59, align 4, !tbaa !13
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.MImageRect, ptr %60, i32 0, i32 2
  %62 = load i32, ptr %61, align 4, !tbaa !16
  %63 = sitofp i32 %62 to float
  %64 = getelementptr inbounds %struct.MImagePoint, ptr %13, i32 0, i32 1
  store float %63, ptr %64, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.MImageRect, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 4, !tbaa !18
  %68 = sub nsw i32 %67, 1
  %69 = sitofp i32 %68 to float
  %70 = getelementptr inbounds %struct.MImagePoint, ptr %14, i32 0, i32 0
  store float %69, ptr %70, align 4, !tbaa !13
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.MImageRect, ptr %71, i32 0, i32 3
  %73 = load i32, ptr %72, align 4, !tbaa !19
  %74 = sub nsw i32 %73, 1
  %75 = sitofp i32 %74 to float
  %76 = getelementptr inbounds %struct.MImagePoint, ptr %14, i32 0, i32 1
  store float %75, ptr %76, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.MImageRect, ptr %77, i32 0, i32 0
  %79 = load i32, ptr %78, align 4, !tbaa !11
  %80 = sitofp i32 %79 to float
  %81 = getelementptr inbounds %struct.MImagePoint, ptr %15, i32 0, i32 0
  store float %80, ptr %81, align 4, !tbaa !13
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.MImageRect, ptr %82, i32 0, i32 3
  %84 = load i32, ptr %83, align 4, !tbaa !19
  %85 = sub nsw i32 %84, 1
  %86 = sitofp i32 %85 to float
  %87 = getelementptr inbounds %struct.MImagePoint, ptr %15, i32 0, i32 1
  store float %86, ptr %87, align 4, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 24, ptr %16) #3
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.DrawPara, ptr %16, i32 0, i32 0
  store ptr %88, ptr %89, align 8, !tbaa !20
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.DrawPara, ptr %16, i32 0, i32 1
  store ptr %90, ptr %91, align 8, !tbaa !22
  %92 = load i32, ptr %10, align 4, !tbaa !9
  %93 = getelementptr inbounds %struct.DrawPara, ptr %16, i32 0, i32 2
  store i32 %92, ptr %93, align 8, !tbaa !23
  call void @mLineTravel(ptr noundef %12, ptr noundef %13, i32 noundef 1, ptr noundef @PointDraw, ptr noundef %16)
  call void @mLineTravel(ptr noundef %13, ptr noundef %14, i32 noundef 1, ptr noundef @PointDraw, ptr noundef %16)
  call void @mLineTravel(ptr noundef %14, ptr noundef %15, i32 noundef 1, ptr noundef @PointDraw, ptr noundef %16)
  call void @mLineTravel(ptr noundef %15, ptr noundef %12, i32 noundef 1, ptr noundef @PointDraw, ptr noundef %16)
  call void @PointDraw(ptr noundef %14, ptr noundef %16)
  call void @llvm.lifetime.end.p0(i64 24, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  ret void
}

declare void @mLineTravel(ptr noundef, ptr noundef, i32 noundef, ptr noundef, 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 = { 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 = !{!"MImageRect", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!13 = !{!14, !15, i64 0}
!14 = !{!"MImagePoint", !15, i64 0, !15, i64 4}
!15 = !{!"float", !7, i64 0}
!16 = !{!12, !10, i64 8}
!17 = !{!14, !15, i64 4}
!18 = !{!12, !10, i64 4}
!19 = !{!12, !10, i64 12}
!20 = !{!21, !6, i64 0}
!21 = !{!"DrawPara", !6, i64 0, !6, i64 8, !10, i64 16}
!22 = !{!21, !6, i64 8}
!23 = !{!21, !10, i64 16}


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

@morn_default_color = external hidden global [4 x i8], align 1
@.str = external hidden unnamed_addr constant [83 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1
@__FUNCTION__.m_ImageDrawRect = external hidden unnamed_addr constant [16 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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @m_ImageDrawRect(ptr nocapture noundef readnone %0, ptr noundef %1, ptr nocapture noundef readonly %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca %struct.MImagePoint, align 4
  %7 = alloca %struct.MImagePoint, align 4
  %8 = alloca %struct.MImagePoint, align 8
  %9 = alloca %struct.MImagePoint, align 4
  %10 = alloca %struct.DrawPara, align 8
  %11 = add i32 %4, -5
  %12 = icmp ult i32 %11, -6
  br i1 %12, label %13, label %14

13:                                               ; preds = %5
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 87, ptr noundef nonnull @__FUNCTION__.m_ImageDrawRect, ptr noundef nonnull @.str.1) #4
  br label %14

14:                                               ; preds = %13, %5
  %15 = icmp eq ptr %3, null
  %16 = icmp eq ptr %3, inttoptr (i64 -1 to ptr)
  %or.cond = or i1 %15, %16
  %spec.store.select = select i1 %or.cond, ptr @morn_default_color, ptr %3
  %spec.store.select3 = tail call i32 @llvm.smax.i32(i32 %4, i32 1)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sitofp i32 %17 to float
  store float %18, ptr %6, align 4, !tbaa !10
  %19 = getelementptr inbounds i8, ptr %2, i64 8
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = sitofp i32 %20 to float
  %22 = getelementptr inbounds i8, ptr %6, i64 4
  store float %21, ptr %22, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  %23 = getelementptr inbounds i8, ptr %2, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !15
  %25 = getelementptr inbounds i8, ptr %7, i64 4
  store float %21, ptr %25, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #4
  %26 = getelementptr inbounds i8, ptr %2, i64 12
  %27 = load i32, ptr %26, align 4, !tbaa !16
  %28 = insertelement <2 x i32> poison, i32 %24, i64 0
  %29 = insertelement <2 x i32> %28, i32 %27, i64 1
  %30 = add nsw <2 x i32> %29, <i32 -1, i32 -1>
  %31 = sitofp <2 x i32> %30 to <2 x float>
  %32 = extractelement <2 x float> %31, i64 0
  store float %32, ptr %7, align 4, !tbaa !10
  store <2 x float> %31, ptr %8, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #4
  store float %18, ptr %9, align 4, !tbaa !10
  %33 = getelementptr inbounds i8, ptr %9, i64 4
  %34 = extractelement <2 x float> %31, i64 1
  store float %34, ptr %33, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %10) #4
  store ptr %1, ptr %10, align 8, !tbaa !18
  %35 = getelementptr inbounds i8, ptr %10, i64 8
  store ptr %spec.store.select, ptr %35, align 8, !tbaa !21
  %36 = getelementptr inbounds i8, ptr %10, i64 16
  store i32 %spec.store.select3, ptr %36, align 8, !tbaa !22
  call void @mLineTravel(ptr noundef nonnull %6, ptr noundef nonnull %7, i32 noundef 1, ptr noundef nonnull @PointDraw, ptr noundef nonnull %10) #4
  call void @mLineTravel(ptr noundef nonnull %7, ptr noundef nonnull %8, i32 noundef 1, ptr noundef nonnull @PointDraw, ptr noundef nonnull %10) #4
  call void @mLineTravel(ptr noundef nonnull %8, ptr noundef nonnull %9, i32 noundef 1, ptr noundef nonnull @PointDraw, ptr noundef nonnull %10) #4
  call void @mLineTravel(ptr noundef nonnull %9, ptr noundef nonnull %6, i32 noundef 1, ptr noundef nonnull @PointDraw, ptr noundef nonnull %10) #4
  call void @PointDraw(ptr noundef nonnull %8, ptr noundef nonnull %10)
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #3

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"MImageRect", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!11, !12, i64 0}
!11 = !{!"MImagePoint", !12, i64 0, !12, i64 4}
!12 = !{!"float", !8, i64 0}
!13 = !{!6, !7, i64 8}
!14 = !{!11, !12, i64 4}
!15 = !{!6, !7, i64 4}
!16 = !{!6, !7, i64 12}
!17 = !{!12, !12, i64 0}
!18 = !{!19, !20, i64 0}
!19 = !{!"DrawPara", !20, i64 0, !20, i64 8, !7, i64 16}
!20 = !{!"any pointer", !8, i64 0}
!21 = !{!19, !20, i64 8}
!22 = !{!19, !7, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass