; LLVM IR from BrunoLevy/learn-fpga :: LiteX/software/Doom/mc1-doom/src (g_game)

; 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.player_s = type { ptr, i32, %struct.ticcmd_t, i32, i32, i32, i32, i32, i32, i32, [6 x i32], [6 x i32], i32, [4 x i32], i32, i32, [9 x i32], [4 x i32], [4 x i32], i32, i32, i32, i32, i32, i32, i32, ptr, i32, i32, ptr, i32, i32, i32, [2 x %struct.pspdef_t], i32 }
%struct.ticcmd_t = type { i8, i8, i16, i16, i8, i8 }
%struct.pspdef_t = type { ptr, i32, i32, i32 }

@players = external dso_local global [4 x %struct.player_s], align 16
@maxammo = external global [4 x i32], 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: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local void @G_PlayerReborn(i32 noundef %0) #3 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca [4 x i32], align 16
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %9 = getelementptr inbounds [4 x i32], ptr %5, i64 0, i64 0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [4 x %struct.player_s], ptr @players, i64 0, i64 %11
  %13 = getelementptr inbounds %struct.player_s, ptr %12, i32 0, i32 13
  %14 = getelementptr inbounds [4 x i32], ptr %13, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %9, ptr align 4 %14, i64 16, i1 false)
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [4 x %struct.player_s], ptr @players, i64 0, i64 %16
  %18 = getelementptr inbounds %struct.player_s, ptr %17, i32 0, i32 23
  %19 = load i32, ptr %18, align 16, !tbaa !9
  store i32 %19, ptr %6, align 4, !tbaa !5
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [4 x %struct.player_s], ptr @players, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.player_s, ptr %22, i32 0, i32 24
  %24 = load i32, ptr %23, align 4, !tbaa !14
  store i32 %24, ptr %7, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [4 x %struct.player_s], ptr @players, i64 0, i64 %26
  %28 = getelementptr inbounds %struct.player_s, ptr %27, i32 0, i32 25
  %29 = load i32, ptr %28, align 8, !tbaa !15
  store i32 %29, ptr %8, align 4, !tbaa !5
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [4 x %struct.player_s], ptr @players, i64 0, i64 %31
  store ptr %32, ptr %3, align 8, !tbaa !16
  %33 = load ptr, ptr %3, align 8, !tbaa !16
  call void @llvm.memset.p0.i64(ptr align 8 %33, i8 0, i64 320, i1 false)
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [4 x %struct.player_s], ptr @players, i64 0, i64 %35
  %37 = getelementptr inbounds %struct.player_s, ptr %36, i32 0, i32 13
  %38 = getelementptr inbounds [4 x i32], ptr %37, i64 0, i64 0
  %39 = getelementptr inbounds [4 x i32], ptr %5, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %38, ptr align 16 %39, i64 16, i1 false)
  %40 = load i32, ptr %6, align 4, !tbaa !5
  %41 = load i32, ptr %2, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [4 x %struct.player_s], ptr @players, i64 0, i64 %42
  %44 = getelementptr inbounds %struct.player_s, ptr %43, i32 0, i32 23
  store i32 %40, ptr %44, align 16, !tbaa !9
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [4 x %struct.player_s], ptr @players, i64 0, i64 %47
  %49 = getelementptr inbounds %struct.player_s, ptr %48, i32 0, i32 24
  store i32 %45, ptr %49, align 4, !tbaa !14
  %50 = load i32, ptr %8, align 4, !tbaa !5
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [4 x %struct.player_s], ptr @players, i64 0, i64 %52
  %54 = getelementptr inbounds %struct.player_s, ptr %53, i32 0, i32 25
  store i32 %50, ptr %54, align 8, !tbaa !15
  %55 = load ptr, ptr %3, align 8, !tbaa !16
  %56 = getelementptr inbounds %struct.player_s, ptr %55, i32 0, i32 19
  store i32 1, ptr %56, align 8, !tbaa !17
  %57 = load ptr, ptr %3, align 8, !tbaa !16
  %58 = getelementptr inbounds %struct.player_s, ptr %57, i32 0, i32 20
  store i32 1, ptr %58, align 4, !tbaa !18
  %59 = load ptr, ptr %3, align 8, !tbaa !16
  %60 = getelementptr inbounds %struct.player_s, ptr %59, i32 0, i32 1
  store i32 0, ptr %60, align 8, !tbaa !19
  %61 = load ptr, ptr %3, align 8, !tbaa !16
  %62 = getelementptr inbounds %struct.player_s, ptr %61, i32 0, i32 7
  store i32 100, ptr %62, align 4, !tbaa !20
  %63 = load ptr, ptr %3, align 8, !tbaa !16
  %64 = getelementptr inbounds %struct.player_s, ptr %63, i32 0, i32 15
  store i32 1, ptr %64, align 8, !tbaa !21
  %65 = load ptr, ptr %3, align 8, !tbaa !16
  %66 = getelementptr inbounds %struct.player_s, ptr %65, i32 0, i32 14
  store i32 1, ptr %66, align 4, !tbaa !22
  %67 = load ptr, ptr %3, align 8, !tbaa !16
  %68 = getelementptr inbounds %struct.player_s, ptr %67, i32 0, i32 16
  %69 = getelementptr inbounds [9 x i32], ptr %68, i64 0, i64 0
  store i32 1, ptr %69, align 4, !tbaa !5
  %70 = load ptr, ptr %3, align 8, !tbaa !16
  %71 = getelementptr inbounds %struct.player_s, ptr %70, i32 0, i32 16
  %72 = getelementptr inbounds [9 x i32], ptr %71, i64 0, i64 1
  store i32 1, ptr %72, align 4, !tbaa !5
  %73 = load ptr, ptr %3, align 8, !tbaa !16
  %74 = getelementptr inbounds %struct.player_s, ptr %73, i32 0, i32 17
  %75 = getelementptr inbounds [4 x i32], ptr %74, i64 0, i64 0
  store i32 50, ptr %75, align 8, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %89, %1
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = icmp slt i32 %77, 4
  br i1 %78, label %79, label %92

79:                                               ; preds = %76
  %80 = load i32, ptr %4, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [4 x i32], ptr @maxammo, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = load ptr, ptr %3, align 8, !tbaa !16
  %85 = getelementptr inbounds %struct.player_s, ptr %84, i32 0, i32 18
  %86 = load i32, ptr %4, align 4, !tbaa !5
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [4 x i32], ptr %85, i64 0, i64 %87
  store i32 %83, ptr %88, align 4, !tbaa !5
  br label %89

89:                                               ; preds = %79
  %90 = load i32, ptr %4, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %4, align 4, !tbaa !5
  br label %76, !llvm.loop !23

92:                                               ; preds = %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { 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, !6, i64 208}
!10 = !{!"player_s", !11, i64 0, !6, i64 8, !12, i64 12, !6, i64 20, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !7, i64 48, !7, i64 72, !6, i64 96, !7, i64 100, !6, i64 116, !6, i64 120, !7, i64 124, !7, i64 160, !7, i64 176, !6, i64 192, !6, i64 196, !6, i64 200, !6, i64 204, !6, i64 208, !6, i64 212, !6, i64 216, !11, i64 224, !6, i64 232, !6, i64 236, !11, i64 240, !6, i64 248, !6, i64 252, !6, i64 256, !7, i64 264, !6, i64 312}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"", !7, i64 0, !7, i64 1, !13, i64 2, !13, i64 4, !7, i64 6, !7, i64 7}
!13 = !{!"short", !7, i64 0}
!14 = !{!10, !6, i64 212}
!15 = !{!10, !6, i64 216}
!16 = !{!11, !11, i64 0}
!17 = !{!10, !6, i64 192}
!18 = !{!10, !6, i64 196}
!19 = !{!10, !6, i64 8}
!20 = !{!10, !6, i64 36}
!21 = !{!10, !6, i64 120}
!22 = !{!10, !6, i64 116}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; 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.player_s = type { ptr, i32, %struct.ticcmd_t, i32, i32, i32, i32, i32, i32, i32, [6 x i32], [6 x i32], i32, [4 x i32], i32, i32, [9 x i32], [4 x i32], [4 x i32], i32, i32, i32, i32, i32, i32, i32, ptr, i32, i32, ptr, i32, i32, i32, [2 x %struct.pspdef_t], i32 }
%struct.ticcmd_t = type { i8, i8, i16, i16, i8, i8 }
%struct.pspdef_t = type { ptr, i32, i32, i32 }

@players = external dso_local local_unnamed_addr global [4 x %struct.player_s], align 16
@maxammo = external local_unnamed_addr global [4 x i32], align 16

; 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: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @G_PlayerReborn(i32 noundef %0) local_unnamed_addr #3 {
  %2 = alloca [4 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2)
  %3 = sext i32 %0 to i64
  %4 = getelementptr inbounds [4 x %struct.player_s], ptr @players, i64 0, i64 %3
  %5 = getelementptr inbounds i8, ptr %4, i64 100
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %2, ptr noundef nonnull align 4 dereferenceable(16) %5, i64 16, i1 false)
  %6 = getelementptr inbounds i8, ptr %4, i64 208
  %7 = getelementptr inbounds i8, ptr %4, i64 216
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = load <2 x i32>, ptr %6, align 16, !tbaa !13
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(320) %4, i8 0, i64 320, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %5, ptr noundef nonnull align 16 dereferenceable(16) %2, i64 16, i1 false)
  store <2 x i32> %9, ptr %6, align 16, !tbaa !13
  store i32 %8, ptr %7, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %4, i64 192
  store i32 1, ptr %10, align 16, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %4, i64 196
  store i32 1, ptr %11, align 4, !tbaa !15
  %12 = getelementptr inbounds i8, ptr %4, i64 36
  store i32 100, ptr %12, align 4, !tbaa !16
  %13 = getelementptr inbounds i8, ptr %4, i64 116
  store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, ptr %13, align 4, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %4, i64 160
  store i32 50, ptr %14, align 16, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %4, i64 176
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %15, ptr noundef nonnull align 16 dereferenceable(16) @maxammo, i64 16, i1 false), !tbaa !13
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2)
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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, !10, i64 216}
!6 = !{!"player_s", !7, i64 0, !10, i64 8, !11, i64 12, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !8, i64 48, !8, i64 72, !10, i64 96, !8, i64 100, !10, i64 116, !10, i64 120, !8, i64 124, !8, i64 160, !8, i64 176, !10, i64 192, !10, i64 196, !10, i64 200, !10, i64 204, !10, i64 208, !10, i64 212, !10, i64 216, !7, i64 224, !10, i64 232, !10, i64 236, !7, i64 240, !10, i64 248, !10, i64 252, !10, i64 256, !8, i64 264, !10, i64 312}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !8, i64 0, !8, i64 1, !12, i64 2, !12, i64 4, !8, i64 6, !8, i64 7}
!12 = !{!"short", !8, i64 0}
!13 = !{!10, !10, i64 0}
!14 = !{!6, !10, i64 192}
!15 = !{!6, !10, i64 196}
!16 = !{!6, !10, i64 36}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass