; 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

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

; Function Attrs: nounwind uwtable
define dso_local void @A_Saw(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
  %8 = 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
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = call i32 @P_Random()
  %11 = srem i32 %10, 10
  %12 = add nsw i32 %11, 1
  %13 = mul nsw i32 2, %12
  store i32 %13, ptr %6, align 4, !tbaa !9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.player_s, ptr %14, i32 0, i32 0
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = getelementptr inbounds %struct.mobj_s, ptr %16, i32 0, i32 6
  %18 = load i32, ptr %17, align 8, !tbaa !15
  store i32 %18, ptr %5, align 4, !tbaa !9
  %19 = call i32 @P_Random()
  %20 = call i32 @P_Random()
  %21 = sub nsw i32 %19, %20
  %22 = shl i32 %21, 18
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = add i32 %23, %22
  store i32 %24, ptr %5, align 4, !tbaa !9
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.player_s, ptr %25, i32 0, i32 0
  %27 = load ptr, ptr %26, align 8, !tbaa !11
  %28 = load i32, ptr %5, align 4, !tbaa !9
  %29 = call i32 @P_AimLineAttack(ptr noundef %27, i32 noundef %28, i32 noundef 4194305)
  store i32 %29, ptr %7, align 4, !tbaa !9
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.player_s, ptr %30, i32 0, i32 0
  %32 = load ptr, ptr %31, align 8, !tbaa !11
  %33 = load i32, ptr %5, align 4, !tbaa !9
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = load i32, ptr %6, align 4, !tbaa !9
  call void @P_LineAttack(ptr noundef %32, i32 noundef %33, i32 noundef 4194305, i32 noundef %34, i32 noundef %35)
  %36 = load ptr, ptr @linetarget, align 8, !tbaa !5
  %37 = icmp ne ptr %36, null
  br i1 %37, label %42, label %38

38:                                               ; preds = %2
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.player_s, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !11
  call void @S_StartSound(ptr noundef %41, i32 noundef 12)
  store i32 1, ptr %8, align 4
  br label %126

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

71:                                               ; preds = %42
  %72 = load i32, ptr %5, align 4, !tbaa !9
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.player_s, ptr %73, i32 0, i32 0
  %75 = load ptr, ptr %74, align 8, !tbaa !11
  %76 = getelementptr inbounds %struct.mobj_s, ptr %75, i32 0, i32 6
  %77 = load i32, ptr %76, align 8, !tbaa !15
  %78 = sub i32 %72, %77
  %79 = icmp ult i32 %78, -53687091
  br i1 %79, label %80, label %87

80:                                               ; preds = %71
  %81 = load i32, ptr %5, align 4, !tbaa !9
  %82 = add i32 %81, 51130563
  %83 = load ptr, ptr %3, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.player_s, ptr %83, i32 0, i32 0
  %85 = load ptr, ptr %84, align 8, !tbaa !11
  %86 = getelementptr inbounds %struct.mobj_s, ptr %85, i32 0, i32 6
  store i32 %82, ptr %86, align 8, !tbaa !15
  br label %94

87:                                               ; preds = %71
  %88 = load ptr, ptr %3, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.player_s, ptr %88, i32 0, i32 0
  %90 = load ptr, ptr %89, align 8, !tbaa !11
  %91 = getelementptr inbounds %struct.mobj_s, ptr %90, i32 0, i32 6
  %92 = load i32, ptr %91, align 8, !tbaa !15
  %93 = sub i32 %92, 53687091
  store i32 %93, ptr %91, align 8, !tbaa !15
  br label %94

94:                                               ; preds = %87, %80
  br label %119

95:                                               ; preds = %42
  %96 = load i32, ptr %5, align 4, !tbaa !9
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.player_s, ptr %97, i32 0, i32 0
  %99 = load ptr, ptr %98, align 8, !tbaa !11
  %100 = getelementptr inbounds %struct.mobj_s, ptr %99, i32 0, i32 6
  %101 = load i32, ptr %100, align 8, !tbaa !15
  %102 = sub i32 %96, %101
  %103 = icmp ugt i32 %102, 53687091
  br i1 %103, label %104, label %111

104:                                              ; preds = %95
  %105 = load i32, ptr %5, align 4, !tbaa !9
  %106 = sub i32 %105, 51130563
  %107 = load ptr, ptr %3, align 8, !tbaa !5
  %108 = getelementptr inbounds %struct.player_s, ptr %107, i32 0, i32 0
  %109 = load ptr, ptr %108, align 8, !tbaa !11
  %110 = getelementptr inbounds %struct.mobj_s, ptr %109, i32 0, i32 6
  store i32 %106, ptr %110, align 8, !tbaa !15
  br label %118

111:                                              ; preds = %95
  %112 = load ptr, ptr %3, align 8, !tbaa !5
  %113 = getelementptr inbounds %struct.player_s, ptr %112, i32 0, i32 0
  %114 = load ptr, ptr %113, align 8, !tbaa !11
  %115 = getelementptr inbounds %struct.mobj_s, ptr %114, i32 0, i32 6
  %116 = load i32, ptr %115, align 8, !tbaa !15
  %117 = add i32 %116, 53687091
  store i32 %117, ptr %115, align 8, !tbaa !15
  br label %118

118:                                              ; preds = %111, %104
  br label %119

119:                                              ; preds = %118, %94
  %120 = load ptr, ptr %3, align 8, !tbaa !5
  %121 = getelementptr inbounds %struct.player_s, ptr %120, i32 0, i32 0
  %122 = load ptr, ptr %121, align 8, !tbaa !11
  %123 = getelementptr inbounds %struct.mobj_s, ptr %122, i32 0, i32 24
  %124 = load i32, ptr %123, align 8, !tbaa !21
  %125 = or i32 %124, 128
  store i32 %125, ptr %123, align 8, !tbaa !21
  store i32 0, ptr %8, align 4
  br label %126

126:                                              ; preds = %119, %38
  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
  %127 = load i32, ptr %8, align 4
  switch i32 %127, label %129 [
    i32 0, label %128
    i32 1, label %128
  ]

128:                                              ; preds = %126, %126
  ret void

129:                                              ; preds = %126
  unreachable
}

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}
!21 = !{!16, !10, i64 160}


; 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

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

; Function Attrs: nounwind uwtable
define dso_local void @A_Saw(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 = load ptr, ptr %0, align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %7, i64 56
  %9 = load i32, ptr %8, align 8, !tbaa !13
  %10 = tail call i32 @P_Random() #2
  %11 = tail call i32 @P_Random() #2
  %12 = sub nsw i32 %10, %11
  %13 = shl i32 %12, 18
  %14 = add i32 %13, %9
  %15 = load ptr, ptr %0, align 8, !tbaa !5
  %16 = tail call i32 @P_AimLineAttack(ptr noundef %15, i32 noundef %14, i32 noundef 4194305) #2
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  tail call void @P_LineAttack(ptr noundef %17, i32 noundef %14, i32 noundef 4194305, i32 noundef %16, i32 noundef %6) #2
  %18 = load ptr, ptr @linetarget, align 8, !tbaa !17
  %.not = icmp eq ptr %18, null
  %19 = load ptr, ptr %0, align 8, !tbaa !5
  br i1 %.not, label %20, label %21

20:                                               ; preds = %2
  tail call void @S_StartSound(ptr noundef %19, i32 noundef 12) #2
  br label %54

21:                                               ; preds = %2
  tail call void @S_StartSound(ptr noundef %19, i32 noundef 13) #2
  %22 = load ptr, ptr %0, align 8, !tbaa !5
  %23 = getelementptr inbounds i8, ptr %22, i64 24
  %24 = load i32, ptr %23, align 8, !tbaa !18
  %25 = getelementptr inbounds i8, ptr %22, i64 28
  %26 = load i32, ptr %25, align 4, !tbaa !19
  %27 = load ptr, ptr @linetarget, align 8, !tbaa !17
  %28 = getelementptr inbounds i8, ptr %27, i64 24
  %29 = load i32, ptr %28, align 8, !tbaa !18
  %30 = getelementptr inbounds i8, ptr %27, i64 28
  %31 = load i32, ptr %30, align 4, !tbaa !19
  %32 = tail call i32 @R_PointToAngle2(i32 noundef %24, i32 noundef %26, i32 noundef %29, i32 noundef %31) #2
  %33 = load ptr, ptr %0, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %33, i64 56
  %35 = load i32, ptr %34, align 8, !tbaa !13
  %36 = sub i32 %32, %35
  %37 = icmp ugt i32 %36, -2147483648
  br i1 %37, label %38, label %44

38:                                               ; preds = %21
  %39 = icmp ult i32 %36, -53687091
  br i1 %39, label %40, label %42

40:                                               ; preds = %38
  %41 = add i32 %32, 51130563
  br label %50

42:                                               ; preds = %38
  %43 = add i32 %35, -53687091
  br label %50

44:                                               ; preds = %21
  %45 = icmp ugt i32 %36, 53687091
  br i1 %45, label %46, label %48

46:                                               ; preds = %44
  %47 = add i32 %32, -51130563
  br label %50

48:                                               ; preds = %44
  %49 = add i32 %35, 53687091
  br label %50

50:                                               ; preds = %46, %48, %40, %42
  %.sink = phi i32 [ %47, %46 ], [ %49, %48 ], [ %41, %40 ], [ %43, %42 ]
  store i32 %.sink, ptr %34, align 8, !tbaa !13
  %51 = getelementptr inbounds i8, ptr %33, i64 160
  %52 = load i32, ptr %51, align 8, !tbaa !20
  %53 = or i32 %52, 128
  store i32 %53, ptr %51, align 8, !tbaa !20
  br label %54

54:                                               ; preds = %50, %20
  ret void
}

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, !7, i64 0}
!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 = !{!14, !10, i64 56}
!14 = !{!"mobj_s", !15, i64 0, !10, i64 24, !10, i64 28, !10, i64 32, !7, i64 40, !7, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !7, i64 72, !7, i64 80, !7, 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, !7, i64 136, !10, i64 144, !7, i64 152, !10, i64 160, !10, i64 164, !10, i64 168, !10, i64 172, !7, i64 176, !10, i64 184, !10, i64 188, !7, i64 192, !10, i64 200, !16, i64 204, !7, i64 216}
!15 = !{!"thinker_s", !7, i64 0, !7, i64 8, !8, i64 16}
!16 = !{!"", !12, i64 0, !12, i64 2, !12, i64 4, !12, i64 6, !12, i64 8}
!17 = !{!7, !7, i64 0}
!18 = !{!14, !10, i64 24}
!19 = !{!14, !10, i64 28}
!20 = !{!14, !10, i64 160}


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