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

@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_ImageDrawShape = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = 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

declare void @mImageCopy(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_ImageDrawShape(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 i32, align 4
  %13 = 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
  br label %14

14:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  %17 = zext i1 %16 to i32
  store i32 %17, ptr %11, align 4, !tbaa !9
  %18 = load i32, ptr %11, align 4, !tbaa !9
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %22

20:                                               ; preds = %14
  %21 = load i32, ptr %11, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %21, i32 noundef -1, ptr noundef @.str, i32 noundef 112, ptr noundef @__FUNCTION__.m_ImageDrawShape, ptr noundef @.str.2)
  br label %22

22:                                               ; preds = %20, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %23

23:                                               ; preds = %22
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.MList, ptr %24, i32 0, i32 0
  %26 = load i32, ptr %25, align 8, !tbaa !11
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  br label %80

29:                                               ; preds = %23
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = icmp eq ptr %30, null
  br i1 %31, label %36, label %32

32:                                               ; preds = %29
  %33 = load ptr, ptr %9, align 8, !tbaa !5
  %34 = ptrtoint ptr %33 to i64
  %35 = icmp eq i64 %34, -1
  br i1 %35, label %36, label %37

36:                                               ; preds = %32, %29
  store ptr @morn_default_color, ptr %9, align 8, !tbaa !5
  br label %37

37:                                               ; preds = %36, %32
  br label %38

38:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %39 = load i32, ptr %10, align 4, !tbaa !9
  %40 = icmp slt i32 %39, -1
  br i1 %40, label %44, label %41

41:                                               ; preds = %38
  %42 = load i32, ptr %10, align 4, !tbaa !9
  %43 = icmp sgt i32 %42, 4
  br label %44

44:                                               ; preds = %41, %38
  %45 = phi i1 [ true, %38 ], [ %43, %41 ]
  %46 = zext i1 %45 to i32
  store i32 %46, ptr %12, align 4, !tbaa !9
  %47 = load i32, ptr %12, align 4, !tbaa !9
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %51

49:                                               ; preds = %44
  %50 = load i32, ptr %12, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %50, i32 noundef -1, ptr noundef @.str, i32 noundef 117, ptr noundef @__FUNCTION__.m_ImageDrawShape, ptr noundef @.str.1)
  br label %51

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

52:                                               ; preds = %51
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = icmp sle i32 %53, 0
  br i1 %54, label %55, label %56

55:                                               ; preds = %52
  store i32 1, ptr %10, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %55, %52
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = icmp eq ptr %57, null
  br i1 %58, label %70, label %59

59:                                               ; preds = %56
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = ptrtoint ptr %60 to i64
  %62 = icmp eq i64 %61, -1
  br i1 %62, label %70, label %63

63:                                               ; preds = %59
  %64 = load ptr, ptr %7, align 8, !tbaa !5
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = icmp ne ptr %64, %65
  br i1 %66, label %67, label %70

67:                                               ; preds = %63
  %68 = load ptr, ptr %6, align 8, !tbaa !5
  %69 = load ptr, ptr %7, align 8, !tbaa !5
  call void @mImageCopy(ptr noundef %68, ptr noundef %69)
  br label %72

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

72:                                               ; preds = %70, %67
  call void @llvm.lifetime.start.p0(i64 24, ptr %13) #3
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.DrawPara, ptr %13, i32 0, i32 0
  store ptr %73, ptr %74, align 8, !tbaa !13
  %75 = load ptr, ptr %9, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.DrawPara, ptr %13, i32 0, i32 1
  store ptr %75, ptr %76, align 8, !tbaa !15
  %77 = load i32, ptr %10, align 4, !tbaa !9
  %78 = getelementptr inbounds %struct.DrawPara, ptr %13, i32 0, i32 2
  store i32 %77, ptr %78, align 8, !tbaa !16
  %79 = load ptr, ptr %8, align 8, !tbaa !5
  call void @mPolygonSideTravel(ptr noundef %79, i32 noundef 1, ptr noundef @PointDraw, ptr noundef %13)
  call void @llvm.lifetime.end.p0(i64 24, ptr %13) #3
  br label %80

80:                                               ; preds = %72, %28
  ret void
}

declare void @mPolygonSideTravel(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 = !{!"MList", !10, i64 0, !6, i64 8}
!13 = !{!14, !6, i64 0}
!14 = !{!"DrawPara", !6, i64 0, !6, i64 8, !10, i64 16}
!15 = !{!14, !6, i64 8}
!16 = !{!14, !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.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_ImageDrawShape = external hidden unnamed_addr constant [17 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [14 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

declare void @mImageCopy(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_ImageDrawShape(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca %struct.DrawPara, align 8
  %7 = icmp eq ptr %2, null
  br i1 %7, label %8, label %9

8:                                                ; 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 112, ptr noundef nonnull @__FUNCTION__.m_ImageDrawShape, ptr noundef nonnull @.str.2) #4
  br label %9

9:                                                ; preds = %8, %5
  %10 = load i32, ptr %2, align 8, !tbaa !5
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %24, label %12

12:                                               ; preds = %9
  %13 = icmp eq ptr %3, null
  %14 = icmp eq ptr %3, inttoptr (i64 -1 to ptr)
  %or.cond = or i1 %13, %14
  %spec.store.select = select i1 %or.cond, ptr @morn_default_color, ptr %3
  %15 = add i32 %4, -5
  %16 = icmp ult i32 %15, -6
  br i1 %16, label %17, label %18

17:                                               ; preds = %12
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 117, ptr noundef nonnull @__FUNCTION__.m_ImageDrawShape, ptr noundef nonnull @.str.1) #4
  br label %18

18:                                               ; preds = %17, %12
  %spec.store.select6 = tail call i32 @llvm.smax.i32(i32 %4, i32 1)
  %magicptr = ptrtoint ptr %1 to i64
  switch i64 %magicptr, label %19 [
    i64 -1, label %21
    i64 0, label %21
  ]

19:                                               ; preds = %18
  %.not = icmp eq ptr %1, %0
  br i1 %.not, label %21, label %20

20:                                               ; preds = %19
  tail call void @mImageCopy(ptr noundef %0, ptr noundef %1) #4
  br label %21

21:                                               ; preds = %19, %18, %18, %20
  %.0 = phi ptr [ %1, %20 ], [ %0, %18 ], [ %0, %18 ], [ %0, %19 ]
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #4
  store ptr %.0, ptr %6, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %6, i64 8
  store ptr %spec.store.select, ptr %22, align 8, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %6, i64 16
  store i32 %spec.store.select6, ptr %23, align 8, !tbaa !14
  call void @mPolygonSideTravel(ptr noundef nonnull %2, i32 noundef 1, ptr noundef nonnull @PointDraw, ptr noundef nonnull %6) #4
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #4
  br label %24

24:                                               ; preds = %9, %21
  ret void
}

declare void @mPolygonSideTravel(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 = !{!"MList", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"DrawPara", !10, i64 0, !10, i64 8, !7, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !7, i64 16}


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