; LLVM IR from godofecht/GANN-Object-Avoidance :: Box2D/Testbed/Framework/RenderGL3.ll (Z13AddGfxCmdRectffffj)

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

%struct.GfxCmd = type { i8, i8, [2 x i8], i32, %union.anon }
%union.anon = type { %struct.GfxText }
%struct.GfxText = type { float, float, i32, ptr }
%struct.GfxRect = type { i16, i16, i16, i16, i16 }

@_ZL17g_gfxCmdQueueSize = external hidden global i32, align 4
@_ZL13g_gfxCmdQueue = external hidden global [5000 x %struct.GfxCmd], align 16

; 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 nounwind uwtable
define dso_local void @_Z13AddGfxCmdRectffffj(float noundef %0, float noundef %1, float noundef %2, float noundef %3, i32 noundef %4) #1 {
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store float %0, ptr %6, align 4, !tbaa !5
  store float %1, ptr %7, align 4, !tbaa !5
  store float %2, ptr %8, align 4, !tbaa !5
  store float %3, ptr %9, align 4, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !9
  %12 = load i32, ptr @_ZL17g_gfxCmdQueueSize, align 4, !tbaa !9
  %13 = icmp uge i32 %12, 5000
  br i1 %13, label %14, label %15

14:                                               ; preds = %5
  br label %54

15:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  %16 = load i32, ptr @_ZL17g_gfxCmdQueueSize, align 4, !tbaa !9
  %17 = add i32 %16, 1
  store i32 %17, ptr @_ZL17g_gfxCmdQueueSize, align 4, !tbaa !9
  %18 = zext i32 %16 to i64
  %19 = getelementptr inbounds [5000 x %struct.GfxCmd], ptr @_ZL13g_gfxCmdQueue, i64 0, i64 %18
  store ptr %19, ptr %11, align 8, !tbaa !11
  %20 = load ptr, ptr %11, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.GfxCmd, ptr %20, i32 0, i32 0
  store i8 0, ptr %21, align 8, !tbaa !13
  %22 = load ptr, ptr %11, align 8, !tbaa !11
  %23 = getelementptr inbounds %struct.GfxCmd, ptr %22, i32 0, i32 1
  store i8 0, ptr %23, align 1, !tbaa !15
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = load ptr, ptr %11, align 8, !tbaa !11
  %26 = getelementptr inbounds %struct.GfxCmd, ptr %25, i32 0, i32 3
  store i32 %24, ptr %26, align 4, !tbaa !16
  %27 = load float, ptr %6, align 4, !tbaa !5
  %28 = fmul float %27, 8.000000e+00
  %29 = fptosi float %28 to i16
  %30 = load ptr, ptr %11, align 8, !tbaa !11
  %31 = getelementptr inbounds %struct.GfxCmd, ptr %30, i32 0, i32 4
  %32 = getelementptr inbounds %struct.GfxRect, ptr %31, i32 0, i32 0
  store i16 %29, ptr %32, align 8, !tbaa !17
  %33 = load float, ptr %7, align 4, !tbaa !5
  %34 = fmul float %33, 8.000000e+00
  %35 = fptosi float %34 to i16
  %36 = load ptr, ptr %11, align 8, !tbaa !11
  %37 = getelementptr inbounds %struct.GfxCmd, ptr %36, i32 0, i32 4
  %38 = getelementptr inbounds %struct.GfxRect, ptr %37, i32 0, i32 1
  store i16 %35, ptr %38, align 2, !tbaa !17
  %39 = load float, ptr %8, align 4, !tbaa !5
  %40 = fmul float %39, 8.000000e+00
  %41 = fptosi float %40 to i16
  %42 = load ptr, ptr %11, align 8, !tbaa !11
  %43 = getelementptr inbounds %struct.GfxCmd, ptr %42, i32 0, i32 4
  %44 = getelementptr inbounds %struct.GfxRect, ptr %43, i32 0, i32 2
  store i16 %41, ptr %44, align 4, !tbaa !17
  %45 = load float, ptr %9, align 4, !tbaa !5
  %46 = fmul float %45, 8.000000e+00
  %47 = fptosi float %46 to i16
  %48 = load ptr, ptr %11, align 8, !tbaa !11
  %49 = getelementptr inbounds %struct.GfxCmd, ptr %48, i32 0, i32 4
  %50 = getelementptr inbounds %struct.GfxRect, ptr %49, i32 0, i32 3
  store i16 %47, ptr %50, align 2, !tbaa !17
  %51 = load ptr, ptr %11, align 8, !tbaa !11
  %52 = getelementptr inbounds %struct.GfxCmd, ptr %51, i32 0, i32 4
  %53 = getelementptr inbounds %struct.GfxRect, ptr %52, i32 0, i32 4
  store i16 0, ptr %53, align 8, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  br label %54

54:                                               ; preds = %15, %14
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"_ZTS6GfxCmd", !7, i64 0, !7, i64 1, !7, i64 2, !10, i64 4, !7, i64 8}
!15 = !{!14, !7, i64 1}
!16 = !{!14, !10, i64 4}
!17 = !{!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"

%struct.GfxCmd = type { i8, i8, [2 x i8], i32, %union.anon }
%union.anon = type { %struct.GfxText }
%struct.GfxText = type { float, float, i32, ptr }

@_ZL17g_gfxCmdQueueSize = external hidden local_unnamed_addr global i32, align 4
@_ZL13g_gfxCmdQueue = external hidden local_unnamed_addr global [5000 x %struct.GfxCmd], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z13AddGfxCmdRectffffj(float noundef %0, float noundef %1, float noundef %2, float noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = load i32, ptr @_ZL17g_gfxCmdQueueSize, align 4, !tbaa !5
  %7 = icmp ugt i32 %6, 4999
  br i1 %7, label %22, label %8

8:                                                ; preds = %5
  %9 = add nuw nsw i32 %6, 1
  store i32 %9, ptr @_ZL17g_gfxCmdQueueSize, align 4, !tbaa !5
  %10 = zext nneg i32 %6 to i64
  %11 = getelementptr inbounds [5000 x %struct.GfxCmd], ptr @_ZL13g_gfxCmdQueue, i64 0, i64 %10
  store i8 0, ptr %11, align 16, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %11, i64 1
  store i8 0, ptr %12, align 1, !tbaa !11
  %13 = getelementptr inbounds i8, ptr %11, i64 4
  store i32 %4, ptr %13, align 4, !tbaa !12
  %14 = insertelement <4 x float> poison, float %0, i64 0
  %15 = insertelement <4 x float> %14, float %1, i64 1
  %16 = insertelement <4 x float> %15, float %2, i64 2
  %17 = insertelement <4 x float> %16, float %3, i64 3
  %18 = fmul <4 x float> %17, <float 8.000000e+00, float 8.000000e+00, float 8.000000e+00, float 8.000000e+00>
  %19 = getelementptr inbounds i8, ptr %11, i64 8
  %20 = fptosi <4 x float> %18 to <4 x i16>
  store <4 x i16> %20, ptr %19, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %11, i64 16
  store i16 0, ptr %21, align 16, !tbaa !13
  br label %22

22:                                               ; preds = %5, %8
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, 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" }

!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, !7, i64 0}
!10 = !{!"_ZTS6GfxCmd", !7, i64 0, !7, i64 1, !7, i64 2, !6, i64 4, !7, i64 8}
!11 = !{!10, !7, i64 1}
!12 = !{!10, !6, i64 4}
!13 = !{!7, !7, i64 0}


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