; 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_ImageDrawLine = 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

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

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

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

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

17:                                               ; preds = %6
  %18 = load ptr, ptr %11, align 8, !tbaa !5
  %19 = ptrtoint ptr %18 to i64
  %20 = icmp eq i64 %19, -1
  br i1 %20, label %21, label %22

21:                                               ; preds = %17, %6
  store ptr @morn_default_color, ptr %11, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %21, %17
  br label %23

23:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %24 = load i32, ptr %12, align 4, !tbaa !9
  %25 = icmp slt i32 %24, -1
  br i1 %25, label %29, label %26

26:                                               ; preds = %23
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = icmp sgt i32 %27, 4
  br label %29

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

34:                                               ; preds = %29
  %35 = load i32, ptr %13, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %35, i32 noundef -1, ptr noundef @.str, i32 noundef 103, ptr noundef @__FUNCTION__.m_ImageDrawLine, ptr noundef @.str.1)
  br label %36

36:                                               ; preds = %34, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %37

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

40:                                               ; preds = %37
  store i32 1, ptr %12, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %40, %37
  %42 = load ptr, ptr %8, align 8, !tbaa !5
  %43 = icmp eq ptr %42, null
  br i1 %43, label %55, label %44

44:                                               ; preds = %41
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = ptrtoint ptr %45 to i64
  %47 = icmp eq i64 %46, -1
  br i1 %47, label %55, label %48

48:                                               ; preds = %44
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = load ptr, ptr %7, align 8, !tbaa !5
  %51 = icmp ne ptr %49, %50
  br i1 %51, label %52, label %55

52:                                               ; preds = %48
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  call void @mImageCopy(ptr noundef %53, ptr noundef %54)
  br label %57

55:                                               ; preds = %48, %44, %41
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %56, ptr %8, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %55, %52
  call void @llvm.lifetime.start.p0(i64 24, ptr %14) #3
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.DrawPara, ptr %14, i32 0, i32 0
  store ptr %58, ptr %59, align 8, !tbaa !11
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.DrawPara, ptr %14, i32 0, i32 1
  store ptr %60, ptr %61, align 8, !tbaa !13
  %62 = load i32, ptr %12, align 4, !tbaa !9
  %63 = getelementptr inbounds %struct.DrawPara, ptr %14, i32 0, i32 2
  store i32 %62, ptr %63, align 8, !tbaa !14
  %64 = load ptr, ptr %9, align 8, !tbaa !5
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  call void @mLineTravel(ptr noundef %64, ptr noundef %65, i32 noundef 1, ptr noundef @PointDraw, ptr noundef %14)
  call void @llvm.lifetime.end.p0(i64 24, ptr %14) #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, !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_ImageDrawLine = 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

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

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

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

10:                                               ; preds = %6
  tail call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef 1, i32 noundef -1, ptr noundef nonnull @.str, i32 noundef 103, ptr noundef nonnull @__FUNCTION__.m_ImageDrawLine, ptr noundef nonnull @.str.1) #4
  br label %11

11:                                               ; preds = %10, %6
  %magicptr = ptrtoint ptr %1 to i64
  switch i64 %magicptr, label %12 [
    i64 -1, label %14
    i64 0, label %14
  ]

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

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

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

; 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