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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @P_GiveBody(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.player_s, ptr %6, i32 0, i32 7
  %8 = load i32, ptr %7, align 4, !tbaa !11
  %9 = icmp sge i32 %8, 100
  br i1 %9, label %10, label %11

10:                                               ; preds = %2
  store i32 0, ptr %3, align 4
  br label %32

11:                                               ; preds = %2
  %12 = load i32, ptr %5, align 4, !tbaa !9
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.player_s, ptr %13, i32 0, i32 7
  %15 = load i32, ptr %14, align 4, !tbaa !11
  %16 = add nsw i32 %15, %12
  store i32 %16, ptr %14, align 4, !tbaa !11
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.player_s, ptr %17, i32 0, i32 7
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = icmp sgt i32 %19, 100
  br i1 %20, label %21, label %24

21:                                               ; preds = %11
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.player_s, ptr %22, i32 0, i32 7
  store i32 100, ptr %23, align 4, !tbaa !11
  br label %24

24:                                               ; preds = %21, %11
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.player_s, ptr %25, i32 0, i32 7
  %27 = load i32, ptr %26, align 4, !tbaa !11
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.player_s, ptr %28, i32 0, i32 0
  %30 = load ptr, ptr %29, align 8, !tbaa !15
  %31 = getelementptr inbounds %struct.mobj_s, ptr %30, i32 0, i32 25
  store i32 %27, ptr %31, align 4, !tbaa !16
  store i32 1, ptr %3, align 4
  br label %32

32:                                               ; preds = %24, %10
  %33 = load i32, ptr %3, align 4
  ret i32 %33
}

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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 36}
!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 = !{!12, !6, i64 0}
!16 = !{!17, !10, i64 164}
!17 = !{!"mobj_s", !18, 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, !19, i64 204, !6, i64 216}
!18 = !{!"thinker_s", !6, i64 0, !6, i64 8, !7, i64 16}
!19 = !{!"", !14, i64 0, !14, i64 2, !14, i64 4, !14, i64 6, !14, i64 8}


; 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: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @P_GiveBody(ptr nocapture noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 36
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = icmp sgt i32 %4, 99
  br i1 %5, label %10, label %6

6:                                                ; preds = %2
  %7 = add nsw i32 %4, %1
  %spec.select = tail call i32 @llvm.smin.i32(i32 %7, i32 100)
  store i32 %spec.select, ptr %3, align 4, !tbaa !5
  %8 = load ptr, ptr %0, align 8, !tbaa !13
  %9 = getelementptr inbounds i8, ptr %8, i64 164
  store i32 %spec.select, ptr %9, align 4, !tbaa !14
  br label %10

10:                                               ; preds = %2, %6
  %.0 = phi i32 [ 1, %6 ], [ 0, %2 ]
  ret i32 %.0
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: readwrite, 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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 36}
!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, !7, i64 0}
!14 = !{!15, !10, i64 164}
!15 = !{!"mobj_s", !16, 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, !17, i64 204, !7, i64 216}
!16 = !{!"thinker_s", !7, i64 0, !7, i64 8, !8, i64 16}
!17 = !{!"", !12, i64 0, !12, i64 2, !12, i64 4, !12, i64 6, !12, i64 8}


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