; LLVM IR from indjev99/Evolving-Snakes :: sources/window_functions.ll (Z19mouseButtonCallbackP10GLFWwindowiii)

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

@pressed = external dso_local global i32, align 4
@mxpos = external dso_local global double, align 8
@mypos = external dso_local global double, align 8
@WINDOWS_WIDTH = external global i32, align 4
@WINDOWS_HEIGHT = external global i32, align 4
@ORIGINAL_WINDOWS_HEIGHT = external constant i32, align 4

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

11:                                               ; preds = %4
  %12 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %12, ptr @pressed, align 4, !tbaa !9
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  call void @glfwGetCursorPos(ptr noundef %13, ptr noundef @mxpos, ptr noundef @mypos)
  %14 = load double, ptr @mxpos, align 8, !tbaa !11
  %15 = load i32, ptr @WINDOWS_WIDTH, align 4, !tbaa !9
  %16 = sitofp i32 %15 to double
  %17 = fneg double %16
  %18 = call double @llvm.fmuladd.f64(double %14, double 2.000000e+00, double %17)
  store double %18, ptr @mxpos, align 8, !tbaa !11
  %19 = load double, ptr @mypos, align 8, !tbaa !11
  %20 = fneg double %19
  %21 = load i32, ptr @WINDOWS_HEIGHT, align 4, !tbaa !9
  %22 = sitofp i32 %21 to double
  %23 = call double @llvm.fmuladd.f64(double %20, double 2.000000e+00, double %22)
  store double %23, ptr @mypos, align 8, !tbaa !11
  %24 = load i32, ptr @ORIGINAL_WINDOWS_HEIGHT, align 4, !tbaa !9
  %25 = sitofp i32 %24 to double
  %26 = load double, ptr @mxpos, align 8, !tbaa !11
  %27 = fdiv double %26, %25
  store double %27, ptr @mxpos, align 8, !tbaa !11
  %28 = load i32, ptr @ORIGINAL_WINDOWS_HEIGHT, align 4, !tbaa !9
  %29 = sitofp i32 %28 to double
  %30 = load double, ptr @mypos, align 8, !tbaa !11
  %31 = fdiv double %30, %29
  store double %31, ptr @mypos, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %11, %4
  ret void
}

declare void @glfwGetCursorPos(ptr noundef, ptr noundef, ptr noundef) #1

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

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

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

@pressed = external dso_local local_unnamed_addr global i32, align 4
@mxpos = external dso_local global double, align 8
@mypos = external dso_local global double, align 8
@WINDOWS_WIDTH = external local_unnamed_addr global i32, align 4
@WINDOWS_HEIGHT = external local_unnamed_addr global i32, align 4
@ORIGINAL_WINDOWS_HEIGHT = external local_unnamed_addr constant i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_Z19mouseButtonCallbackP10GLFWwindowiii(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq i32 %2, 1
  br i1 %5, label %6, label %21

6:                                                ; preds = %4
  store i32 %1, ptr @pressed, align 4, !tbaa !5
  tail call void @glfwGetCursorPos(ptr noundef %0, ptr noundef nonnull @mxpos, ptr noundef nonnull @mypos)
  %7 = load double, ptr @mxpos, align 8, !tbaa !9
  %8 = load i32, ptr @WINDOWS_WIDTH, align 4, !tbaa !5
  %9 = sitofp i32 %8 to double
  %10 = fneg double %9
  %11 = tail call double @llvm.fmuladd.f64(double %7, double 2.000000e+00, double %10)
  %12 = load double, ptr @mypos, align 8, !tbaa !9
  %13 = fneg double %12
  %14 = load i32, ptr @WINDOWS_HEIGHT, align 4, !tbaa !5
  %15 = sitofp i32 %14 to double
  %16 = tail call double @llvm.fmuladd.f64(double %13, double 2.000000e+00, double %15)
  %17 = load i32, ptr @ORIGINAL_WINDOWS_HEIGHT, align 4, !tbaa !5
  %18 = sitofp i32 %17 to double
  %19 = fdiv double %11, %18
  store double %19, ptr @mxpos, align 8, !tbaa !9
  %20 = fdiv double %16, %18
  store double %20, ptr @mypos, align 8, !tbaa !9
  br label %21

21:                                               ; preds = %6, %4
  ret void
}

declare void @glfwGetCursorPos(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #1

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

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" }
attributes #1 = { "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 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}


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