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

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

16:                                               ; preds = %6
  br label %59

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

59:                                               ; preds = %17, %16
  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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"_ZTS6GfxCmd", !7, i64 0, !7, i64 1, !7, i64 2, !6, i64 4, !7, i64 8}
!13 = !{!12, !7, i64 1}
!14 = !{!12, !6, i64 4}
!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"

%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 @_Z17AddGfxCmdTriangleiiiiij(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = load i32, ptr @_ZL17g_gfxCmdQueueSize, align 4, !tbaa !5
  %8 = icmp ugt i32 %7, 4999
  br i1 %8, label %24, label %9

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

24:                                               ; preds = %6, %9
  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