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

@morn_default_color = external hidden global [4 x i8], align 1
@.str = external hidden unnamed_addr constant [83 x i8], align 1
@__FUNCTION__.m_ImageDrawPoint = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @m_ImageDrawPoint(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) #0 {
  %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
  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
  %12 = load ptr, ptr %9, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %18, label %14

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

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

19:                                               ; preds = %18, %14
  br label %20

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

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

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

31:                                               ; preds = %26
  %32 = load i32, ptr %11, align 4, !tbaa !9
  call void (i32, i32, ptr, i32, ptr, ptr, ...) @m_Exception(i32 noundef %32, i32 noundef -1, ptr noundef @.str, i32 noundef 63, ptr noundef @__FUNCTION__.m_ImageDrawPoint, ptr noundef @.str.1)
  br label %33

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

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

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

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

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

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

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

52:                                               ; preds = %45, %41, %38
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %53, ptr %7, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %52, %49
  %55 = load i32, ptr %10, align 4, !tbaa !9
  %56 = icmp eq i32 %55, 1
  br i1 %56, label %57, label %61

57:                                               ; preds = %54
  %58 = load ptr, ptr %7, align 8, !tbaa !5
  %59 = load ptr, ptr %8, align 8, !tbaa !5
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  call void @ImageDrawPoint1(ptr noundef %58, ptr noundef %59, ptr noundef %60)
  br label %85

61:                                               ; preds = %54
  %62 = load i32, ptr %10, align 4, !tbaa !9
  %63 = icmp eq i32 %62, 2
  br i1 %63, label %64, label %68

64:                                               ; preds = %61
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = load ptr, ptr %9, align 8, !tbaa !5
  call void @ImageDrawPoint2(ptr noundef %65, ptr noundef %66, ptr noundef %67)
  br label %84

68:                                               ; preds = %61
  %69 = load i32, ptr %10, align 4, !tbaa !9
  %70 = icmp eq i32 %69, 3
  br i1 %70, label %71, label %75

71:                                               ; preds = %68
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = load ptr, ptr %8, align 8, !tbaa !5
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  call void @ImageDrawPoint3(ptr noundef %72, ptr noundef %73, ptr noundef %74)
  br label %83

75:                                               ; preds = %68
  %76 = load i32, ptr %10, align 4, !tbaa !9
  %77 = icmp eq i32 %76, 4
  br i1 %77, label %78, label %82

78:                                               ; preds = %75
  %79 = load ptr, ptr %7, align 8, !tbaa !5
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = load ptr, ptr %9, align 8, !tbaa !5
  call void @ImageDrawPoint4(ptr noundef %79, ptr noundef %80, ptr noundef %81)
  br label %82

82:                                               ; preds = %78, %75
  br label %83

83:                                               ; preds = %82, %71
  br label %84

84:                                               ; preds = %83, %64
  br label %85

85:                                               ; preds = %84, %57
  ret void
}

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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}


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

@morn_default_color = external hidden global [4 x i8], align 1
@.str = external hidden unnamed_addr constant [83 x i8], align 1
@__FUNCTION__.m_ImageDrawPoint = external hidden unnamed_addr constant [17 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [14 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @ImageDrawPoint1(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @ImageDrawPoint2(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @ImageDrawPoint3(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @ImageDrawPoint4(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @m_ImageDrawPoint(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq ptr %3, null
  %7 = icmp eq ptr %3, inttoptr (i64 -1 to ptr)
  %or.cond = or i1 %6, %7
  %spec.store.select = select i1 %or.cond, ptr @morn_default_color, ptr %3
  %8 = add i32 %4, -5
  %9 = icmp ult i32 %8, -6
  br i1 %9, label %10, label %11

10:                                               ; 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 63, ptr noundef nonnull @__FUNCTION__.m_ImageDrawPoint, ptr noundef nonnull @.str.1) #2
  br label %11

11:                                               ; preds = %10, %5
  %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) #2
  br label %14

14:                                               ; preds = %12, %11, %11, %13
  %.0 = phi ptr [ %1, %13 ], [ %0, %11 ], [ %0, %11 ], [ %0, %12 ]
  %15 = icmp slt i32 %4, 2
  br i1 %15, label %16, label %17

16:                                               ; preds = %14
  tail call void @ImageDrawPoint1(ptr noundef %.0, ptr noundef %2, ptr noundef %spec.store.select)
  br label %21

17:                                               ; preds = %14
  switch i32 %4, label %21 [
    i32 2, label %18
    i32 3, label %19
    i32 4, label %20
  ]

18:                                               ; preds = %17
  tail call void @ImageDrawPoint2(ptr noundef %.0, ptr noundef %2, ptr noundef %spec.store.select)
  br label %21

19:                                               ; preds = %17
  tail call void @ImageDrawPoint3(ptr noundef %.0, ptr noundef %2, ptr noundef %spec.store.select)
  br label %21

20:                                               ; preds = %17
  tail call void @ImageDrawPoint4(ptr noundef %.0, ptr noundef %2, ptr noundef %spec.store.select)
  br label %21

21:                                               ; preds = %17, %18, %20, %19, %16
  ret void
}

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

attributes #0 = { 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 #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 }

!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)"}


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