; LLVM IR from achilles288/robot-monitor-graphics :: src/base/camera.ll (ZN3rmg6Camera18setMaximumDistanceEf)

; 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.rmg::Mat4" = type { %union.anon }
%union.anon = type { [4 x [4 x float]] }
%"class.rmg::Camera" = type { %"struct.rmg::Vec3", %"struct.rmg::Mat3", %"struct.rmg::Mat4", %"struct.rmg::Mat4", %"struct.rmg::Mat4", float, float, float, float, float, i32 }
%"struct.rmg::Vec3" = type { %union.anon.0 }
%union.anon.0 = type { %struct.anon }
%struct.anon = type { float, float, float }
%"struct.rmg::Mat3" = type { %union.anon.1 }
%union.anon.1 = type { [3 x [3 x float]] }

; 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) #0

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

declare void @_ZNK3rmg4Mat4mlERKS0_(ptr dead_on_unwind writable sret(%"struct.rmg::Mat4") align 4, ptr noundef nonnull align 4 dereferenceable(64), ptr noundef nonnull align 4 dereferenceable(64)) #2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(16) ptr @_ZN3rmg4Mat4ixEh(ptr noundef nonnull align 4 dereferenceable(64), i8 noundef zeroext) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg7Mat4RowixEh(ptr noundef nonnull align 4 dereferenceable(16), i8 noundef zeroext) #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg6Camera18setMaximumDistanceEf(ptr noundef nonnull align 4 dereferenceable(264) %0, float noundef %1) #4 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca float, align 4
  %5 = alloca %"struct.rmg::Mat4", align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !9
  %6 = load ptr, ptr %3, align 8
  %7 = load float, ptr %4, align 4, !tbaa !9
  %8 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 9
  store float %7, ptr %8, align 4, !tbaa !11
  %9 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 10
  %10 = load i32, ptr %9, align 4, !tbaa !17
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %12, label %40

12:                                               ; preds = %2
  %13 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 9
  %14 = load float, ptr %13, align 4, !tbaa !11
  %15 = fneg float %14
  %16 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 9
  %17 = load float, ptr %16, align 4, !tbaa !11
  %18 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 8
  %19 = load float, ptr %18, align 4, !tbaa !18
  %20 = fsub float %17, %19
  %21 = fdiv float %15, %20
  %22 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 3
  %23 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZN3rmg4Mat4ixEh(ptr noundef nonnull align 4 dereferenceable(64) %22, i8 noundef zeroext 2)
  %24 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg7Mat4RowixEh(ptr noundef nonnull align 4 dereferenceable(16) %23, i8 noundef zeroext 2)
  store float %21, ptr %24, align 4, !tbaa !9
  %25 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 8
  %26 = load float, ptr %25, align 4, !tbaa !18
  %27 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 9
  %28 = load float, ptr %27, align 4, !tbaa !11
  %29 = fmul float %26, %28
  %30 = fneg float %29
  %31 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 9
  %32 = load float, ptr %31, align 4, !tbaa !11
  %33 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 8
  %34 = load float, ptr %33, align 4, !tbaa !18
  %35 = fsub float %32, %34
  %36 = fdiv float %30, %35
  %37 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 3
  %38 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZN3rmg4Mat4ixEh(ptr noundef nonnull align 4 dereferenceable(64) %37, i8 noundef zeroext 2)
  %39 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg7Mat4RowixEh(ptr noundef nonnull align 4 dereferenceable(16) %38, i8 noundef zeroext 3)
  store float %36, ptr %39, align 4, !tbaa !9
  br label %62

40:                                               ; preds = %2
  %41 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 9
  %42 = load float, ptr %41, align 4, !tbaa !11
  %43 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 8
  %44 = load float, ptr %43, align 4, !tbaa !18
  %45 = fsub float %42, %44
  %46 = fdiv float -1.000000e+00, %45
  %47 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 3
  %48 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZN3rmg4Mat4ixEh(ptr noundef nonnull align 4 dereferenceable(64) %47, i8 noundef zeroext 2)
  %49 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg7Mat4RowixEh(ptr noundef nonnull align 4 dereferenceable(16) %48, i8 noundef zeroext 2)
  store float %46, ptr %49, align 4, !tbaa !9
  %50 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 8
  %51 = load float, ptr %50, align 4, !tbaa !18
  %52 = fneg float %51
  %53 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 9
  %54 = load float, ptr %53, align 4, !tbaa !11
  %55 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 8
  %56 = load float, ptr %55, align 4, !tbaa !18
  %57 = fsub float %54, %56
  %58 = fdiv float %52, %57
  %59 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 3
  %60 = call noundef nonnull align 4 dereferenceable(16) ptr @_ZN3rmg4Mat4ixEh(ptr noundef nonnull align 4 dereferenceable(64) %59, i8 noundef zeroext 2)
  %61 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg7Mat4RowixEh(ptr noundef nonnull align 4 dereferenceable(16) %60, i8 noundef zeroext 3)
  store float %58, ptr %61, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %40, %12
  call void @llvm.lifetime.start.p0(i64 64, ptr %5) #5
  %63 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 3
  %64 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 2
  call void @_ZNK3rmg4Mat4mlERKS0_(ptr dead_on_unwind writable sret(%"struct.rmg::Mat4") align 4 %5, ptr noundef nonnull align 4 dereferenceable(64) %63, ptr noundef nonnull align 4 dereferenceable(64) %64)
  %65 = getelementptr inbounds %"class.rmg::Camera", ptr %6, i32 0, i32 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %65, ptr align 4 %5, i64 64, i1 false), !tbaa.struct !19
  call void @llvm.lifetime.end.p0(i64 64, ptr %5) #5
  ret void
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint mustprogress 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 #4 = { mustprogress 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 #5 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = !{!12, !10, i64 256}
!12 = !{!"_ZTSN3rmg6CameraE", !13, i64 0, !14, i64 12, !15, i64 48, !15, i64 112, !15, i64 176, !10, i64 240, !10, i64 244, !10, i64 248, !10, i64 252, !10, i64 256, !16, i64 260}
!13 = !{!"_ZTSN3rmg4Vec3E", !7, i64 0}
!14 = !{!"_ZTSN3rmg4Mat3E", !7, i64 0}
!15 = !{!"_ZTSN3rmg4Mat4E", !7, i64 0}
!16 = !{!"_ZTSN3rmg14ProjectionModeE", !7, i64 0}
!17 = !{!12, !16, i64 260}
!18 = !{!12, !10, i64 252}
!19 = !{i64 0, i64 64, !20}
!20 = !{!7, !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"

%"struct.rmg::Mat4" = type { %union.anon }
%union.anon = type { [4 x [4 x float]] }

; 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) #0

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

declare void @_ZNK3rmg4Mat4mlERKS0_(ptr dead_on_unwind writable sret(%"struct.rmg::Mat4") align 4, ptr noundef nonnull align 4 dereferenceable(64), ptr noundef nonnull align 4 dereferenceable(64)) local_unnamed_addr #2

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(16) ptr @_ZN3rmg4Mat4ixEh(ptr noundef nonnull align 4 dereferenceable(64), i8 noundef zeroext) local_unnamed_addr #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg7Mat4RowixEh(ptr noundef nonnull align 4 dereferenceable(16), i8 noundef zeroext) local_unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN3rmg6Camera18setMaximumDistanceEf(ptr noundef nonnull align 4 dereferenceable(264) %0, float noundef %1) local_unnamed_addr #4 align 2 {
  %3 = alloca %"struct.rmg::Mat4", align 4
  %4 = getelementptr inbounds i8, ptr %0, i64 256
  store float %1, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 260
  %6 = load i32, ptr %5, align 4, !tbaa !14
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %8, label %23

8:                                                ; preds = %2
  %9 = fneg float %1
  %10 = getelementptr inbounds i8, ptr %0, i64 252
  %11 = load float, ptr %10, align 4, !tbaa !15
  %12 = fsub float %1, %11
  %13 = fdiv float %9, %12
  %14 = getelementptr inbounds i8, ptr %0, i64 112
  %15 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZN3rmg4Mat4ixEh(ptr noundef nonnull align 4 dereferenceable(64) %14, i8 noundef zeroext 2)
  %16 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg7Mat4RowixEh(ptr noundef nonnull align 4 dereferenceable(16) %15, i8 noundef zeroext 2)
  store float %13, ptr %16, align 4, !tbaa !16
  %17 = load float, ptr %10, align 4, !tbaa !15
  %18 = load float, ptr %4, align 4, !tbaa !5
  %19 = fneg float %17
  %20 = fmul float %18, %19
  %21 = fsub float %18, %17
  %22 = fdiv float %20, %21
  br label %36

23:                                               ; preds = %2
  %24 = getelementptr inbounds i8, ptr %0, i64 252
  %25 = load float, ptr %24, align 4, !tbaa !15
  %26 = fsub float %1, %25
  %27 = fdiv float -1.000000e+00, %26
  %28 = getelementptr inbounds i8, ptr %0, i64 112
  %29 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZN3rmg4Mat4ixEh(ptr noundef nonnull align 4 dereferenceable(64) %28, i8 noundef zeroext 2)
  %30 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg7Mat4RowixEh(ptr noundef nonnull align 4 dereferenceable(16) %29, i8 noundef zeroext 2)
  store float %27, ptr %30, align 4, !tbaa !16
  %31 = load float, ptr %24, align 4, !tbaa !15
  %32 = fneg float %31
  %33 = load float, ptr %4, align 4, !tbaa !5
  %34 = fsub float %33, %31
  %35 = fdiv float %32, %34
  br label %36

36:                                               ; preds = %23, %8
  %.sink4 = phi ptr [ %28, %23 ], [ %14, %8 ]
  %.sink = phi float [ %35, %23 ], [ %22, %8 ]
  %37 = tail call noundef nonnull align 4 dereferenceable(16) ptr @_ZN3rmg4Mat4ixEh(ptr noundef nonnull align 4 dereferenceable(64) %.sink4, i8 noundef zeroext 2)
  %38 = tail call noundef nonnull align 4 dereferenceable(4) ptr @_ZN3rmg7Mat4RowixEh(ptr noundef nonnull align 4 dereferenceable(16) %37, i8 noundef zeroext 3)
  store float %.sink, ptr %38, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %3) #5
  %39 = getelementptr inbounds i8, ptr %0, i64 112
  %40 = getelementptr inbounds i8, ptr %0, i64 48
  call void @_ZNK3rmg4Mat4mlERKS0_(ptr dead_on_unwind nonnull writable sret(%"struct.rmg::Mat4") align 4 %3, ptr noundef nonnull align 4 dereferenceable(64) %39, ptr noundef nonnull align 4 dereferenceable(64) %40)
  %41 = getelementptr inbounds i8, ptr %0, i64 176
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(64) %41, ptr noundef nonnull align 4 dereferenceable(64) %3, i64 64, i1 false), !tbaa.struct !17
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %3) #5
  ret void
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { inlinehint mustprogress 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 #4 = { mustprogress 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 #5 = { 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, !12, i64 256}
!6 = !{!"_ZTSN3rmg6CameraE", !7, i64 0, !10, i64 12, !11, i64 48, !11, i64 112, !11, i64 176, !12, i64 240, !12, i64 244, !12, i64 248, !12, i64 252, !12, i64 256, !13, i64 260}
!7 = !{!"_ZTSN3rmg4Vec3E", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSN3rmg4Mat3E", !8, i64 0}
!11 = !{!"_ZTSN3rmg4Mat4E", !8, i64 0}
!12 = !{!"float", !8, i64 0}
!13 = !{!"_ZTSN3rmg14ProjectionModeE", !8, i64 0}
!14 = !{!6, !13, i64 260}
!15 = !{!6, !12, i64 252}
!16 = !{!12, !12, i64 0}
!17 = !{i64 0, i64 64, !18}
!18 = !{!8, !8, i64 0}


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