; LLVM IR from heroseh/cgm :: cgm (cgm_2d_aabb_vs_ray)

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

%union.CgmVec2 = type { %struct.anon }
%struct.anon = type { float, float }
%struct.anon.2 = type { float, float, float, float }
%struct.CgmRay2d = type { %union.anon, %union.CgmVec2 }
%union.anon = type { %struct.anon.4 }
%struct.anon.4 = type { float, float }

; Function Attrs: nounwind uwtable
declare dso_local float @cgm_min(float noundef, float noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local float @cgm_max(float noundef, float 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.copysign.f32(float, float) #3

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @cgm_2d_aabb_vs_ray(float noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca i8, align 1
  %7 = alloca float, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  %14 = alloca float, align 4
  %15 = alloca float, align 4
  %16 = alloca float, align 4
  %17 = alloca float, align 4
  %18 = alloca float, align 4
  %19 = alloca float, align 4
  %20 = alloca %union.CgmVec2, align 4
  %21 = alloca %union.CgmVec2, align 4
  %22 = alloca i32, align 4
  store float %0, ptr %7, align 4, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %23 = load ptr, ptr %8, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.anon.2, ptr %23, i32 0, i32 0
  %25 = load float, ptr %24, align 4, !tbaa !11
  %26 = load ptr, ptr %9, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.CgmRay2d, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds %struct.anon, ptr %27, i32 0, i32 0
  %29 = load float, ptr %28, align 4, !tbaa !11
  %30 = fsub float %25, %29
  %31 = load ptr, ptr %9, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.CgmRay2d, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds %struct.anon, ptr %32, i32 0, i32 0
  %34 = load float, ptr %33, align 4, !tbaa !11
  %35 = fdiv float %30, %34
  store float %35, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %36 = load ptr, ptr %8, align 8, !tbaa !9
  %37 = getelementptr inbounds %struct.anon.2, ptr %36, i32 0, i32 2
  %38 = load float, ptr %37, align 4, !tbaa !11
  %39 = load ptr, ptr %9, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.CgmRay2d, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds %struct.anon, ptr %40, i32 0, i32 0
  %42 = load float, ptr %41, align 4, !tbaa !11
  %43 = fsub float %38, %42
  %44 = load ptr, ptr %9, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.CgmRay2d, ptr %44, i32 0, i32 1
  %46 = getelementptr inbounds %struct.anon, ptr %45, i32 0, i32 0
  %47 = load float, ptr %46, align 4, !tbaa !11
  %48 = fdiv float %43, %47
  store float %48, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %49 = load float, ptr %12, align 4, !tbaa !5
  %50 = load float, ptr %13, align 4, !tbaa !5
  %51 = call float @cgm_min(float noundef %49, float noundef %50)
  store float %51, ptr %14, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %52 = load float, ptr %12, align 4, !tbaa !5
  %53 = load float, ptr %13, align 4, !tbaa !5
  %54 = call float @cgm_max(float noundef %52, float noundef %53)
  store float %54, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  %55 = load ptr, ptr %8, align 8, !tbaa !9
  %56 = getelementptr inbounds %struct.anon.2, ptr %55, i32 0, i32 1
  %57 = load float, ptr %56, align 4, !tbaa !11
  %58 = load ptr, ptr %9, align 8, !tbaa !9
  %59 = getelementptr inbounds %struct.CgmRay2d, ptr %58, i32 0, i32 0
  %60 = getelementptr inbounds %struct.anon, ptr %59, i32 0, i32 1
  %61 = load float, ptr %60, align 4, !tbaa !11
  %62 = fsub float %57, %61
  %63 = load ptr, ptr %9, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.CgmRay2d, ptr %63, i32 0, i32 1
  %65 = getelementptr inbounds %struct.anon, ptr %64, i32 0, i32 1
  %66 = load float, ptr %65, align 4, !tbaa !11
  %67 = fdiv float %62, %66
  store float %67, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %68 = load ptr, ptr %8, align 8, !tbaa !9
  %69 = getelementptr inbounds %struct.anon.2, ptr %68, i32 0, i32 3
  %70 = load float, ptr %69, align 4, !tbaa !11
  %71 = load ptr, ptr %9, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.CgmRay2d, ptr %71, i32 0, i32 0
  %73 = getelementptr inbounds %struct.anon, ptr %72, i32 0, i32 1
  %74 = load float, ptr %73, align 4, !tbaa !11
  %75 = fsub float %70, %74
  %76 = load ptr, ptr %9, align 8, !tbaa !9
  %77 = getelementptr inbounds %struct.CgmRay2d, ptr %76, i32 0, i32 1
  %78 = getelementptr inbounds %struct.anon, ptr %77, i32 0, i32 1
  %79 = load float, ptr %78, align 4, !tbaa !11
  %80 = fdiv float %75, %79
  store float %80, ptr %17, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #4
  %81 = load float, ptr %16, align 4, !tbaa !5
  %82 = load float, ptr %17, align 4, !tbaa !5
  %83 = call float @cgm_min(float noundef %81, float noundef %82)
  store float %83, ptr %18, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #4
  %84 = load float, ptr %14, align 4, !tbaa !5
  %85 = load float, ptr %18, align 4, !tbaa !5
  %86 = call float @cgm_max(float noundef %84, float noundef %85)
  store float %86, ptr %19, align 4, !tbaa !5
  %87 = load float, ptr %15, align 4, !tbaa !5
  %88 = load float, ptr %16, align 4, !tbaa !5
  %89 = load float, ptr %17, align 4, !tbaa !5
  %90 = call float @cgm_max(float noundef %88, float noundef %89)
  %91 = call float @cgm_min(float noundef %87, float noundef %90)
  store float %91, ptr %15, align 4, !tbaa !5
  %92 = load float, ptr %15, align 4, !tbaa !5
  %93 = fcmp ogt float %92, 0.000000e+00
  br i1 %93, label %94, label %129

94:                                               ; preds = %5
  %95 = load float, ptr %15, align 4, !tbaa !5
  %96 = load float, ptr %19, align 4, !tbaa !5
  %97 = fcmp oge float %95, %96
  br i1 %97, label %98, label %129

98:                                               ; preds = %94
  %99 = load float, ptr %19, align 4, !tbaa !5
  %100 = load float, ptr %7, align 4, !tbaa !5
  %101 = fcmp ole float %99, %100
  br i1 %101, label %102, label %129

102:                                              ; preds = %98
  %103 = load float, ptr %14, align 4, !tbaa !5
  %104 = load float, ptr %18, align 4, !tbaa !5
  %105 = fcmp ogt float %103, %104
  br i1 %105, label %106, label %116

106:                                              ; preds = %102
  %107 = load ptr, ptr %10, align 8, !tbaa !9
  %108 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 0
  %109 = load ptr, ptr %9, align 8, !tbaa !9
  %110 = getelementptr inbounds %struct.CgmRay2d, ptr %109, i32 0, i32 1
  %111 = getelementptr inbounds %struct.anon, ptr %110, i32 0, i32 0
  %112 = load float, ptr %111, align 4, !tbaa !11
  %113 = call float @llvm.copysign.f32(float 1.000000e+00, float %112)
  %114 = fneg float %113
  store float %114, ptr %108, align 4, !tbaa !12
  %115 = getelementptr inbounds %struct.anon, ptr %20, i32 0, i32 1
  store float 0.000000e+00, ptr %115, align 4, !tbaa !14
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %107, ptr align 4 %20, i64 8, i1 false), !tbaa.struct !15
  br label %126

116:                                              ; preds = %102
  %117 = load ptr, ptr %10, align 8, !tbaa !9
  %118 = getelementptr inbounds %struct.anon, ptr %21, i32 0, i32 0
  store float 0.000000e+00, ptr %118, align 4, !tbaa !12
  %119 = getelementptr inbounds %struct.anon, ptr %21, i32 0, i32 1
  %120 = load ptr, ptr %9, align 8, !tbaa !9
  %121 = getelementptr inbounds %struct.CgmRay2d, ptr %120, i32 0, i32 1
  %122 = getelementptr inbounds %struct.anon, ptr %121, i32 0, i32 1
  %123 = load float, ptr %122, align 4, !tbaa !11
  %124 = call float @llvm.copysign.f32(float 1.000000e+00, float %123)
  %125 = fneg float %124
  store float %125, ptr %119, align 4, !tbaa !14
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %117, ptr align 4 %21, i64 8, i1 false), !tbaa.struct !15
  br label %126

126:                                              ; preds = %116, %106
  %127 = load float, ptr %19, align 4, !tbaa !5
  %128 = load ptr, ptr %11, align 8, !tbaa !9
  store float %127, ptr %128, align 4, !tbaa !5
  store i8 1, ptr %6, align 1
  store i32 1, ptr %22, align 4
  br label %130

129:                                              ; preds = %98, %94, %5
  store i8 0, ptr %6, align 1
  store i32 1, ptr %22, align 4
  br label %130

130:                                              ; preds = %129, %126
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  %131 = load i8, ptr %6, align 1
  ret i8 %131
}

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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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, !6, i64 0}
!6 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !6, i64 4}
!14 = !{!13, !6, i64 4}
!15 = !{i64 0, i64 8, !11}


; 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
declare dso_local float @cgm_min(float noundef, float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local float @cgm_max(float noundef, float noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.copysign.f32(float, float) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext range(i8 0, 2) i8 @cgm_2d_aabb_vs_ray(float noundef %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #0 {
  %6 = load float, ptr %1, align 4, !tbaa !5
  %7 = load float, ptr %2, align 4, !tbaa !5
  %8 = fsub float %6, %7
  %9 = getelementptr inbounds i8, ptr %2, i64 8
  %10 = load float, ptr %9, align 4, !tbaa !5
  %11 = fdiv float %8, %10
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = load float, ptr %12, align 4, !tbaa !5
  %14 = fsub float %13, %7
  %15 = fdiv float %14, %10
  %16 = tail call float @cgm_min(float noundef %11, float noundef %15)
  %17 = tail call float @cgm_max(float noundef %11, float noundef %15)
  %18 = getelementptr inbounds i8, ptr %1, i64 4
  %19 = load float, ptr %18, align 4, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %2, i64 4
  %21 = load float, ptr %20, align 4, !tbaa !5
  %22 = fsub float %19, %21
  %23 = getelementptr inbounds i8, ptr %2, i64 12
  %24 = load float, ptr %23, align 4, !tbaa !5
  %25 = fdiv float %22, %24
  %26 = getelementptr inbounds i8, ptr %1, i64 12
  %27 = load float, ptr %26, align 4, !tbaa !5
  %28 = fsub float %27, %21
  %29 = fdiv float %28, %24
  %30 = tail call float @cgm_min(float noundef %25, float noundef %29)
  %31 = tail call float @cgm_max(float noundef %16, float noundef %30)
  %32 = tail call float @cgm_max(float noundef %25, float noundef %29)
  %33 = tail call float @cgm_min(float noundef %17, float noundef %32)
  %34 = fcmp ule float %33, 0.000000e+00
  %35 = fcmp ult float %33, %31
  %36 = fcmp ugt float %31, %0
  %37 = or i1 %36, %35
  %or.cond40 = select i1 %34, i1 true, i1 %37
  br i1 %or.cond40, label %50, label %38

38:                                               ; preds = %5
  %39 = fcmp ogt float %16, %30
  br i1 %39, label %40, label %44

40:                                               ; preds = %38
  %41 = load float, ptr %9, align 4, !tbaa !5
  %42 = fneg float %41
  %43 = tail call float @llvm.copysign.f32(float 1.000000e+00, float %42)
  br label %48

44:                                               ; preds = %38
  %45 = load float, ptr %23, align 4, !tbaa !5
  %46 = fneg float %45
  %47 = tail call float @llvm.copysign.f32(float 1.000000e+00, float %46)
  br label %48

48:                                               ; preds = %44, %40
  %.sink41 = phi float [ %43, %40 ], [ 0.000000e+00, %44 ]
  %.sink = phi float [ 0.000000e+00, %40 ], [ %47, %44 ]
  store float %.sink41, ptr %3, align 4
  %49 = getelementptr inbounds i8, ptr %3, i64 4
  store float %.sink, ptr %49, align 4
  store float %31, ptr %4, align 4, !tbaa !8
  br label %50

50:                                               ; preds = %5, %48
  %.0 = phi i8 [ 1, %48 ], [ 0, %5 ]
  ret i8 %.0
}

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 nosync nounwind speculatable willreturn memory(none) }

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


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