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

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

@onground = external dso_local global i32, align 4
@states = external global [967 x %struct.state_t], align 16

; Function Attrs: nounwind uwtable
declare dso_local void @P_Thrust(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_MovePlayer(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = getelementptr inbounds %struct.player_s, ptr %4, i32 0, i32 2
  store ptr %5, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.ticcmd_t, ptr %6, i32 0, i32 2
  %8 = load i16, ptr %7, align 2, !tbaa !9
  %9 = sext i16 %8 to i32
  %10 = shl i32 %9, 16
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.player_s, ptr %11, i32 0, i32 0
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = getelementptr inbounds %struct.mobj_s, ptr %13, i32 0, i32 6
  %15 = load i32, ptr %14, align 8, !tbaa !15
  %16 = add i32 %15, %10
  store i32 %16, ptr %14, align 8, !tbaa !15
  %17 = load ptr, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.player_s, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !12
  %20 = getelementptr inbounds %struct.mobj_s, ptr %19, i32 0, i32 3
  %21 = load i32, ptr %20, align 8, !tbaa !19
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.player_s, ptr %22, i32 0, i32 0
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = getelementptr inbounds %struct.mobj_s, ptr %24, i32 0, i32 12
  %26 = load i32, ptr %25, align 8, !tbaa !20
  %27 = icmp sle i32 %21, %26
  %28 = zext i1 %27 to i32
  store i32 %28, ptr @onground, align 4, !tbaa !21
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ticcmd_t, ptr %29, i32 0, i32 0
  %31 = load i8, ptr %30, align 2, !tbaa !22
  %32 = sext i8 %31 to i32
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %49

34:                                               ; preds = %1
  %35 = load i32, ptr @onground, align 4, !tbaa !21
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %37, label %49

37:                                               ; preds = %34
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = load ptr, ptr %2, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.player_s, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !12
  %42 = getelementptr inbounds %struct.mobj_s, ptr %41, i32 0, i32 6
  %43 = load i32, ptr %42, align 8, !tbaa !15
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.ticcmd_t, ptr %44, i32 0, i32 0
  %46 = load i8, ptr %45, align 2, !tbaa !22
  %47 = sext i8 %46 to i32
  %48 = mul nsw i32 %47, 2048
  call void @P_Thrust(ptr noundef %38, i32 noundef %43, i32 noundef %48)
  br label %49

49:                                               ; preds = %37, %34, %1
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.ticcmd_t, ptr %50, i32 0, i32 1
  %52 = load i8, ptr %51, align 1, !tbaa !23
  %53 = sext i8 %52 to i32
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %55, label %71

55:                                               ; preds = %49
  %56 = load i32, ptr @onground, align 4, !tbaa !21
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %58, label %71

58:                                               ; preds = %55
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.player_s, ptr %60, i32 0, i32 0
  %62 = load ptr, ptr %61, align 8, !tbaa !12
  %63 = getelementptr inbounds %struct.mobj_s, ptr %62, i32 0, i32 6
  %64 = load i32, ptr %63, align 8, !tbaa !15
  %65 = sub i32 %64, 1073741824
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ticcmd_t, ptr %66, i32 0, i32 1
  %68 = load i8, ptr %67, align 1, !tbaa !23
  %69 = sext i8 %68 to i32
  %70 = mul nsw i32 %69, 2048
  call void @P_Thrust(ptr noundef %59, i32 noundef %65, i32 noundef %70)
  br label %71

71:                                               ; preds = %58, %55, %49
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.ticcmd_t, ptr %72, i32 0, i32 0
  %74 = load i8, ptr %73, align 2, !tbaa !22
  %75 = sext i8 %74 to i32
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %83, label %77

77:                                               ; preds = %71
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.ticcmd_t, ptr %78, i32 0, i32 1
  %80 = load i8, ptr %79, align 1, !tbaa !23
  %81 = sext i8 %80 to i32
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %95

83:                                               ; preds = %77, %71
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.player_s, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !12
  %87 = getelementptr inbounds %struct.mobj_s, ptr %86, i32 0, i32 23
  %88 = load ptr, ptr %87, align 8, !tbaa !24
  %89 = icmp eq ptr %88, getelementptr inbounds ([967 x %struct.state_t], ptr @states, i64 0, i64 149)
  br i1 %89, label %90, label %95

90:                                               ; preds = %83
  %91 = load ptr, ptr %2, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.player_s, ptr %91, i32 0, i32 0
  %93 = load ptr, ptr %92, align 8, !tbaa !12
  %94 = call i32 @P_SetMobjState(ptr noundef %93, i32 noundef 150)
  br label %95

95:                                               ; preds = %90, %83, %77
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

declare i32 @P_SetMobjState(ptr noundef, i32 noundef) #2

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


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

%struct.state_t = type { i32, i64, i64, %union.actionf_t, i32, i64, i64 }
%union.actionf_t = type { ptr }

@onground = external dso_local local_unnamed_addr global i32, align 4
@states = external global [967 x %struct.state_t], align 16

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

; Function Attrs: nounwind uwtable
define dso_local void @P_MovePlayer(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 12
  %3 = getelementptr inbounds i8, ptr %0, i64 14
  %4 = load i16, ptr %3, align 2, !tbaa !5
  %5 = sext i16 %4 to i32
  %6 = shl nsw i32 %5, 16
  %7 = load ptr, ptr %0, align 8, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %7, i64 56
  %9 = load i32, ptr %8, align 8, !tbaa !14
  %10 = add i32 %9, %6
  store i32 %10, ptr %8, align 8, !tbaa !14
  %11 = getelementptr inbounds i8, ptr %7, i64 32
  %12 = load i32, ptr %11, align 8, !tbaa !18
  %13 = getelementptr inbounds i8, ptr %7, i64 96
  %14 = load i32, ptr %13, align 8, !tbaa !19
  %15 = icmp sle i32 %12, %14
  %16 = zext i1 %15 to i32
  store i32 %16, ptr @onground, align 4, !tbaa !20
  %17 = load i8, ptr %2, align 2, !tbaa !21
  %18 = icmp ne i8 %17, 0
  %or.cond = select i1 %18, i1 %15, i1 false
  br i1 %or.cond, label %19, label %23

19:                                               ; preds = %1
  %20 = sext i8 %17 to i32
  %21 = shl nsw i32 %20, 11
  tail call void @P_Thrust(ptr noundef nonnull %0, i32 noundef %10, i32 noundef %21)
  %.pre = load i32, ptr @onground, align 4
  %22 = icmp ne i32 %.pre, 0
  br label %23

23:                                               ; preds = %19, %1
  %24 = phi i1 [ %22, %19 ], [ %15, %1 ]
  %25 = getelementptr inbounds i8, ptr %0, i64 13
  %26 = load i8, ptr %25, align 1, !tbaa !22
  %27 = icmp ne i8 %26, 0
  %or.cond3 = select i1 %27, i1 %24, i1 false
  br i1 %or.cond3, label %28, label %35

28:                                               ; preds = %23
  %29 = sext i8 %26 to i32
  %30 = load ptr, ptr %0, align 8, !tbaa !10
  %31 = getelementptr inbounds i8, ptr %30, i64 56
  %32 = load i32, ptr %31, align 8, !tbaa !14
  %33 = add i32 %32, -1073741824
  %34 = shl nsw i32 %29, 11
  tail call void @P_Thrust(ptr noundef nonnull %0, i32 noundef %33, i32 noundef %34)
  br label %35

35:                                               ; preds = %28, %23
  %36 = load i8, ptr %2, align 2, !tbaa !21
  %.not = icmp eq i8 %36, 0
  br i1 %.not, label %37, label %39

37:                                               ; preds = %35
  %38 = load i8, ptr %25, align 1, !tbaa !22
  %.not21 = icmp eq i8 %38, 0
  br i1 %.not21, label %46, label %39

39:                                               ; preds = %37, %35
  %40 = load ptr, ptr %0, align 8, !tbaa !10
  %41 = getelementptr inbounds i8, ptr %40, i64 152
  %42 = load ptr, ptr %41, align 8, !tbaa !23
  %43 = icmp eq ptr %42, getelementptr inbounds (i8, ptr @states, i64 8344)
  br i1 %43, label %44, label %46

44:                                               ; preds = %39
  %45 = tail call i32 @P_SetMobjState(ptr noundef nonnull %40, i32 noundef 150) #2
  br label %46

46:                                               ; preds = %44, %39, %37
  ret void
}

declare i32 @P_SetMobjState(ptr noundef, i32 noundef) local_unnamed_addr #1

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 = { "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, !9, i64 2}
!6 = !{!"", !7, i64 0, !7, i64 1, !9, i64 2, !9, i64 4, !7, i64 6, !7, i64 7}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"short", !7, i64 0}
!10 = !{!11, !12, i64 0}
!11 = !{!"player_s", !12, i64 0, !13, i64 8, !6, i64 12, !13, i64 20, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !7, i64 48, !7, i64 72, !13, i64 96, !7, i64 100, !13, i64 116, !13, i64 120, !7, i64 124, !7, i64 160, !7, i64 176, !13, i64 192, !13, i64 196, !13, i64 200, !13, i64 204, !13, i64 208, !13, i64 212, !13, i64 216, !12, i64 224, !13, i64 232, !13, i64 236, !12, i64 240, !13, i64 248, !13, i64 252, !13, i64 256, !7, i64 264, !13, i64 312}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!15, !13, i64 56}
!15 = !{!"mobj_s", !16, i64 0, !13, i64 24, !13, i64 28, !13, i64 32, !12, i64 40, !12, i64 48, !13, i64 56, !13, i64 60, !13, i64 64, !12, i64 72, !12, i64 80, !12, i64 88, !13, i64 96, !13, i64 100, !13, i64 104, !13, i64 108, !13, i64 112, !13, i64 116, !13, i64 120, !13, i64 124, !13, i64 128, !12, i64 136, !13, i64 144, !12, i64 152, !13, i64 160, !13, i64 164, !13, i64 168, !13, i64 172, !12, i64 176, !13, i64 184, !13, i64 188, !12, i64 192, !13, i64 200, !17, i64 204, !12, i64 216}
!16 = !{!"thinker_s", !12, i64 0, !12, i64 8, !7, i64 16}
!17 = !{!"", !9, i64 0, !9, i64 2, !9, i64 4, !9, i64 6, !9, i64 8}
!18 = !{!15, !13, i64 32}
!19 = !{!15, !13, i64 96}
!20 = !{!13, !13, i64 0}
!21 = !{!6, !7, i64 0}
!22 = !{!6, !7, i64 1}
!23 = !{!15, !12, i64 152}


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