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

; 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.MImageCurve = type { %struct.MImagePoint, %struct.MImagePoint, i32, ptr, [16 x float] }
%struct.MImagePoint = type { float, 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 void @mCurve(ptr noundef %0, float noundef %1, float noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) #1 {
  %7 = alloca ptr, align 8
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store float %1, ptr %8, align 4, !tbaa !9
  store float %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !11
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  %14 = load i32, ptr %10, align 4, !tbaa !11
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.MImageCurve, ptr %15, i32 0, i32 2
  store i32 %14, ptr %16, align 8, !tbaa !13
  %17 = load ptr, ptr %11, align 8, !tbaa !5
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.MImageCurve, ptr %18, i32 0, i32 3
  store ptr %17, ptr %19, align 8, !tbaa !16
  %20 = load ptr, ptr %12, align 8, !tbaa !5
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %27

22:                                               ; preds = %6
  %23 = load ptr, ptr %7, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.MImageCurve, ptr %23, i32 0, i32 4
  %25 = getelementptr inbounds [16 x float], ptr %24, i64 0, i64 0
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %25, ptr align 4 %26, i64 64, i1 false)
  br label %27

27:                                               ; preds = %22, %6
  %28 = load float, ptr %9, align 4, !tbaa !9
  %29 = load float, ptr %8, align 4, !tbaa !9
  %30 = fcmp olt float %28, %29
  br i1 %30, label %31, label %37

31:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %32 = load float, ptr %8, align 4, !tbaa !9
  %33 = fptosi float %32 to i32
  store i32 %33, ptr %13, align 4, !tbaa !11
  %34 = load float, ptr %9, align 4, !tbaa !9
  store float %34, ptr %8, align 4, !tbaa !9
  %35 = load i32, ptr %13, align 4, !tbaa !11
  %36 = sitofp i32 %35 to float
  store float %36, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  br label %37

37:                                               ; preds = %31, %27
  %38 = load i32, ptr %10, align 4, !tbaa !11
  %39 = icmp sle i32 %38, 0
  br i1 %39, label %40, label %63

40:                                               ; preds = %37
  %41 = load float, ptr %8, align 4, !tbaa !9
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.MImageCurve, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds %struct.MImagePoint, ptr %43, i32 0, i32 0
  store float %41, ptr %44, align 8, !tbaa !17
  %45 = load ptr, ptr %11, align 8, !tbaa !5
  %46 = load float, ptr %8, align 4, !tbaa !9
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = call float %45(float noundef %46, ptr noundef %47)
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.MImageCurve, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds %struct.MImagePoint, ptr %50, i32 0, i32 1
  store float %48, ptr %51, align 4, !tbaa !18
  %52 = load float, ptr %9, align 4, !tbaa !9
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.MImageCurve, ptr %53, i32 0, i32 1
  %55 = getelementptr inbounds %struct.MImagePoint, ptr %54, i32 0, i32 0
  store float %52, ptr %55, align 8, !tbaa !19
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load float, ptr %9, align 4, !tbaa !9
  %58 = load ptr, ptr %12, align 8, !tbaa !5
  %59 = call float %56(float noundef %57, ptr noundef %58)
  %60 = load ptr, ptr %7, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.MImageCurve, ptr %60, i32 0, i32 1
  %62 = getelementptr inbounds %struct.MImagePoint, ptr %61, i32 0, i32 1
  store float %59, ptr %62, align 4, !tbaa !20
  br label %86

63:                                               ; preds = %37
  %64 = load float, ptr %8, align 4, !tbaa !9
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.MImageCurve, ptr %65, i32 0, i32 0
  %67 = getelementptr inbounds %struct.MImagePoint, ptr %66, i32 0, i32 1
  store float %64, ptr %67, align 4, !tbaa !18
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  %69 = load float, ptr %8, align 4, !tbaa !9
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = call float %68(float noundef %69, ptr noundef %70)
  %72 = load ptr, ptr %7, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.MImageCurve, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds %struct.MImagePoint, ptr %73, i32 0, i32 0
  store float %71, ptr %74, align 8, !tbaa !17
  %75 = load float, ptr %9, align 4, !tbaa !9
  %76 = load ptr, ptr %7, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.MImageCurve, ptr %76, i32 0, i32 1
  %78 = getelementptr inbounds %struct.MImagePoint, ptr %77, i32 0, i32 1
  store float %75, ptr %78, align 4, !tbaa !20
  %79 = load ptr, ptr %11, align 8, !tbaa !5
  %80 = load float, ptr %9, align 4, !tbaa !9
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  %82 = call float %79(float noundef %80, ptr noundef %81)
  %83 = load ptr, ptr %7, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.MImageCurve, ptr %83, i32 0, i32 1
  %85 = getelementptr inbounds %struct.MImagePoint, ptr %84, i32 0, i32 0
  store float %82, ptr %85, align 8, !tbaa !19
  br label %86

86:                                               ; preds = %63, %40
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = !{!"float", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 16}
!14 = !{!"MImageCurve", !15, i64 0, !15, i64 8, !12, i64 16, !6, i64 24, !7, i64 32}
!15 = !{!"MImagePoint", !10, i64 0, !10, i64 4}
!16 = !{!14, !6, i64 24}
!17 = !{!14, !10, i64 0}
!18 = !{!14, !10, i64 4}
!19 = !{!14, !10, i64 8}
!20 = !{!14, !10, i64 12}


; 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: nounwind uwtable
define dso_local void @mCurve(ptr nocapture noundef writeonly %0, float noundef %1, float noundef %2, i32 noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 %3, ptr %7, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %4, ptr %8, align 8, !tbaa !13
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %11, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(64) %10, ptr noundef nonnull align 4 dereferenceable(64) %5, i64 64, i1 false)
  br label %11

11:                                               ; preds = %9, %6
  %12 = fcmp olt float %2, %1
  %13 = fptosi float %1 to i32
  %14 = sitofp i32 %13 to float
  %.036 = select i1 %12, float %14, float %2
  %.0 = select i1 %12, float %2, float %1
  %15 = icmp slt i32 %3, 1
  %16 = getelementptr inbounds i8, ptr %0, i64 8
  br i1 %15, label %17, label %22

17:                                               ; preds = %11
  store float %.0, ptr %0, align 8, !tbaa !14
  %18 = tail call float %4(float noundef %.0, ptr noundef %5) #2
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  store float %18, ptr %19, align 4, !tbaa !15
  store float %.036, ptr %16, align 8, !tbaa !16
  %20 = tail call float %4(float noundef %.036, ptr noundef %5) #2
  %21 = getelementptr inbounds i8, ptr %0, i64 12
  store float %20, ptr %21, align 4, !tbaa !17
  br label %27

22:                                               ; preds = %11
  %23 = getelementptr inbounds i8, ptr %0, i64 4
  store float %.0, ptr %23, align 4, !tbaa !15
  %24 = tail call float %4(float noundef %.0, ptr noundef %5) #2
  store float %24, ptr %0, align 8, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %0, i64 12
  store float %.036, ptr %25, align 4, !tbaa !17
  %26 = tail call float %4(float noundef %.036, ptr noundef %5) #2
  store float %26, ptr %16, align 8, !tbaa !16
  br label %27

27:                                               ; preds = %22, %17
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !11, i64 16}
!6 = !{!"MImageCurve", !7, i64 0, !7, i64 8, !11, i64 16, !12, i64 24, !9, i64 32}
!7 = !{!"MImagePoint", !8, i64 0, !8, i64 4}
!8 = !{!"float", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"any pointer", !9, i64 0}
!13 = !{!6, !12, i64 24}
!14 = !{!6, !8, i64 0}
!15 = !{!6, !8, i64 4}
!16 = !{!6, !8, i64 8}
!17 = !{!6, !8, i64 12}


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