; 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 }
%struct.state_t = type { i32, i64, i64, %union.actionf_t, i32, i64, i64 }
%union.actionf_t = type { ptr }

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local void @P_MovePsprites(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.player_s, ptr %6, i32 0, i32 33
  %8 = getelementptr inbounds [2 x %struct.pspdef_t], ptr %7, i64 0, i64 0
  store ptr %8, ptr %4, align 8, !tbaa !5
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %42, %1
  %10 = load i32, ptr %3, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 2
  br i1 %11, label %12, label %47

12:                                               ; preds = %9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.pspdef_t, ptr %13, i32 0, i32 0
  %15 = load ptr, ptr %14, align 8, !tbaa !11
  store ptr %15, ptr %5, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %17, label %41

17:                                               ; preds = %12
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.pspdef_t, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 8, !tbaa !13
  %21 = icmp ne i32 %20, -1
  br i1 %21, label %22, label %40

22:                                               ; preds = %17
  %23 = load ptr, ptr %4, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.pspdef_t, ptr %23, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = add nsw i32 %25, -1
  store i32 %26, ptr %24, align 8, !tbaa !13
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.pspdef_t, ptr %27, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !13
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %39, label %31

31:                                               ; preds = %22
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !9
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.pspdef_t, ptr %34, i32 0, i32 0
  %36 = load ptr, ptr %35, align 8, !tbaa !11
  %37 = getelementptr inbounds %struct.state_t, ptr %36, i32 0, i32 4
  %38 = load i32, ptr %37, align 8, !tbaa !14
  call void @P_SetPsprite(ptr noundef %32, i32 noundef %33, i32 noundef %38)
  br label %39

39:                                               ; preds = %31, %22
  br label %40

40:                                               ; preds = %39, %17
  br label %41

41:                                               ; preds = %40, %12
  br label %42

42:                                               ; preds = %41
  %43 = load i32, ptr %3, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %3, align 4, !tbaa !9
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.pspdef_t, ptr %45, i32 1
  store ptr %46, ptr %4, align 8, !tbaa !5
  br label %9, !llvm.loop !17

47:                                               ; preds = %9
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.player_s, ptr %48, i32 0, i32 33
  %50 = getelementptr inbounds [2 x %struct.pspdef_t], ptr %49, i64 0, i64 0
  %51 = getelementptr inbounds %struct.pspdef_t, ptr %50, i32 0, i32 2
  %52 = load i32, ptr %51, align 4, !tbaa !19
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.player_s, ptr %53, i32 0, i32 33
  %55 = getelementptr inbounds [2 x %struct.pspdef_t], ptr %54, i64 0, i64 1
  %56 = getelementptr inbounds %struct.pspdef_t, ptr %55, i32 0, i32 2
  store i32 %52, ptr %56, align 4, !tbaa !19
  %57 = load ptr, ptr %2, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.player_s, ptr %57, i32 0, i32 33
  %59 = getelementptr inbounds [2 x %struct.pspdef_t], ptr %58, i64 0, i64 0
  %60 = getelementptr inbounds %struct.pspdef_t, ptr %59, i32 0, i32 3
  %61 = load i32, ptr %60, align 8, !tbaa !20
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.player_s, ptr %62, i32 0, i32 33
  %64 = getelementptr inbounds [2 x %struct.pspdef_t], ptr %63, i64 0, i64 1
  %65 = getelementptr inbounds %struct.pspdef_t, ptr %64, i32 0, i32 3
  store i32 %61, ptr %65, align 8, !tbaa !20
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!13 = !{!12, !10, i64 8}
!14 = !{!15, !10, i64 32}
!15 = !{!"", !10, i64 0, !16, i64 8, !16, i64 16, !7, i64 24, !10, i64 32, !16, i64 40, !16, i64 48}
!16 = !{!"long", !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!12, !10, i64 12}
!20 = !{!12, !10, i64 16}


; 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 void @P_SetPsprite(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @P_MovePsprites(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 264
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %12, label %4

4:                                                ; preds = %1
  %5 = getelementptr inbounds i8, ptr %0, i64 272
  %6 = load i32, ptr %5, align 8, !tbaa !11
  %.not16 = icmp eq i32 %6, -1
  br i1 %.not16, label %12, label %7

7:                                                ; preds = %4
  %8 = add nsw i32 %6, -1
  store i32 %8, ptr %5, align 8, !tbaa !11
  %.not17 = icmp eq i32 %8, 0
  br i1 %.not17, label %9, label %12

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %3, i64 32
  %11 = load i32, ptr %10, align 8, !tbaa !12
  tail call void @P_SetPsprite(ptr noundef nonnull %0, i32 noundef 0, i32 noundef %11)
  br label %12

12:                                               ; preds = %1, %7, %9, %4
  %13 = getelementptr inbounds i8, ptr %0, i64 288
  %14 = load ptr, ptr %13, align 8, !tbaa !5
  %.not.1 = icmp eq ptr %14, null
  br i1 %.not.1, label %23, label %15

15:                                               ; preds = %12
  %16 = getelementptr inbounds i8, ptr %0, i64 296
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %.not16.1 = icmp eq i32 %17, -1
  br i1 %.not16.1, label %23, label %18

18:                                               ; preds = %15
  %19 = add nsw i32 %17, -1
  store i32 %19, ptr %16, align 8, !tbaa !11
  %.not17.1 = icmp eq i32 %19, 0
  br i1 %.not17.1, label %20, label %23

20:                                               ; preds = %18
  %21 = getelementptr inbounds i8, ptr %14, i64 32
  %22 = load i32, ptr %21, align 8, !tbaa !12
  tail call void @P_SetPsprite(ptr noundef nonnull %0, i32 noundef 1, i32 noundef %22)
  br label %23

23:                                               ; preds = %20, %18, %15, %12
  %24 = getelementptr inbounds i8, ptr %0, i64 276
  %25 = getelementptr inbounds i8, ptr %0, i64 300
  %26 = load <2 x i32>, ptr %24, align 4, !tbaa !15
  store <2 x i32> %26, ptr %25, align 4, !tbaa !15
  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, !7, i64 0}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !10, i64 16}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!13, !10, i64 32}
!13 = !{!"", !10, i64 0, !14, i64 8, !14, i64 16, !8, i64 24, !10, i64 32, !14, i64 40, !14, i64 48}
!14 = !{!"long", !8, i64 0}
!15 = !{!10, !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass