; 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.mobj_s = type { %struct.thinker_s, i32, i32, i32, ptr, ptr, i32, i32, i32, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, i32, ptr, i32, i32, i32, i32, ptr, i32, i32, ptr, i32, %struct.mapthing_t, ptr }
%struct.thinker_s = type { ptr, ptr, %union.actionf_t }
%union.actionf_t = type { ptr }
%struct.mapthing_t = type { i16, i16, i16, i16, i16 }

@linetarget = external global ptr, align 8

; 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

declare void @S_StartSound(ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @A_Punch(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = call i32 @P_Random()
  %10 = srem i32 %9, 10
  %11 = add nsw i32 %10, 1
  %12 = shl i32 %11, 1
  store i32 %12, ptr %6, align 4, !tbaa !9
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.player_s, ptr %13, i32 0, i32 10
  %15 = getelementptr inbounds [6 x i32], ptr %14, i64 0, i64 1
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %21

18:                                               ; preds = %2
  %19 = load i32, ptr %6, align 4, !tbaa !9
  %20 = mul nsw i32 %19, 10
  store i32 %20, ptr %6, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %18, %2
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.player_s, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !11
  %25 = getelementptr inbounds %struct.mobj_s, ptr %24, i32 0, i32 6
  %26 = load i32, ptr %25, align 8, !tbaa !15
  store i32 %26, ptr %5, align 4, !tbaa !9
  %27 = call i32 @P_Random()
  %28 = call i32 @P_Random()
  %29 = sub nsw i32 %27, %28
  %30 = shl i32 %29, 18
  %31 = load i32, ptr %5, align 4, !tbaa !9
  %32 = add i32 %31, %30
  store i32 %32, ptr %5, align 4, !tbaa !9
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.player_s, ptr %33, i32 0, i32 0
  %35 = load ptr, ptr %34, align 8, !tbaa !11
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = call i32 @P_AimLineAttack(ptr noundef %35, i32 noundef %36, i32 noundef 4194304)
  store i32 %37, ptr %7, align 4, !tbaa !9
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.player_s, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = load i32, ptr %7, align 4, !tbaa !9
  %43 = load i32, ptr %6, align 4, !tbaa !9
  call void @P_LineAttack(ptr noundef %40, i32 noundef %41, i32 noundef 4194304, i32 noundef %42, i32 noundef %43)
  %44 = load ptr, ptr @linetarget, align 8, !tbaa !5
  %45 = icmp ne ptr %44, null
  br i1 %45, label %46, label %71

46:                                               ; preds = %21
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.player_s, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !11
  call void @S_StartSound(ptr noundef %49, i32 noundef 83)
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.player_s, ptr %50, i32 0, i32 0
  %52 = load ptr, ptr %51, align 8, !tbaa !11
  %53 = getelementptr inbounds %struct.mobj_s, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !19
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.player_s, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = getelementptr inbounds %struct.mobj_s, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 4, !tbaa !20
  %60 = load ptr, ptr @linetarget, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.mobj_s, ptr %60, i32 0, i32 1
  %62 = load i32, ptr %61, align 8, !tbaa !19
  %63 = load ptr, ptr @linetarget, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.mobj_s, ptr %63, i32 0, i32 2
  %65 = load i32, ptr %64, align 4, !tbaa !20
  %66 = call i32 @R_PointToAngle2(i32 noundef %54, i32 noundef %59, i32 noundef %62, i32 noundef %65)
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.player_s, ptr %67, i32 0, i32 0
  %69 = load ptr, ptr %68, align 8, !tbaa !11
  %70 = getelementptr inbounds %struct.mobj_s, ptr %69, i32 0, i32 6
  store i32 %66, ptr %70, align 8, !tbaa !15
  br label %71

71:                                               ; preds = %46, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  ret void
}

declare i32 @P_Random() #1

declare i32 @P_AimLineAttack(ptr noundef, i32 noundef, i32 noundef) #1

declare void @P_LineAttack(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

declare i32 @R_PointToAngle2(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 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 = !{!"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 = !{!"player_s", !6, i64 0, !10, i64 8, !13, i64 12, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !7, i64 48, !7, i64 72, !10, i64 96, !7, i64 100, !10, i64 116, !10, i64 120, !7, i64 124, !7, i64 160, !7, i64 176, !10, i64 192, !10, i64 196, !10, i64 200, !10, i64 204, !10, i64 208, !10, i64 212, !10, i64 216, !6, i64 224, !10, i64 232, !10, i64 236, !6, i64 240, !10, i64 248, !10, i64 252, !10, i64 256, !7, i64 264, !10, i64 312}
!13 = !{!"", !7, i64 0, !7, i64 1, !14, i64 2, !14, i64 4, !7, i64 6, !7, i64 7}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !10, i64 56}
!16 = !{!"mobj_s", !17, i64 0, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !10, i64 128, !6, i64 136, !10, i64 144, !6, i64 152, !10, i64 160, !10, i64 164, !10, i64 168, !10, i64 172, !6, i64 176, !10, i64 184, !10, i64 188, !6, i64 192, !10, i64 200, !18, i64 204, !6, i64 216}
!17 = !{!"thinker_s", !6, i64 0, !6, i64 8, !7, i64 16}
!18 = !{!"", !14, i64 0, !14, i64 2, !14, i64 4, !14, i64 6, !14, i64 8}
!19 = !{!16, !10, i64 24}
!20 = !{!16, !10, i64 28}


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

@linetarget = external local_unnamed_addr global ptr, align 8

declare void @S_StartSound(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @A_Punch(ptr nocapture noundef readonly %0, ptr nocapture noundef readnone %1) local_unnamed_addr #1 {
  %3 = tail call i32 @P_Random() #2
  %4 = srem i32 %3, 10
  %5 = shl nsw i32 %4, 1
  %6 = add nsw i32 %5, 2
  %7 = getelementptr inbounds i8, ptr %0, i64 52
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not = icmp eq i32 %8, 0
  %9 = mul nsw i32 %6, 10
  %spec.select = select i1 %.not, i32 %6, i32 %9
  %10 = load ptr, ptr %0, align 8, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %10, i64 56
  %12 = load i32, ptr %11, align 8, !tbaa !14
  %13 = tail call i32 @P_Random() #2
  %14 = tail call i32 @P_Random() #2
  %15 = sub nsw i32 %13, %14
  %16 = shl i32 %15, 18
  %17 = add i32 %16, %12
  %18 = load ptr, ptr %0, align 8, !tbaa !9
  %19 = tail call i32 @P_AimLineAttack(ptr noundef %18, i32 noundef %17, i32 noundef 4194304) #2
  %20 = load ptr, ptr %0, align 8, !tbaa !9
  tail call void @P_LineAttack(ptr noundef %20, i32 noundef %17, i32 noundef 4194304, i32 noundef %19, i32 noundef %spec.select) #2
  %21 = load ptr, ptr @linetarget, align 8, !tbaa !18
  %.not14 = icmp eq ptr %21, null
  br i1 %.not14, label %37, label %22

22:                                               ; preds = %2
  %23 = load ptr, ptr %0, align 8, !tbaa !9
  tail call void @S_StartSound(ptr noundef %23, i32 noundef 83) #2
  %24 = load ptr, ptr %0, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %24, i64 24
  %26 = load i32, ptr %25, align 8, !tbaa !19
  %27 = getelementptr inbounds i8, ptr %24, i64 28
  %28 = load i32, ptr %27, align 4, !tbaa !20
  %29 = load ptr, ptr @linetarget, align 8, !tbaa !18
  %30 = getelementptr inbounds i8, ptr %29, i64 24
  %31 = load i32, ptr %30, align 8, !tbaa !19
  %32 = getelementptr inbounds i8, ptr %29, i64 28
  %33 = load i32, ptr %32, align 4, !tbaa !20
  %34 = tail call i32 @R_PointToAngle2(i32 noundef %26, i32 noundef %28, i32 noundef %31, i32 noundef %33) #2
  %35 = load ptr, ptr %0, align 8, !tbaa !9
  %36 = getelementptr inbounds i8, ptr %35, i64 56
  store i32 %34, ptr %36, align 8, !tbaa !14
  br label %37

37:                                               ; preds = %22, %2
  ret void
}

declare i32 @P_Random() local_unnamed_addr #0

declare i32 @P_AimLineAttack(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare void @P_LineAttack(ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare i32 @R_PointToAngle2(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

attributes #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 = { 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/C++ TBAA"}
!9 = !{!10, !11, i64 0}
!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 = !{!15, !6, i64 56}
!15 = !{!"mobj_s", !16, i64 0, !6, i64 24, !6, i64 28, !6, i64 32, !11, i64 40, !11, i64 48, !6, i64 56, !6, i64 60, !6, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !6, i64 96, !6, i64 100, !6, i64 104, !6, i64 108, !6, i64 112, !6, i64 116, !6, i64 120, !6, i64 124, !6, i64 128, !11, i64 136, !6, i64 144, !11, i64 152, !6, i64 160, !6, i64 164, !6, i64 168, !6, i64 172, !11, i64 176, !6, i64 184, !6, i64 188, !11, i64 192, !6, i64 200, !17, i64 204, !11, i64 216}
!16 = !{!"thinker_s", !11, i64 0, !11, i64 8, !7, i64 16}
!17 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !13, i64 8}
!18 = !{!11, !11, i64 0}
!19 = !{!15, !6, i64 24}
!20 = !{!15, !6, i64 28}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass