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

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

@pressedButton = external dso_local global i32, align 4
@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
@glad_glBindTexture = external global ptr, align 8
@glad_glBindFramebuffer = external global ptr, align 8
@numCellsX = external dso_local global i32, align 4
@numCellsY = external dso_local global i32, align 4
@cellsRead = external dso_local global i32, align 4
@cellsReadFramebuffer = 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
@glad_glReadPixels = external global ptr, align 8
@glad_glTexSubImage2D = external global ptr, 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 @onMouseButton(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i8, align 1
  %14 = 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
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %17, label %19

17:                                               ; preds = %4
  %18 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %18, ptr @pressedButton, align 4, !tbaa !9
  br label %29

19:                                               ; preds = %4
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %28

22:                                               ; preds = %19
  %23 = load i32, ptr %6, align 4, !tbaa !9
  %24 = load i32, ptr @pressedButton, align 4, !tbaa !9
  %25 = icmp eq i32 %23, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %22
  store i32 -1, ptr @pressedButton, align 4, !tbaa !9
  br label %27

27:                                               ; preds = %26, %22
  br label %118

28:                                               ; preds = %19
  br label %29

29:                                               ; preds = %28, %17
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %29
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 1
  br i1 %34, label %39, label %35

35:                                               ; preds = %32, %29
  %36 = call zeroext i8 @keyModsArePressed()
  %37 = zext i8 %36 to i32
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %35, %32
  br label %118

40:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  %41 = load double, ptr @mouseX, align 8, !tbaa !11
  %42 = load i32, ptr @windowWidth, align 4, !tbaa !9
  %43 = sitofp i32 %42 to double
  %44 = fdiv double %41, %43
  %45 = fptrunc double %44 to float
  store float %45, ptr %9, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %46 = load double, ptr @mouseY, align 8, !tbaa !11
  %47 = load i32, ptr @windowHeight, align 4, !tbaa !9
  %48 = sitofp i32 %47 to double
  %49 = fdiv double %46, %48
  %50 = fptrunc double %49 to float
  store float %50, ptr %10, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %51 = load i32, ptr @numCellsX, align 4, !tbaa !9
  %52 = sitofp i32 %51 to float
  %53 = load float, ptr @offsetX, align 4, !tbaa !13
  %54 = load float, ptr %9, align 4, !tbaa !13
  %55 = load float, ptr @scaleX, align 4, !tbaa !13
  %56 = fmul float %54, %55
  %57 = load float, ptr @scale, align 4, !tbaa !13
  %58 = call float @llvm.fmuladd.f32(float %56, float %57, float %53)
  %59 = fmul float %52, %58
  %60 = fptosi float %59 to i32
  store i32 %60, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  %61 = load i32, ptr @numCellsY, align 4, !tbaa !9
  %62 = sitofp i32 %61 to float
  %63 = load float, ptr @offsetY, align 4, !tbaa !13
  %64 = load float, ptr %10, align 4, !tbaa !13
  %65 = load float, ptr @scaleY, align 4, !tbaa !13
  %66 = fmul float %64, %65
  %67 = load float, ptr @scale, align 4, !tbaa !13
  %68 = call float @llvm.fmuladd.f32(float %66, float %67, float %63)
  %69 = fmul float %62, %68
  %70 = fptosi float %69 to i32
  store i32 %70, ptr %12, align 4, !tbaa !9
  %71 = load i32, ptr %11, align 4, !tbaa !9
  %72 = icmp sge i32 %71, 0
  br i1 %72, label %73, label %117

73:                                               ; preds = %40
  %74 = load i32, ptr %11, align 4, !tbaa !9
  %75 = load i32, ptr @numCellsX, align 4, !tbaa !9
  %76 = icmp slt i32 %74, %75
  br i1 %76, label %77, label %117

77:                                               ; preds = %73
  %78 = load i32, ptr %12, align 4, !tbaa !9
  %79 = icmp sge i32 %78, 0
  br i1 %79, label %80, label %117

80:                                               ; preds = %77
  %81 = load i32, ptr %12, align 4, !tbaa !9
  %82 = load i32, ptr @numCellsY, align 4, !tbaa !9
  %83 = icmp slt i32 %81, %82
  br i1 %83, label %84, label %117

84:                                               ; preds = %80
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #3
  store i8 0, ptr %13, align 1, !tbaa !15
  %85 = load i32, ptr %6, align 4, !tbaa !9
  %86 = icmp eq i32 %85, 0
  br i1 %86, label %87, label %88

87:                                               ; preds = %84
  store i8 -1, ptr %13, align 1, !tbaa !15
  br label %88

88:                                               ; preds = %87, %84
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #3
  %89 = load ptr, ptr @glad_glBindFramebuffer, align 8, !tbaa !5
  %90 = load i32, ptr @cellsReadFramebuffer, align 4, !tbaa !9
  call void %89(i32 noundef 36160, i32 noundef %90)
  %91 = load ptr, ptr @glad_glReadPixels, align 8, !tbaa !5
  %92 = load i32, ptr %11, align 4, !tbaa !9
  %93 = load i32, ptr %12, align 4, !tbaa !9
  %94 = sdiv i32 %93, 32
  call void %91(i32 noundef %92, i32 noundef %94, i32 noundef 1, i32 noundef 1, i32 noundef 36244, i32 noundef 5125, ptr noundef %14)
  %95 = load i8, ptr %13, align 1, !tbaa !15
  %96 = icmp ne i8 %95, 0
  br i1 %96, label %97, label %103

97:                                               ; preds = %88
  %98 = load i32, ptr %12, align 4, !tbaa !9
  %99 = and i32 %98, 31
  %100 = shl i32 1, %99
  %101 = load i32, ptr %14, align 4, !tbaa !9
  %102 = or i32 %101, %100
  store i32 %102, ptr %14, align 4, !tbaa !9
  br label %110

103:                                              ; preds = %88
  %104 = load i32, ptr %12, align 4, !tbaa !9
  %105 = and i32 %104, 31
  %106 = shl i32 1, %105
  %107 = xor i32 %106, -1
  %108 = load i32, ptr %14, align 4, !tbaa !9
  %109 = and i32 %108, %107
  store i32 %109, ptr %14, align 4, !tbaa !9
  br label %110

110:                                              ; preds = %103, %97
  %111 = load ptr, ptr @glad_glBindTexture, align 8, !tbaa !5
  %112 = load i32, ptr @cellsRead, align 4, !tbaa !9
  call void %111(i32 noundef 3553, i32 noundef %112)
  %113 = load ptr, ptr @glad_glTexSubImage2D, align 8, !tbaa !5
  %114 = load i32, ptr %11, align 4, !tbaa !9
  %115 = load i32, ptr %12, align 4, !tbaa !9
  %116 = sdiv i32 %115, 32
  call void %113(i32 noundef 3553, i32 noundef 0, i32 noundef %114, i32 noundef %116, i32 noundef 1, i32 noundef 1, i32 noundef 36244, i32 noundef 5125, ptr noundef %14)
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #3
  br label %117

117:                                              ; preds = %110, %80, %77, %73, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  br label %118

118:                                              ; preds = %117, %39, %27
  ret void
}

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

@pressedButton = external dso_local local_unnamed_addr global i32, align 4
@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
@glad_glBindTexture = external local_unnamed_addr global ptr, align 8
@glad_glBindFramebuffer = external local_unnamed_addr global ptr, align 8
@numCellsX = external dso_local local_unnamed_addr global i32, align 4
@numCellsY = external dso_local local_unnamed_addr global i32, align 4
@cellsRead = external dso_local local_unnamed_addr global i32, align 4
@cellsReadFramebuffer = 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
@glad_glReadPixels = external local_unnamed_addr global ptr, align 8
@glad_glTexSubImage2D = external local_unnamed_addr global ptr, align 8

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

; Function Attrs: nounwind uwtable
define dso_local void @onMouseButton(ptr nocapture noundef readnone %0, i32 noundef %1, i32 noundef %2, i32 noundef %3) local_unnamed_addr #1 {
  %5 = alloca i32, align 4
  switch i32 %2, label %11 [
    i32 1, label %6
    i32 0, label %7
  ]

6:                                                ; preds = %4
  store i32 %1, ptr @pressedButton, align 4, !tbaa !5
  br label %11

7:                                                ; preds = %4
  %8 = load i32, ptr @pressedButton, align 4, !tbaa !5
  %9 = icmp eq i32 %8, %1
  br i1 %9, label %10, label %73

10:                                               ; preds = %7
  store i32 -1, ptr @pressedButton, align 4, !tbaa !5
  br label %73

11:                                               ; preds = %4, %6
  %or.cond = icmp ugt i32 %1, 1
  br i1 %or.cond, label %73, label %12

12:                                               ; preds = %11
  %13 = tail call zeroext i8 @keyModsArePressed()
  %.not = icmp eq i8 %13, 0
  br i1 %.not, label %14, label %73

14:                                               ; preds = %12
  %15 = load double, ptr @mouseX, align 8, !tbaa !9
  %16 = load i32, ptr @windowWidth, align 4, !tbaa !5
  %17 = load double, ptr @mouseY, align 8, !tbaa !9
  %18 = load i32, ptr @windowHeight, align 4, !tbaa !5
  %19 = load i32, ptr @numCellsX, align 4, !tbaa !5
  %20 = load float, ptr @offsetX, align 4, !tbaa !11
  %21 = load float, ptr @scaleX, align 4, !tbaa !11
  %22 = load float, ptr @scale, align 4, !tbaa !11
  %23 = load i32, ptr @numCellsY, align 4, !tbaa !5
  %24 = load float, ptr @offsetY, align 4, !tbaa !11
  %25 = load float, ptr @scaleY, align 4, !tbaa !11
  %26 = insertelement <2 x i32> poison, i32 %18, i64 0
  %27 = insertelement <2 x i32> %26, i32 %16, i64 1
  %28 = sitofp <2 x i32> %27 to <2 x double>
  %29 = insertelement <2 x double> poison, double %17, i64 0
  %30 = insertelement <2 x double> %29, double %15, i64 1
  %31 = fdiv <2 x double> %30, %28
  %32 = fptrunc <2 x double> %31 to <2 x float>
  %33 = insertelement <2 x i32> poison, i32 %23, i64 0
  %34 = insertelement <2 x i32> %33, i32 %19, i64 1
  %35 = sitofp <2 x i32> %34 to <2 x float>
  %36 = insertelement <2 x float> poison, float %25, i64 0
  %37 = insertelement <2 x float> %36, float %21, i64 1
  %38 = fmul <2 x float> %37, %32
  %39 = insertelement <2 x float> poison, float %22, i64 0
  %40 = shufflevector <2 x float> %39, <2 x float> poison, <2 x i32> zeroinitializer
  %41 = insertelement <2 x float> poison, float %24, i64 0
  %42 = insertelement <2 x float> %41, float %20, i64 1
  %43 = tail call <2 x float> @llvm.fmuladd.v2f32(<2 x float> %38, <2 x float> %40, <2 x float> %42)
  %44 = fmul <2 x float> %43, %35
  %45 = fptosi <2 x float> %44 to <2 x i32>
  %46 = extractelement <2 x i32> %45, i64 1
  %47 = icmp sgt i32 %46, -1
  br i1 %47, label %48, label %73

48:                                               ; preds = %14
  %49 = icmp sgt <2 x i32> %34, %45
  %50 = extractelement <2 x i32> %45, i64 0
  %51 = icmp sgt i32 %50, -1
  %52 = extractelement <2 x i1> %49, i64 1
  %or.cond3 = select i1 %52, i1 %51, i1 false
  %53 = extractelement <2 x i1> %49, i64 0
  %or.cond24 = select i1 %or.cond3, i1 %53, i1 false
  br i1 %or.cond24, label %54, label %73

54:                                               ; preds = %48
  %55 = icmp eq i32 %1, 0
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #3
  %56 = load ptr, ptr @glad_glBindFramebuffer, align 8, !tbaa !13
  %57 = load i32, ptr @cellsReadFramebuffer, align 4, !tbaa !5
  tail call void %56(i32 noundef 36160, i32 noundef %57) #3
  %58 = load ptr, ptr @glad_glReadPixels, align 8, !tbaa !13
  %59 = lshr i32 %50, 5
  call void %58(i32 noundef %46, i32 noundef %59, i32 noundef 1, i32 noundef 1, i32 noundef 36244, i32 noundef 5125, ptr noundef nonnull %5) #3
  %60 = and i32 %50, 31
  %61 = shl nuw i32 1, %60
  br i1 %55, label %62, label %65

62:                                               ; preds = %54
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = or i32 %63, %61
  br label %69

65:                                               ; preds = %54
  %66 = xor i32 %61, -1
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = and i32 %67, %66
  br label %69

69:                                               ; preds = %65, %62
  %storemerge = phi i32 [ %68, %65 ], [ %64, %62 ]
  store i32 %storemerge, ptr %5, align 4, !tbaa !5
  %70 = load ptr, ptr @glad_glBindTexture, align 8, !tbaa !13
  %71 = load i32, ptr @cellsRead, align 4, !tbaa !5
  call void %70(i32 noundef 3553, i32 noundef %71) #3
  %72 = load ptr, ptr @glad_glTexSubImage2D, align 8, !tbaa !13
  call void %72(i32 noundef 3553, i32 noundef 0, i32 noundef %46, i32 noundef %59, i32 noundef 1, i32 noundef 1, i32 noundef 36244, i32 noundef 5125, ptr noundef nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  br label %73

73:                                               ; preds = %14, %48, %69, %12, %11, %7, %10
  ret void
}

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

attributes #0 = { mustprogress 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 = !{!"int", !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 = !{!"float", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}


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