; LLVM IR from BrunoLevy/learn-fpga :: FemtoRV/FIRMWARE/CPP_EXAMPLES (tinyrt_cpp)

; 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.vec = type { float, float, float }

@GL_height = external global i16, align 2
@GL_width = external global i16, align 2

; 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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3vecILm3EfEC2Efff(ptr noundef nonnull align 4 dereferenceable(12), float noundef, float noundef, float noundef) unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZN3vecILm3EfE9normalizeEf(ptr noundef nonnull align 4 dereferenceable(12), float noundef) #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { <2 x float>, float } @_Z8cast_rayRK3vecILm3EfES2_RKSt6vectorI6SphereSaIS4_EERKS3_I5LightSaIS9_EEm(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9set_pixeliifff(i32 noundef, i32 noundef, float noundef, float noundef, float noundef) #4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6renderRKSt6vectorI6SphereSaIS0_EERKS_I5LightSaIS5_EE(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) #3 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca float, align 4
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca %struct.vec, align 4
  %13 = alloca %struct.vec, align 4
  %14 = alloca %struct.vec, align 4
  %15 = alloca { <2 x float>, float }, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store float 0x3FF0C15240000000, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  store i64 0, ptr %6, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %78, %2
  %17 = load i64, ptr %6, align 8, !tbaa !11
  %18 = load i16, ptr @GL_height, align 2, !tbaa !13
  %19 = zext i16 %18 to i64
  %20 = icmp ult i64 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %81

22:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %23

23:                                               ; preds = %74, %22
  %24 = load i64, ptr %8, align 8, !tbaa !11
  %25 = load i16, ptr @GL_width, align 2, !tbaa !13
  %26 = zext i16 %25 to i64
  %27 = icmp ult i64 %24, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %23
  store i32 5, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %77

29:                                               ; preds = %23
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %30 = load i64, ptr %8, align 8, !tbaa !11
  %31 = uitofp i64 %30 to double
  %32 = fadd double %31, 5.000000e-01
  %33 = load i16, ptr @GL_width, align 2, !tbaa !13
  %34 = zext i16 %33 to i32
  %35 = sitofp i32 %34 to double
  %36 = fdiv double %35, 2.000000e+00
  %37 = fsub double %32, %36
  %38 = fptrunc double %37 to float
  store float %38, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %39 = load i64, ptr %6, align 8, !tbaa !11
  %40 = uitofp i64 %39 to double
  %41 = fadd double %40, 5.000000e-01
  %42 = fneg double %41
  %43 = load i16, ptr @GL_height, align 2, !tbaa !13
  %44 = zext i16 %43 to i32
  %45 = sitofp i32 %44 to double
  %46 = fdiv double %45, 2.000000e+00
  %47 = fadd double %42, %46
  %48 = fptrunc double %47 to float
  store float %48, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  %49 = load i16, ptr @GL_height, align 2, !tbaa !13
  %50 = zext i16 %49 to i32
  %51 = sub nsw i32 0, %50
  %52 = sitofp i32 %51 to double
  %53 = call double @tan(double noundef 0x3FE0C15240000000) #6
  %54 = fmul double 2.000000e+00, %53
  %55 = fdiv double %52, %54
  %56 = fptrunc double %55 to float
  store float %56, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 12, ptr %12) #6
  call void @llvm.lifetime.start.p0(i64 12, ptr %13) #6
  call void @_ZN3vecILm3EfEC2Efff(ptr noundef nonnull align 4 dereferenceable(12) %13, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00)
  call void @llvm.lifetime.start.p0(i64 12, ptr %14) #6
  %57 = load float, ptr %9, align 4, !tbaa !9
  %58 = load float, ptr %10, align 4, !tbaa !9
  %59 = load float, ptr %11, align 4, !tbaa !9
  call void @_ZN3vecILm3EfEC2Efff(ptr noundef nonnull align 4 dereferenceable(12) %14, float noundef %57, float noundef %58, float noundef %59)
  %60 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZN3vecILm3EfE9normalizeEf(ptr noundef nonnull align 4 dereferenceable(12) %14, float noundef 1.000000e+00)
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = call { <2 x float>, float } @_Z8cast_rayRK3vecILm3EfES2_RKSt6vectorI6SphereSaIS4_EERKS3_I5LightSaIS9_EEm(ptr noundef nonnull align 4 dereferenceable(12) %13, ptr noundef nonnull align 4 dereferenceable(12) %60, ptr noundef nonnull align 8 dereferenceable(24) %61, ptr noundef nonnull align 8 dereferenceable(24) %62, i64 noundef 0)
  store { <2 x float>, float } %63, ptr %15, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %12, ptr align 8 %15, i64 12, i1 false)
  call void @llvm.lifetime.end.p0(i64 12, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 12, ptr %13) #6
  %64 = load i64, ptr %8, align 8, !tbaa !11
  %65 = trunc i64 %64 to i32
  %66 = load i64, ptr %6, align 8, !tbaa !11
  %67 = trunc i64 %66 to i32
  %68 = getelementptr inbounds %struct.vec, ptr %12, i32 0, i32 0
  %69 = load float, ptr %68, align 4, !tbaa !15
  %70 = getelementptr inbounds %struct.vec, ptr %12, i32 0, i32 1
  %71 = load float, ptr %70, align 4, !tbaa !17
  %72 = getelementptr inbounds %struct.vec, ptr %12, i32 0, i32 2
  %73 = load float, ptr %72, align 4, !tbaa !18
  call void @_Z9set_pixeliifff(i32 noundef %65, i32 noundef %67, float noundef %69, float noundef %71, float noundef %73)
  call void @llvm.lifetime.end.p0(i64 12, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %74

74:                                               ; preds = %29
  %75 = load i64, ptr %8, align 8, !tbaa !11
  %76 = add i64 %75, 1
  store i64 %76, ptr %8, align 8, !tbaa !11
  br label %23, !llvm.loop !19

77:                                               ; preds = %28
  br label %78

78:                                               ; preds = %77
  %79 = load i64, ptr %6, align 8, !tbaa !11
  %80 = add i64 %79, 1
  store i64 %80, ptr %6, align 8, !tbaa !11
  br label %16, !llvm.loop !21

81:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  ret void
}

; Function Attrs: nounwind
declare double @tan(double noundef) #5

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress 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 #3 = { mustprogress uwtable "min-legal-vector-width"="64" "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 "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 #6 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !10, i64 0}
!16 = !{!"_ZTS3vecILm3EfE", !10, i64 0, !10, i64 4, !10, i64 8}
!17 = !{!16, !10, i64 4}
!18 = !{!16, !10, i64 8}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = distinct !{!21, !20}


; 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.vec = type { float, float, float }

@GL_height = external local_unnamed_addr global i16, align 2
@GL_width = external local_unnamed_addr global i16, align 2

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN3vecILm3EfEC2Efff(ptr noundef nonnull align 4 dereferenceable(12), float noundef, float noundef, float noundef) unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZN3vecILm3EfE9normalizeEf(ptr noundef nonnull align 4 dereferenceable(12), float noundef) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { <2 x float>, float } @_Z8cast_rayRK3vecILm3EfES2_RKSt6vectorI6SphereSaIS4_EERKS3_I5LightSaIS9_EEm(ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 4 dereferenceable(12), ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z9set_pixeliifff(i32 noundef, i32 noundef, float noundef, float noundef, float noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6renderRKSt6vectorI6SphereSaIS0_EERKS_I5LightSaIS5_EE(ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1) local_unnamed_addr #2 {
  %3 = alloca %struct.vec, align 4
  %4 = alloca %struct.vec, align 4
  %5 = load i16, ptr @GL_height, align 2, !tbaa !5
  %.not = icmp eq i16 %5, 0
  br i1 %.not, label %._crit_edge16, label %.preheader.preheader

.preheader.preheader:                             ; preds = %2
  %.pre = load i16, ptr @GL_width, align 2, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %6 = phi i16 [ %11, %._crit_edge ], [ %5, %.preheader.preheader ]
  %7 = phi i16 [ %12, %._crit_edge ], [ %.pre, %.preheader.preheader ]
  %.015 = phi i64 [ %13, %._crit_edge ], [ 0, %.preheader.preheader ]
  %.not17 = icmp eq i16 %7, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %8 = uitofp nneg i64 %.015 to double
  %9 = fadd double %8, 5.000000e-01
  %10 = trunc nuw nsw i64 %.015 to i32
  br label %16

._crit_edge16:                                    ; preds = %._crit_edge, %2
  ret void

._crit_edge.loopexit:                             ; preds = %16
  %.pre18 = load i16, ptr @GL_height, align 2, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %11 = phi i16 [ %.pre18, %._crit_edge.loopexit ], [ %6, %.preheader ]
  %12 = phi i16 [ %38, %._crit_edge.loopexit ], [ 0, %.preheader ]
  %13 = add nuw nsw i64 %.015, 1
  %14 = zext i16 %11 to i64
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %.preheader, label %._crit_edge16, !llvm.loop !9

16:                                               ; preds = %.lr.ph, %16
  %17 = phi i16 [ %7, %.lr.ph ], [ %38, %16 ]
  %.01314 = phi i64 [ 0, %.lr.ph ], [ %37, %16 ]
  %18 = uitofp nneg i64 %.01314 to double
  %19 = fadd double %18, 5.000000e-01
  %20 = uitofp i16 %17 to double
  %21 = fmul double %20, 5.000000e-01
  %22 = fsub double %19, %21
  %23 = fptrunc double %22 to float
  %24 = load i16, ptr @GL_height, align 2, !tbaa !5
  %25 = zext i16 %24 to i32
  %26 = uitofp i16 %24 to double
  %27 = fmul double %26, 5.000000e-01
  %28 = fsub double %27, %9
  %29 = fptrunc double %28 to float
  %30 = sub nsw i32 0, %25
  %31 = sitofp i32 %30 to double
  %32 = fdiv double %31, 0x3FF279A74FFE43EC
  %33 = fptrunc double %32 to float
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #4
  call void @_ZN3vecILm3EfEC2Efff(ptr noundef nonnull align 4 dereferenceable(12) %3, float noundef 0.000000e+00, float noundef 0.000000e+00, float noundef 0.000000e+00)
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #4
  call void @_ZN3vecILm3EfEC2Efff(ptr noundef nonnull align 4 dereferenceable(12) %4, float noundef %23, float noundef %29, float noundef %33)
  %34 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZN3vecILm3EfE9normalizeEf(ptr noundef nonnull align 4 dereferenceable(12) %4, float noundef 1.000000e+00)
  %35 = call { <2 x float>, float } @_Z8cast_rayRK3vecILm3EfES2_RKSt6vectorI6SphereSaIS4_EERKS3_I5LightSaIS9_EEm(ptr noundef nonnull align 4 dereferenceable(12) %3, ptr noundef nonnull align 4 dereferenceable(12) %34, ptr noundef nonnull align 8 dereferenceable(24) %0, ptr noundef nonnull align 8 dereferenceable(24) %1, i64 noundef 0)
  %.fca.0.extract = extractvalue { <2 x float>, float } %35, 0
  %.fca.1.extract = extractvalue { <2 x float>, float } %35, 1
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #4
  %36 = trunc nuw nsw i64 %.01314 to i32
  %.sroa.01.0.vec.extract = extractelement <2 x float> %.fca.0.extract, i64 0
  %.sroa.01.4.vec.extract = extractelement <2 x float> %.fca.0.extract, i64 1
  call void @_Z9set_pixeliifff(i32 noundef %36, i32 noundef %10, float noundef %.sroa.01.0.vec.extract, float noundef %.sroa.01.4.vec.extract, float noundef %.fca.1.extract)
  %37 = add nuw nsw i64 %.01314, 1
  %38 = load i16, ptr @GL_width, align 2, !tbaa !5
  %39 = zext i16 %38 to i64
  %40 = icmp ult i64 %37, %39
  br i1 %40, label %16, label %._crit_edge.loopexit, !llvm.loop !11
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { mustprogress uwtable "min-legal-vector-width"="64" "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 = { 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 = { 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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass