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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @P_CheckAmmo(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local void @P_FireWeapon(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @A_ReFire(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.player_s, ptr %6, i32 0, i32 2
  %8 = getelementptr inbounds %struct.ticcmd_t, ptr %7, i32 0, i32 5
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %10 = zext i8 %9 to i32
  %11 = and i32 %10, 1
  %12 = icmp ne i32 %11, 0
  br i1 %12, label %13, label %29

13:                                               ; preds = %2
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.player_s, ptr %14, i32 0, i32 15
  %16 = load i32, ptr %15, align 8, !tbaa !14
  %17 = icmp eq i32 %16, 10
  br i1 %17, label %18, label %29

18:                                               ; preds = %13
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.player_s, ptr %19, i32 0, i32 7
  %21 = load i32, ptr %20, align 4, !tbaa !15
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %23, label %29

23:                                               ; preds = %18
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.player_s, ptr %24, i32 0, i32 22
  %26 = load i32, ptr %25, align 4, !tbaa !16
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %25, align 4, !tbaa !16
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  call void @P_FireWeapon(ptr noundef %28)
  br label %34

29:                                               ; preds = %18, %13, %2
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.player_s, ptr %30, i32 0, i32 22
  store i32 0, ptr %31, align 4, !tbaa !16
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = call i32 @P_CheckAmmo(ptr noundef %32)
  br label %34

34:                                               ; preds = %29, %23
  ret void
}

attributes #0 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 19}
!10 = !{!"player_s", !6, i64 0, !11, i64 8, !12, i64 12, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !7, i64 48, !7, i64 72, !11, i64 96, !7, i64 100, !11, i64 116, !11, i64 120, !7, i64 124, !7, i64 160, !7, i64 176, !11, i64 192, !11, i64 196, !11, i64 200, !11, i64 204, !11, i64 208, !11, i64 212, !11, i64 216, !6, i64 224, !11, i64 232, !11, i64 236, !6, i64 240, !11, i64 248, !11, i64 252, !11, i64 256, !7, i64 264, !11, i64 312}
!11 = !{!"int", !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, !11, i64 120}
!15 = !{!10, !11, i64 36}
!16 = !{!10, !11, i64 204}


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

; Function Attrs: nounwind uwtable
declare dso_local i32 @P_CheckAmmo(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @P_FireWeapon(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @A_ReFire(ptr noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 19
  %4 = load i8, ptr %3, align 1, !tbaa !5
  %5 = and i8 %4, 1
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %17, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %0, i64 120
  %8 = load i32, ptr %7, align 8, !tbaa !13
  %9 = icmp eq i32 %8, 10
  br i1 %9, label %10, label %17

10:                                               ; preds = %6
  %11 = getelementptr inbounds i8, ptr %0, i64 36
  %12 = load i32, ptr %11, align 4, !tbaa !14
  %.not8 = icmp eq i32 %12, 0
  br i1 %.not8, label %17, label %13

13:                                               ; preds = %10
  %14 = getelementptr inbounds i8, ptr %0, i64 204
  %15 = load i32, ptr %14, align 4, !tbaa !15
  %16 = add nsw i32 %15, 1
  store i32 %16, ptr %14, align 4, !tbaa !15
  tail call void @P_FireWeapon(ptr noundef nonnull %0)
  br label %20

17:                                               ; preds = %10, %6, %2
  %18 = getelementptr inbounds i8, ptr %0, i64 204
  store i32 0, ptr %18, align 4, !tbaa !15
  %19 = tail call i32 @P_CheckAmmo(ptr noundef nonnull %0)
  br label %20

20:                                               ; preds = %17, %13
  ret void
}

attributes #0 = { 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, !8, i64 19}
!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 = !{!6, !10, i64 120}
!14 = !{!6, !10, i64 36}
!15 = !{!6, !10, i64 204}


; Effective O3 passes: CorrelatedValuePropagationPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,TailCallElimPass