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

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

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

14:                                               ; preds = %5
  br label %44

15:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %16 = load i32, ptr @_ZL17g_gfxCmdQueueSize, align 4, !tbaa !13
  %17 = add i32 %16, 1
  store i32 %17, ptr @_ZL17g_gfxCmdQueueSize, align 4, !tbaa !13
  %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 3, ptr %21, align 8, !tbaa !15
  %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 !17
  %24 = load i32, ptr %10, align 4, !tbaa !13
  %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 !18
  %27 = load float, ptr %6, align 4, !tbaa !5
  %28 = load ptr, ptr %11, align 8, !tbaa !11
  %29 = getelementptr inbounds %struct.GfxCmd, ptr %28, i32 0, i32 4
  %30 = getelementptr inbounds %struct.GfxText, ptr %29, i32 0, i32 0
  store float %27, ptr %30, align 8, !tbaa !19
  %31 = load float, ptr %7, align 4, !tbaa !5
  %32 = load ptr, ptr %11, align 8, !tbaa !11
  %33 = getelementptr inbounds %struct.GfxCmd, ptr %32, i32 0, i32 4
  %34 = getelementptr inbounds %struct.GfxText, ptr %33, i32 0, i32 1
  store float %31, ptr %34, align 4, !tbaa !19
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = load ptr, ptr %11, align 8, !tbaa !11
  %37 = getelementptr inbounds %struct.GfxCmd, ptr %36, i32 0, i32 4
  %38 = getelementptr inbounds %struct.GfxText, ptr %37, i32 0, i32 2
  store i32 %35, ptr %38, align 8, !tbaa !19
  %39 = load ptr, ptr %9, align 8, !tbaa !11
  %40 = call noundef ptr @_ZL9allocTextPKc(ptr noundef %39)
  %41 = load ptr, ptr %11, align 8, !tbaa !11
  %42 = getelementptr inbounds %struct.GfxCmd, ptr %41, i32 0, i32 4
  %43 = getelementptr inbounds %struct.GfxText, ptr %42, i32 0, i32 3
  store ptr %40, ptr %43, align 8, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  br label %44

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL9allocTextPKc(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_ZTS9TextAlign", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !7, i64 0}
!16 = !{!"_ZTS6GfxCmd", !7, i64 0, !7, i64 1, !7, i64 2, !14, i64 4, !7, i64 8}
!17 = !{!16, !7, i64 1}
!18 = !{!16, !14, i64 4}
!19 = !{!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 nounwind uwtable
define dso_local void @_Z13AddGfxCmdTextff9TextAlignPKcj(float noundef %0, float noundef %1, i32 noundef %2, ptr 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 %19, 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 3, 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 = getelementptr inbounds i8, ptr %11, i64 8
  store float %0, ptr %14, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %11, i64 12
  store float %1, ptr %15, align 4, !tbaa !13
  %16 = getelementptr inbounds i8, ptr %11, i64 16
  store i32 %2, ptr %16, align 16, !tbaa !13
  %17 = tail call noundef ptr @_ZL9allocTextPKc(ptr noundef %3)
  %18 = getelementptr inbounds i8, ptr %11, i64 24
  store ptr %17, ptr %18, align 8, !tbaa !13
  br label %19

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL9allocTextPKc(ptr noundef) local_unnamed_addr #0

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

!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,SROAPass,SimplifyCFGPass,TailCallElimPass