; LLVM IR from blat-blatnik/Painted-Portal-Ray-Tracing :: src/game.ll (Z16gameOnMouseWheelP10GLFWwindowdd)

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

@_ZL8gameMode = external hidden global i32, align 4
@_ZL8material = external hidden global i32, align 4
@_ZL15cameraFoveaDist = external hidden global float, align 4

; 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: mustprogress uwtable
declare hidden void @_ZL19printPickedMaterialv() #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z16gameOnMouseWheelP10GLFWwindowdd(ptr noundef %0, double noundef %1, double noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca double, align 8
  %7 = alloca float, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  store double %2, ptr %6, align 8, !tbaa !9
  %8 = load i32, ptr @_ZL8gameMode, align 4, !tbaa !11
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %10, label %25

10:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  store float 0x3FF19999A0000000, ptr %7, align 4, !tbaa !13
  %11 = load double, ptr %6, align 8, !tbaa !9
  %12 = fcmp ogt double %11, 0.000000e+00
  br i1 %12, label %13, label %17

13:                                               ; preds = %10
  %14 = load float, ptr %7, align 4, !tbaa !13
  %15 = load float, ptr @_ZL15cameraFoveaDist, align 4, !tbaa !13
  %16 = fmul float %15, %14
  store float %16, ptr @_ZL15cameraFoveaDist, align 4, !tbaa !13
  br label %17

17:                                               ; preds = %13, %10
  %18 = load double, ptr %6, align 8, !tbaa !9
  %19 = fcmp olt double %18, 0.000000e+00
  br i1 %19, label %20, label %24

20:                                               ; preds = %17
  %21 = load float, ptr %7, align 4, !tbaa !13
  %22 = load float, ptr @_ZL15cameraFoveaDist, align 4, !tbaa !13
  %23 = fdiv float %22, %21
  store float %23, ptr @_ZL15cameraFoveaDist, align 4, !tbaa !13
  br label %24

24:                                               ; preds = %20, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %50

25:                                               ; preds = %3
  %26 = load i32, ptr @_ZL8gameMode, align 4, !tbaa !11
  %27 = icmp eq i32 %26, 1
  br i1 %27, label %28, label %49

28:                                               ; preds = %25
  %29 = load double, ptr %6, align 8, !tbaa !9
  %30 = fcmp ogt double %29, 0.000000e+00
  br i1 %30, label %31, label %34

31:                                               ; preds = %28
  %32 = load i32, ptr @_ZL8material, align 4, !tbaa !15
  %33 = add i32 %32, 1
  store i32 %33, ptr @_ZL8material, align 4, !tbaa !15
  br label %34

34:                                               ; preds = %31, %28
  %35 = load double, ptr %6, align 8, !tbaa !9
  %36 = fcmp olt double %35, 0.000000e+00
  br i1 %36, label %37, label %40

37:                                               ; preds = %34
  %38 = load i32, ptr @_ZL8material, align 4, !tbaa !15
  %39 = add i32 %38, -1
  store i32 %39, ptr @_ZL8material, align 4, !tbaa !15
  br label %40

40:                                               ; preds = %37, %34
  %41 = load i32, ptr @_ZL8material, align 4, !tbaa !15
  %42 = icmp ult i32 %41, 1
  br i1 %42, label %43, label %44

43:                                               ; preds = %40
  store i32 1, ptr @_ZL8material, align 4, !tbaa !15
  br label %44

44:                                               ; preds = %43, %40
  %45 = load i32, ptr @_ZL8material, align 4, !tbaa !15
  %46 = icmp ugt i32 %45, 10
  br i1 %46, label %47, label %48

47:                                               ; preds = %44
  store i32 10, ptr @_ZL8material, align 4, !tbaa !15
  br label %48

48:                                               ; preds = %47, %44
  call void @_ZL19printPickedMaterialv()
  br label %49

49:                                               ; preds = %48, %25
  br label %50

50:                                               ; preds = %49, %24
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTS8GameMode", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!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"

@_ZL8gameMode = external hidden local_unnamed_addr global i32, align 4
@_ZL8material = external hidden local_unnamed_addr global i32, align 4
@_ZL15cameraFoveaDist = external hidden local_unnamed_addr global float, align 4

; Function Attrs: mustprogress uwtable
declare hidden void @_ZL19printPickedMaterialv() local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z16gameOnMouseWheelP10GLFWwindowdd(ptr nocapture noundef readnone %0, double noundef %1, double noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @_ZL8gameMode, align 4, !tbaa !5
  switch i32 %4, label %29 [
    i32 0, label %5
    i32 1, label %15
  ]

5:                                                ; preds = %3
  %6 = fcmp ogt double %2, 0.000000e+00
  br i1 %6, label %7, label %10

7:                                                ; preds = %5
  %8 = load float, ptr @_ZL15cameraFoveaDist, align 4, !tbaa !9
  %9 = fmul float %8, 0x3FF19999A0000000
  store float %9, ptr @_ZL15cameraFoveaDist, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %7, %5
  %11 = fcmp olt double %2, 0.000000e+00
  br i1 %11, label %12, label %29

12:                                               ; preds = %10
  %13 = load float, ptr @_ZL15cameraFoveaDist, align 4, !tbaa !9
  %14 = fdiv float %13, 0x3FF19999A0000000
  store float %14, ptr @_ZL15cameraFoveaDist, align 4, !tbaa !9
  br label %29

15:                                               ; preds = %3
  %16 = fcmp ogt double %2, 0.000000e+00
  br i1 %16, label %17, label %20

17:                                               ; preds = %15
  %18 = load i32, ptr @_ZL8material, align 4, !tbaa !11
  %19 = add i32 %18, 1
  store i32 %19, ptr @_ZL8material, align 4, !tbaa !11
  br label %20

20:                                               ; preds = %17, %15
  %21 = fcmp olt double %2, 0.000000e+00
  %22 = load i32, ptr @_ZL8material, align 4, !tbaa !11
  br i1 %21, label %23, label %thread-pre-split

23:                                               ; preds = %20
  %24 = add i32 %22, -1
  store i32 %24, ptr @_ZL8material, align 4, !tbaa !11
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %20, %23
  %.pr7 = phi i32 [ %24, %23 ], [ %22, %20 ]
  %25 = icmp eq i32 %.pr7, 0
  br i1 %25, label %.sink.split, label %26

26:                                               ; preds = %thread-pre-split
  %27 = icmp ugt i32 %.pr7, 10
  br i1 %27, label %.sink.split, label %28

.sink.split:                                      ; preds = %26, %thread-pre-split
  %.sink = phi i32 [ 1, %thread-pre-split ], [ 10, %26 ]
  store i32 %.sink, ptr @_ZL8material, align 4, !tbaa !11
  br label %28

28:                                               ; preds = %.sink.split, %26
  tail call void @_ZL19printPickedMaterialv()
  br label %29

29:                                               ; preds = %3, %10, %12, %28
  ret void
}

attributes #0 = { 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" }

!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 = !{!"_ZTS8GameMode", !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 = !{!"int", !7, i64 0}


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