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

; 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.MImageMask = type { float, float, float, [100 x float], [100 x float] }

; 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

; Function Attrs: nounwind uwtable
define dso_local i32 @mMaskData(ptr noundef %0, float noundef %1, float noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !9
  store float %2, ptr %7, align 4, !tbaa !9
  %10 = load float, ptr %7, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.MImageMask, ptr %11, i32 0, i32 0
  %13 = load float, ptr %12, align 4, !tbaa !11
  %14 = fcmp olt float %10, %13
  br i1 %14, label %21, label %15

15:                                               ; preds = %3
  %16 = load float, ptr %7, align 4, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.MImageMask, ptr %17, i32 0, i32 1
  %19 = load float, ptr %18, align 4, !tbaa !13
  %20 = fcmp ogt float %16, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %15, %3
  store i32 0, ptr %4, align 4
  br label %55

22:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %23 = load float, ptr %7, align 4, !tbaa !9
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.MImageMask, ptr %24, i32 0, i32 0
  %26 = load float, ptr %25, align 4, !tbaa !11
  %27 = fsub float %23, %26
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.MImageMask, ptr %28, i32 0, i32 2
  %30 = load float, ptr %29, align 4, !tbaa !14
  %31 = fdiv float %27, %30
  %32 = fpext float %31 to double
  %33 = fadd double %32, 5.000000e-01
  %34 = fptosi double %33 to i32
  store i32 %34, ptr %8, align 4, !tbaa !15
  %35 = load float, ptr %6, align 4, !tbaa !9
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.MImageMask, ptr %36, i32 0, i32 3
  %38 = load i32, ptr %8, align 4, !tbaa !15
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100 x float], ptr %37, i64 0, i64 %39
  %41 = load float, ptr %40, align 4, !tbaa !9
  %42 = fcmp olt float %35, %41
  br i1 %42, label %52, label %43

43:                                               ; preds = %22
  %44 = load float, ptr %6, align 4, !tbaa !9
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.MImageMask, ptr %45, i32 0, i32 4
  %47 = load i32, ptr %8, align 4, !tbaa !15
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [100 x float], ptr %46, i64 0, i64 %48
  %50 = load float, ptr %49, align 4, !tbaa !9
  %51 = fcmp ogt float %44, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %43, %22
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %54

53:                                               ; preds = %43
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %54

54:                                               ; preds = %53, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  br label %55

55:                                               ; preds = %54, %21
  %56 = load i32, ptr %4, align 4
  ret i32 %56
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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)"}
!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 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"MImageMask", !10, i64 0, !10, i64 4, !10, i64 8, !7, i64 12, !7, i64 412}
!13 = !{!12, !10, i64 4}
!14 = !{!12, !10, i64 8}
!15 = !{!16, !16, i64 0}
!16 = !{!"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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) uwtable
define dso_local range(i32 0, 2) i32 @mMaskData(ptr nocapture noundef readonly %0, float noundef %1, float noundef %2) local_unnamed_addr #0 {
  %4 = load float, ptr %0, align 4, !tbaa !5
  %5 = fcmp ogt float %4, %2
  br i1 %5, label %29, label %6

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  %8 = load float, ptr %7, align 4, !tbaa !10
  %9 = fcmp olt float %8, %2
  br i1 %9, label %29, label %10

10:                                               ; preds = %6
  %11 = fsub float %2, %4
  %12 = getelementptr inbounds i8, ptr %0, i64 8
  %13 = load float, ptr %12, align 4, !tbaa !11
  %14 = fdiv float %11, %13
  %15 = fpext float %14 to double
  %16 = fadd double %15, 5.000000e-01
  %17 = fptosi double %16 to i32
  %18 = getelementptr inbounds i8, ptr %0, i64 12
  %19 = sext i32 %17 to i64
  %20 = getelementptr inbounds [100 x float], ptr %18, i64 0, i64 %19
  %21 = load float, ptr %20, align 4, !tbaa !12
  %22 = fcmp ogt float %21, %1
  br i1 %22, label %29, label %23

23:                                               ; preds = %10
  %24 = getelementptr inbounds i8, ptr %0, i64 412
  %25 = getelementptr inbounds [100 x float], ptr %24, i64 0, i64 %19
  %26 = load float, ptr %25, align 4, !tbaa !12
  %27 = fcmp olt float %26, %1
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  br label %29

29:                                               ; preds = %28, %23, %10, %3, %6
  %.1 = phi i32 [ 0, %6 ], [ 0, %3 ], [ 1, %28 ], [ 0, %23 ], [ 0, %10 ]
  ret i32 %.1
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: read) 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" }

!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 = !{!"MImageMask", !7, i64 0, !7, i64 4, !7, i64 8, !8, i64 12, !8, i64 412}
!7 = !{!"float", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 8}
!12 = !{!7, !7, i64 0}


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