; LLVM IR from blat-blatnik/GPU-Life :: main (onMouseWheel)

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

@scale = external dso_local global float, align 4
@scaleX = external dso_local global float, align 4
@scaleY = external dso_local global float, align 4
@offsetX = external dso_local global float, align 4
@offsetY = external dso_local global float, align 4
@updatesPerFrame = external dso_local global i32, align 4
@framesPerUpdate = external dso_local global i32, align 4
@windowWidth = external dso_local global i32, align 4
@windowHeight = external dso_local global i32, align 4
@mouseX = external dso_local global double, align 8
@mouseY = external dso_local global double, align 8

; 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
declare dso_local zeroext i8 @keyModsArePressed() #1

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

; Function Attrs: nounwind uwtable
define dso_local void @onMouseWheel(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
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = 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
  %11 = call zeroext i8 @keyModsArePressed()
  %12 = icmp ne i8 %11, 0
  br i1 %12, label %13, label %65

13:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %14 = load double, ptr @mouseX, align 8, !tbaa !9
  %15 = load i32, ptr @windowWidth, align 4, !tbaa !11
  %16 = sitofp i32 %15 to double
  %17 = fdiv double %14, %16
  %18 = fptrunc double %17 to float
  store float %18, ptr %7, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %19 = load double, ptr @mouseY, align 8, !tbaa !9
  %20 = load i32, ptr @windowHeight, align 4, !tbaa !11
  %21 = sitofp i32 %20 to double
  %22 = fdiv double %19, %21
  %23 = fptrunc double %22 to float
  store float %23, ptr %8, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %24 = load float, ptr @offsetX, align 4, !tbaa !13
  %25 = load float, ptr %7, align 4, !tbaa !13
  %26 = load float, ptr @scaleX, align 4, !tbaa !13
  %27 = fmul float %25, %26
  %28 = load float, ptr @scale, align 4, !tbaa !13
  %29 = call float @llvm.fmuladd.f32(float %27, float %28, float %24)
  store float %29, ptr %9, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %30 = load float, ptr @offsetY, align 4, !tbaa !13
  %31 = load float, ptr %8, align 4, !tbaa !13
  %32 = load float, ptr @scaleY, align 4, !tbaa !13
  %33 = fmul float %31, %32
  %34 = load float, ptr @scale, align 4, !tbaa !13
  %35 = call float @llvm.fmuladd.f32(float %33, float %34, float %30)
  store float %35, ptr %10, align 4, !tbaa !13
  %36 = load double, ptr %6, align 8, !tbaa !9
  %37 = fcmp ogt double %36, 0.000000e+00
  br i1 %37, label %38, label %42

38:                                               ; preds = %13
  %39 = load float, ptr @scale, align 4, !tbaa !13
  %40 = fdiv float %39, 0x3FF19999A0000000
  %41 = call float @llvm.maxnum.f32(float %40, float 0x3F1A36E2E0000000)
  store float %41, ptr @scale, align 4, !tbaa !13
  br label %50

42:                                               ; preds = %13
  %43 = load double, ptr %6, align 8, !tbaa !9
  %44 = fcmp olt double %43, 0.000000e+00
  br i1 %44, label %45, label %49

45:                                               ; preds = %42
  %46 = load float, ptr @scale, align 4, !tbaa !13
  %47 = fmul float %46, 0x3FF19999A0000000
  %48 = call float @llvm.minnum.f32(float %47, float 1.000000e+01)
  store float %48, ptr @scale, align 4, !tbaa !13
  br label %49

49:                                               ; preds = %45, %42
  br label %50

50:                                               ; preds = %49, %38
  %51 = load float, ptr %9, align 4, !tbaa !13
  %52 = load float, ptr %7, align 4, !tbaa !13
  %53 = load float, ptr @scaleX, align 4, !tbaa !13
  %54 = fmul float %52, %53
  %55 = load float, ptr @scale, align 4, !tbaa !13
  %56 = fneg float %54
  %57 = call float @llvm.fmuladd.f32(float %56, float %55, float %51)
  store float %57, ptr @offsetX, align 4, !tbaa !13
  %58 = load float, ptr %10, align 4, !tbaa !13
  %59 = load float, ptr %8, align 4, !tbaa !13
  %60 = load float, ptr @scaleY, align 4, !tbaa !13
  %61 = fmul float %59, %60
  %62 = load float, ptr @scale, align 4, !tbaa !13
  %63 = fneg float %61
  %64 = call float @llvm.fmuladd.f32(float %63, float %62, float %58)
  store float %64, ptr @offsetY, align 4, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %93

65:                                               ; preds = %3
  %66 = load double, ptr %6, align 8, !tbaa !9
  %67 = fcmp ogt double %66, 0.000000e+00
  br i1 %67, label %68, label %78

68:                                               ; preds = %65
  %69 = load i32, ptr @framesPerUpdate, align 4, !tbaa !11
  %70 = icmp sgt i32 %69, 1
  br i1 %70, label %71, label %74

71:                                               ; preds = %68
  %72 = load i32, ptr @framesPerUpdate, align 4, !tbaa !11
  %73 = sdiv i32 %72, 2
  store i32 %73, ptr @framesPerUpdate, align 4, !tbaa !11
  br label %77

74:                                               ; preds = %68
  %75 = load i32, ptr @updatesPerFrame, align 4, !tbaa !11
  %76 = mul nsw i32 %75, 2
  store i32 %76, ptr @updatesPerFrame, align 4, !tbaa !11
  br label %77

77:                                               ; preds = %74, %71
  br label %92

78:                                               ; preds = %65
  %79 = load double, ptr %6, align 8, !tbaa !9
  %80 = fcmp olt double %79, 0.000000e+00
  br i1 %80, label %81, label %91

81:                                               ; preds = %78
  %82 = load i32, ptr @updatesPerFrame, align 4, !tbaa !11
  %83 = icmp sgt i32 %82, 1
  br i1 %83, label %84, label %87

84:                                               ; preds = %81
  %85 = load i32, ptr @updatesPerFrame, align 4, !tbaa !11
  %86 = sdiv i32 %85, 2
  store i32 %86, ptr @updatesPerFrame, align 4, !tbaa !11
  br label %90

87:                                               ; preds = %81
  %88 = load i32, ptr @framesPerUpdate, align 4, !tbaa !11
  %89 = mul nsw i32 %88, 2
  store i32 %89, ptr @framesPerUpdate, align 4, !tbaa !11
  br label %90

90:                                               ; preds = %87, %84
  br label %91

91:                                               ; preds = %90, %78
  br label %92

92:                                               ; preds = %91, %77
  br label %93

93:                                               ; preds = %92, %50
  ret void
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.minnum.f32(float, float) #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 nosync nounwind speculatable willreturn memory(none) }
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 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !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"

@scale = external dso_local local_unnamed_addr global float, align 4
@scaleX = external dso_local local_unnamed_addr global float, align 4
@scaleY = external dso_local local_unnamed_addr global float, align 4
@offsetX = external dso_local local_unnamed_addr global float, align 4
@offsetY = external dso_local local_unnamed_addr global float, align 4
@updatesPerFrame = external dso_local local_unnamed_addr global i32, align 4
@framesPerUpdate = external dso_local local_unnamed_addr global i32, align 4
@windowWidth = external dso_local local_unnamed_addr global i32, align 4
@windowHeight = external dso_local local_unnamed_addr global i32, align 4
@mouseX = external dso_local local_unnamed_addr global double, align 8
@mouseY = external dso_local local_unnamed_addr global double, align 8

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @keyModsArePressed() local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local void @onMouseWheel(ptr nocapture noundef readnone %0, double noundef %1, double noundef %2) local_unnamed_addr #0 {
  %4 = tail call zeroext i8 @keyModsArePressed()
  %.not = icmp eq i8 %4, 0
  br i1 %.not, label %42, label %5

5:                                                ; preds = %3
  %6 = load double, ptr @mouseX, align 8, !tbaa !5
  %7 = load i32, ptr @windowWidth, align 4, !tbaa !9
  %8 = sitofp i32 %7 to double
  %9 = fdiv double %6, %8
  %10 = fptrunc double %9 to float
  %11 = load double, ptr @mouseY, align 8, !tbaa !5
  %12 = load i32, ptr @windowHeight, align 4, !tbaa !9
  %13 = sitofp i32 %12 to double
  %14 = fdiv double %11, %13
  %15 = fptrunc double %14 to float
  %16 = load float, ptr @offsetX, align 4, !tbaa !11
  %17 = load float, ptr @scaleX, align 4, !tbaa !11
  %18 = fmul float %17, %10
  %19 = load float, ptr @scale, align 4, !tbaa !11
  %20 = tail call float @llvm.fmuladd.f32(float %18, float %19, float %16)
  %21 = load float, ptr @offsetY, align 4, !tbaa !11
  %22 = load float, ptr @scaleY, align 4, !tbaa !11
  %23 = fmul float %22, %15
  %24 = tail call float @llvm.fmuladd.f32(float %23, float %19, float %21)
  %25 = fcmp ogt double %2, 0.000000e+00
  br i1 %25, label %26, label %29

26:                                               ; preds = %5
  %27 = fdiv float %19, 0x3FF19999A0000000
  %28 = tail call float @llvm.maxnum.f32(float %27, float 0x3F1A36E2E0000000)
  br label %.sink.split

29:                                               ; preds = %5
  %30 = fcmp olt double %2, 0.000000e+00
  br i1 %30, label %31, label %34

31:                                               ; preds = %29
  %32 = fmul float %19, 0x3FF19999A0000000
  %33 = tail call float @llvm.minnum.f32(float %32, float 1.000000e+01)
  br label %.sink.split

.sink.split:                                      ; preds = %26, %31
  %.sink = phi float [ %33, %31 ], [ %28, %26 ]
  store float %.sink, ptr @scale, align 4, !tbaa !11
  br label %34

34:                                               ; preds = %.sink.split, %29
  %35 = phi float [ %19, %29 ], [ %.sink, %.sink.split ]
  %36 = fneg float %17
  %37 = fmul float %10, %36
  %38 = tail call float @llvm.fmuladd.f32(float %37, float %35, float %20)
  store float %38, ptr @offsetX, align 4, !tbaa !11
  %39 = fneg float %22
  %40 = fmul float %15, %39
  %41 = tail call float @llvm.fmuladd.f32(float %40, float %35, float %24)
  store float %41, ptr @offsetY, align 4, !tbaa !11
  br label %62

42:                                               ; preds = %3
  %43 = fcmp ogt double %2, 0.000000e+00
  br i1 %43, label %44, label %52

44:                                               ; preds = %42
  %45 = load i32, ptr @framesPerUpdate, align 4, !tbaa !9
  %46 = icmp sgt i32 %45, 1
  br i1 %46, label %47, label %49

47:                                               ; preds = %44
  %48 = lshr i32 %45, 1
  store i32 %48, ptr @framesPerUpdate, align 4, !tbaa !9
  br label %62

49:                                               ; preds = %44
  %50 = load i32, ptr @updatesPerFrame, align 4, !tbaa !9
  %51 = shl nsw i32 %50, 1
  store i32 %51, ptr @updatesPerFrame, align 4, !tbaa !9
  br label %62

52:                                               ; preds = %42
  %53 = fcmp olt double %2, 0.000000e+00
  br i1 %53, label %54, label %62

54:                                               ; preds = %52
  %55 = load i32, ptr @updatesPerFrame, align 4, !tbaa !9
  %56 = icmp sgt i32 %55, 1
  br i1 %56, label %57, label %59

57:                                               ; preds = %54
  %58 = lshr i32 %55, 1
  store i32 %58, ptr @updatesPerFrame, align 4, !tbaa !9
  br label %62

59:                                               ; preds = %54
  %60 = load i32, ptr @framesPerUpdate, align 4, !tbaa !9
  %61 = shl nsw i32 %60, 1
  store i32 %61, ptr @framesPerUpdate, align 4, !tbaa !9
  br label %62

62:                                               ; preds = %49, %47, %57, %59, %52, %34
  ret void
}

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.minnum.f32(float, float) #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 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 = !{!"double", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !7, i64 0}


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