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

; 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
@numCellsX = external dso_local global i32, align 4
@numCellsY = external dso_local global i32, align 4
@windowWidth = external dso_local global i32, align 4
@windowHeight = external dso_local global i32, 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: nounwind uwtable
define dso_local void @centerCellsOnScreen() #1 {
  %1 = alloca float, align 4
  %2 = alloca float, align 4
  store float 1.000000e+00, ptr @scale, align 4, !tbaa !5
  store float 1.000000e+00, ptr @scaleX, align 4, !tbaa !5
  store float 1.000000e+00, ptr @scaleY, align 4, !tbaa !5
  store float 0.000000e+00, ptr @offsetX, align 4, !tbaa !5
  store float 0.000000e+00, ptr @offsetY, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %3 = load i32, ptr @windowWidth, align 4, !tbaa !9
  %4 = sitofp i32 %3 to float
  %5 = load i32, ptr @windowHeight, align 4, !tbaa !9
  %6 = sitofp i32 %5 to float
  %7 = fdiv float %4, %6
  store float %7, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %8 = load i32, ptr @numCellsX, align 4, !tbaa !9
  %9 = sitofp i32 %8 to float
  %10 = load i32, ptr @numCellsY, align 4, !tbaa !9
  %11 = sitofp i32 %10 to float
  %12 = fdiv float %9, %11
  store float %12, ptr %2, align 4, !tbaa !5
  %13 = load float, ptr %2, align 4, !tbaa !5
  %14 = load float, ptr %1, align 4, !tbaa !5
  %15 = fcmp ogt float %13, %14
  br i1 %15, label %16, label %28

16:                                               ; preds = %0
  %17 = load float, ptr @scaleX, align 4, !tbaa !5
  %18 = load i32, ptr @numCellsX, align 4, !tbaa !9
  %19 = sitofp i32 %18 to float
  %20 = fmul float %17, %19
  %21 = load float, ptr %1, align 4, !tbaa !5
  %22 = load i32, ptr @numCellsY, align 4, !tbaa !9
  %23 = sitofp i32 %22 to float
  %24 = fmul float %21, %23
  %25 = fdiv float %20, %24
  store float %25, ptr @scaleY, align 4, !tbaa !5
  %26 = load float, ptr @scaleY, align 4, !tbaa !5
  %27 = call float @llvm.fmuladd.f32(float -5.000000e-01, float %26, float 5.000000e-01)
  store float %27, ptr @offsetY, align 4, !tbaa !5
  br label %45

28:                                               ; preds = %0
  %29 = load float, ptr %2, align 4, !tbaa !5
  %30 = load float, ptr %1, align 4, !tbaa !5
  %31 = fcmp olt float %29, %30
  br i1 %31, label %32, label %44

32:                                               ; preds = %28
  %33 = load float, ptr %1, align 4, !tbaa !5
  %34 = load float, ptr @scaleY, align 4, !tbaa !5
  %35 = fmul float %33, %34
  %36 = load i32, ptr @numCellsY, align 4, !tbaa !9
  %37 = sitofp i32 %36 to float
  %38 = fmul float %35, %37
  %39 = load i32, ptr @numCellsX, align 4, !tbaa !9
  %40 = sitofp i32 %39 to float
  %41 = fdiv float %38, %40
  store float %41, ptr @scaleX, align 4, !tbaa !5
  %42 = load float, ptr @scaleX, align 4, !tbaa !5
  %43 = call float @llvm.fmuladd.f32(float -5.000000e-01, float %42, float 5.000000e-01)
  store float %43, ptr @offsetX, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %32, %28
  br label %45

45:                                               ; preds = %44, %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

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

@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
@numCellsX = external dso_local local_unnamed_addr global i32, align 4
@numCellsY = 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

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none) uwtable
define dso_local void @centerCellsOnScreen() local_unnamed_addr #0 {
  store float 1.000000e+00, ptr @scale, align 4, !tbaa !5
  store float 1.000000e+00, ptr @scaleX, align 4, !tbaa !5
  store float 1.000000e+00, ptr @scaleY, align 4, !tbaa !5
  store float 0.000000e+00, ptr @offsetX, align 4, !tbaa !5
  store float 0.000000e+00, ptr @offsetY, align 4, !tbaa !5
  %1 = load i32, ptr @windowWidth, align 4, !tbaa !9
  %2 = load i32, ptr @windowHeight, align 4, !tbaa !9
  %3 = load i32, ptr @numCellsX, align 4, !tbaa !9
  %4 = load i32, ptr @numCellsY, align 4, !tbaa !9
  %5 = insertelement <2 x i32> poison, i32 %3, i64 0
  %6 = insertelement <2 x i32> %5, i32 %1, i64 1
  %7 = sitofp <2 x i32> %6 to <2 x float>
  %8 = insertelement <2 x i32> poison, i32 %4, i64 0
  %9 = insertelement <2 x i32> %8, i32 %2, i64 1
  %10 = sitofp <2 x i32> %9 to <2 x float>
  %11 = fdiv <2 x float> %7, %10
  %12 = extractelement <2 x float> %11, i64 0
  %13 = extractelement <2 x float> %11, i64 1
  %14 = fcmp ogt float %12, %13
  br i1 %14, label %15, label %20

15:                                               ; preds = %0
  %16 = extractelement <2 x float> %10, i64 0
  %17 = fmul float %13, %16
  %18 = extractelement <2 x float> %7, i64 0
  %19 = fdiv float %18, %17
  store float %19, ptr @scaleY, align 4, !tbaa !5
  br label %.sink.split

20:                                               ; preds = %0
  %21 = fcmp olt float %12, %13
  br i1 %21, label %22, label %28

22:                                               ; preds = %20
  %23 = extractelement <2 x float> %10, i64 0
  %24 = fmul float %13, %23
  %25 = extractelement <2 x float> %7, i64 0
  %26 = fdiv float %24, %25
  store float %26, ptr @scaleX, align 4, !tbaa !5
  br label %.sink.split

.sink.split:                                      ; preds = %15, %22
  %.sink7 = phi float [ %26, %22 ], [ %19, %15 ]
  %offsetX.sink = phi ptr [ @offsetX, %22 ], [ @offsetY, %15 ]
  %27 = tail call float @llvm.fmuladd.f32(float %.sink7, float -5.000000e-01, float 5.000000e-01)
  store float %27, ptr %offsetX.sink, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %.sink.split, %20
  ret void
}

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

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none) 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


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