; 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 }

@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_ImageDrawCurve = external hidden unnamed_addr constant [17 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_ImageDrawCurve(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.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
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %19, label %15

15:                                               ; preds = %5
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = ptrtoint ptr %16 to i64
  %18 = icmp eq i64 %17, -1
  br i1 %18, label %19, label %20

19:                                               ; preds = %15, %5
  store ptr @morn_default_color, ptr %9, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %19, %15
  br label %21

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

24:                                               ; preds = %21
  %25 = load i32, ptr %10, align 4, !tbaa !9
  %26 = icmp sgt i32 %25, 4
  br label %27

27:                                               ; preds = %24, %21
  %28 = phi i1 [ true, %21 ], [ %26, %24 ]
  %29 = zext i1 %28 to i32
  store i32 %29, ptr %11, align 4, !tbaa !9
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %27
  %33 = load i32, ptr %11, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %33, i32 noundef -1, ptr noundef @.str, i32 noundef 175, ptr noundef @__FUNCTION__.m_ImageDrawCurve, ptr noundef @.str.1)
  br label %34

34:                                               ; preds = %32, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %35

35:                                               ; preds = %34
  %36 = load i32, ptr %10, align 4, !tbaa !9
  %37 = icmp sle i32 %36, 0
  br i1 %37, label %38, label %39

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

39:                                               ; preds = %38, %35
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %53, label %42

42:                                               ; preds = %39
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = ptrtoint ptr %43 to i64
  %45 = icmp eq i64 %44, -1
  br i1 %45, label %53, label %46

46:                                               ; preds = %42
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = icmp ne ptr %47, %48
  br i1 %49, label %50, label %53

50:                                               ; preds = %46
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  call void @mImageCopy(ptr noundef %51, ptr noundef %52)
  br label %55

53:                                               ; preds = %46, %42, %39
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %54, ptr %7, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %53, %50
  call void @llvm.lifetime.start.p0(i64 24, ptr %12) #3
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.DrawPara, ptr %12, i32 0, i32 0
  store ptr %56, ptr %57, align 8, !tbaa !11
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.DrawPara, ptr %12, i32 0, i32 1
  store ptr %58, ptr %59, align 8, !tbaa !13
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = getelementptr inbounds %struct.DrawPara, ptr %12, i32 0, i32 2
  store i32 %60, ptr %61, align 8, !tbaa !14
  %62 = load ptr, ptr %8, align 8, !tbaa !5
  call void @mCurveTravel(ptr noundef %62, i32 noundef 1, ptr noundef @PointDraw, ptr noundef %12)
  call void @llvm.lifetime.end.p0(i64 24, ptr %12) #3
  ret void
}

declare void @mCurveTravel(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, !6, i64 0}
!12 = !{!"DrawPara", !6, i64 0, !6, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!12, !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_ImageDrawCurve = external hidden unnamed_addr constant [17 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_ImageDrawCurve(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 = add i32 %4, -5
  %8 = icmp ult i32 %7, -6
  br i1 %8, label %9, label %10

9:                                                ; 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 175, ptr noundef nonnull @__FUNCTION__.m_ImageDrawCurve, ptr noundef nonnull @.str.1) #4
  br label %10

10:                                               ; preds = %9, %5
  %magicptr = ptrtoint ptr %1 to i64
  switch i64 %magicptr, label %11 [
    i64 -1, label %13
    i64 0, label %13
  ]

11:                                               ; preds = %10
  %.not = icmp eq ptr %1, %0
  br i1 %.not, label %13, label %12

12:                                               ; preds = %11
  tail call void @mImageCopy(ptr noundef %0, ptr noundef %1) #4
  br label %13

13:                                               ; preds = %11, %10, %10, %12
  %.0 = phi ptr [ %1, %12 ], [ %0, %10 ], [ %0, %10 ], [ %0, %11 ]
  %spec.store.select6 = tail call i32 @llvm.smax.i32(i32 %4, i32 1)
  %14 = icmp eq ptr %3, null
  %15 = icmp eq ptr %3, inttoptr (i64 -1 to ptr)
  %or.cond = or i1 %14, %15
  %spec.store.select = select i1 %or.cond, ptr @morn_default_color, ptr %3
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #4
  store ptr %.0, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %6, i64 8
  store ptr %spec.store.select, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds i8, ptr %6, i64 16
  store i32 %spec.store.select6, ptr %17, align 8, !tbaa !12
  call void @mCurveTravel(ptr noundef %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
  ret void
}

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


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