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

; 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.mobjinfo_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, 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 }

@mobjinfo = external global [137 x %struct.mobjinfo_t], align 16
@viletryx = external dso_local global i32, align 4
@viletryy = external dso_local global i32, align 4
@corpsehit = external dso_local 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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @PIT_VileCheck(ptr noundef %0) #2 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.mobj_s, ptr %7, i32 0, i32 24
  %9 = load i32, ptr %8, align 8, !tbaa !9
  %10 = and i32 %9, 1048576
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %13, label %12

12:                                               ; preds = %1
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %79

13:                                               ; preds = %1
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.mobj_s, ptr %14, i32 0, i32 22
  %16 = load i32, ptr %15, align 8, !tbaa !15
  %17 = icmp ne i32 %16, -1
  br i1 %17, label %18, label %19

18:                                               ; preds = %13
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %79

19:                                               ; preds = %13
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.mobj_s, ptr %20, i32 0, i32 21
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = getelementptr inbounds %struct.mobjinfo_t, ptr %22, i32 0, i32 22
  %24 = load i32, ptr %23, align 4, !tbaa !17
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %19
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %79

27:                                               ; preds = %19
  %28 = load ptr, ptr %3, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.mobj_s, ptr %28, i32 0, i32 21
  %30 = load ptr, ptr %29, align 8, !tbaa !16
  %31 = getelementptr inbounds %struct.mobjinfo_t, ptr %30, i32 0, i32 16
  %32 = load i32, ptr %31, align 4, !tbaa !19
  %33 = load i32, ptr getelementptr inbounds (%struct.mobjinfo_t, ptr getelementptr inbounds ([137 x %struct.mobjinfo_t], ptr @mobjinfo, i64 0, i64 3), i32 0, i32 16), align 4, !tbaa !19
  %34 = add nsw i32 %32, %33
  store i32 %34, ptr %4, align 4, !tbaa !20
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mobj_s, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 8, !tbaa !21
  %38 = load i32, ptr @viletryx, align 4, !tbaa !20
  %39 = sub nsw i32 %37, %38
  %40 = call i32 @llvm.abs.i32(i32 %39, i1 true)
  %41 = load i32, ptr %4, align 4, !tbaa !20
  %42 = icmp sgt i32 %40, %41
  br i1 %42, label %52, label %43

43:                                               ; preds = %27
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.mobj_s, ptr %44, i32 0, i32 2
  %46 = load i32, ptr %45, align 4, !tbaa !22
  %47 = load i32, ptr @viletryy, align 4, !tbaa !20
  %48 = sub nsw i32 %46, %47
  %49 = call i32 @llvm.abs.i32(i32 %48, i1 true)
  %50 = load i32, ptr %4, align 4, !tbaa !20
  %51 = icmp sgt i32 %49, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %43, %27
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %79

53:                                               ; preds = %43
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %54, ptr @corpsehit, align 8, !tbaa !5
  %55 = load ptr, ptr @corpsehit, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.mobj_s, ptr %55, i32 0, i32 17
  store i32 0, ptr %56, align 4, !tbaa !23
  %57 = load ptr, ptr @corpsehit, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.mobj_s, ptr %57, i32 0, i32 16
  store i32 0, ptr %58, align 8, !tbaa !24
  %59 = load ptr, ptr @corpsehit, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.mobj_s, ptr %59, i32 0, i32 15
  %61 = load i32, ptr %60, align 4, !tbaa !25
  %62 = shl i32 %61, 2
  store i32 %62, ptr %60, align 4, !tbaa !25
  %63 = load ptr, ptr @corpsehit, align 8, !tbaa !5
  %64 = load ptr, ptr @corpsehit, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.mobj_s, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 8, !tbaa !21
  %67 = load ptr, ptr @corpsehit, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.mobj_s, ptr %67, i32 0, i32 2
  %69 = load i32, ptr %68, align 4, !tbaa !22
  %70 = call i32 @P_CheckPosition(ptr noundef %63, i32 noundef %66, i32 noundef %69)
  store i32 %70, ptr %5, align 4, !tbaa !20
  %71 = load ptr, ptr @corpsehit, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.mobj_s, ptr %71, i32 0, i32 15
  %73 = load i32, ptr %72, align 4, !tbaa !25
  %74 = ashr i32 %73, 2
  store i32 %74, ptr %72, align 4, !tbaa !25
  %75 = load i32, ptr %5, align 4, !tbaa !20
  %76 = icmp ne i32 %75, 0
  br i1 %76, label %78, label %77

77:                                               ; preds = %53
  store i32 1, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %79

78:                                               ; preds = %53
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %79

79:                                               ; preds = %78, %77, %52, %26, %18, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %80 = load i32, ptr %2, align 4
  ret i32 %80
}

declare i32 @P_CheckPosition(ptr noundef, i32 noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { "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 #4 = { 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, !12, i64 160}
!10 = !{!"mobj_s", !11, i64 0, !12, i64 24, !12, i64 28, !12, i64 32, !6, i64 40, !6, i64 48, !12, i64 56, !12, i64 60, !12, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !12, i64 96, !12, i64 100, !12, i64 104, !12, i64 108, !12, i64 112, !12, i64 116, !12, i64 120, !12, i64 124, !12, i64 128, !6, i64 136, !12, i64 144, !6, i64 152, !12, i64 160, !12, i64 164, !12, i64 168, !12, i64 172, !6, i64 176, !12, i64 184, !12, i64 188, !6, i64 192, !12, i64 200, !13, i64 204, !6, i64 216}
!11 = !{!"thinker_s", !6, i64 0, !6, i64 8, !7, i64 16}
!12 = !{!"int", !7, i64 0}
!13 = !{!"", !14, i64 0, !14, i64 2, !14, i64 4, !14, i64 6, !14, i64 8}
!14 = !{!"short", !7, i64 0}
!15 = !{!10, !12, i64 144}
!16 = !{!10, !6, i64 136}
!17 = !{!18, !12, i64 88}
!18 = !{!"", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !12, i64 68, !12, i64 72, !12, i64 76, !12, i64 80, !12, i64 84, !12, i64 88}
!19 = !{!18, !12, i64 64}
!20 = !{!12, !12, i64 0}
!21 = !{!10, !12, i64 24}
!22 = !{!10, !12, i64 28}
!23 = !{!10, !12, i64 116}
!24 = !{!10, !12, i64 112}
!25 = !{!10, !12, i64 108}


; 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.mobjinfo_t = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32 }

@mobjinfo = external local_unnamed_addr global [137 x %struct.mobjinfo_t], align 16
@viletryx = external dso_local local_unnamed_addr global i32, align 4
@viletryy = external dso_local local_unnamed_addr global i32, align 4
@corpsehit = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #0

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @PIT_VileCheck(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 160
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = and i32 %3, 1048576
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %43, label %5

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 144
  %7 = load i32, ptr %6, align 8, !tbaa !14
  %.not11 = icmp eq i32 %7, -1
  br i1 %.not11, label %8, label %43

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 136
  %10 = load ptr, ptr %9, align 8, !tbaa !15
  %11 = getelementptr inbounds i8, ptr %10, i64 88
  %12 = load i32, ptr %11, align 4, !tbaa !16
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %43, label %14

14:                                               ; preds = %8
  %15 = getelementptr inbounds i8, ptr %10, i64 64
  %16 = load i32, ptr %15, align 4, !tbaa !18
  %17 = load i32, ptr getelementptr inbounds (i8, ptr @mobjinfo, i64 340), align 4, !tbaa !18
  %18 = add nsw i32 %17, %16
  %19 = getelementptr inbounds i8, ptr %0, i64 24
  %20 = load i32, ptr %19, align 8, !tbaa !19
  %21 = load i32, ptr @viletryx, align 4, !tbaa !20
  %22 = sub nsw i32 %20, %21
  %23 = tail call i32 @llvm.abs.i32(i32 %22, i1 true)
  %24 = icmp sgt i32 %23, %18
  br i1 %24, label %43, label %25

25:                                               ; preds = %14
  %26 = getelementptr inbounds i8, ptr %0, i64 28
  %27 = load i32, ptr %26, align 4, !tbaa !21
  %28 = load i32, ptr @viletryy, align 4, !tbaa !20
  %29 = sub nsw i32 %27, %28
  %30 = tail call i32 @llvm.abs.i32(i32 %29, i1 true)
  %31 = icmp ugt i32 %30, %18
  br i1 %31, label %43, label %32

32:                                               ; preds = %25
  store ptr %0, ptr @corpsehit, align 8, !tbaa !22
  %33 = getelementptr inbounds i8, ptr %0, i64 116
  store i32 0, ptr %33, align 4, !tbaa !23
  %34 = getelementptr inbounds i8, ptr %0, i64 112
  store i32 0, ptr %34, align 8, !tbaa !24
  %35 = getelementptr inbounds i8, ptr %0, i64 108
  %36 = load i32, ptr %35, align 4, !tbaa !25
  %37 = shl i32 %36, 2
  store i32 %37, ptr %35, align 4, !tbaa !25
  %38 = tail call i32 @P_CheckPosition(ptr noundef nonnull %0, i32 noundef %20, i32 noundef %27) #3
  %39 = load ptr, ptr @corpsehit, align 8, !tbaa !22
  %40 = getelementptr inbounds i8, ptr %39, i64 108
  %41 = load i32, ptr %40, align 4, !tbaa !25
  %42 = ashr i32 %41, 2
  store i32 %42, ptr %40, align 4, !tbaa !25
  %.not12 = icmp eq i32 %38, 0
  %. = zext i1 %.not12 to i32
  br label %43

43:                                               ; preds = %32, %14, %25, %8, %5, %1
  %.0 = phi i32 [ 1, %1 ], [ 1, %5 ], [ 1, %8 ], [ 1, %25 ], [ 1, %14 ], [ %., %32 ]
  ret i32 %.0
}

declare i32 @P_CheckPosition(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { "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, !11, i64 160}
!6 = !{!"mobj_s", !7, i64 0, !11, i64 24, !11, i64 28, !11, i64 32, !8, i64 40, !8, i64 48, !11, i64 56, !11, i64 60, !11, i64 64, !8, i64 72, !8, i64 80, !8, i64 88, !11, i64 96, !11, i64 100, !11, i64 104, !11, i64 108, !11, i64 112, !11, i64 116, !11, i64 120, !11, i64 124, !11, i64 128, !8, i64 136, !11, i64 144, !8, i64 152, !11, i64 160, !11, i64 164, !11, i64 168, !11, i64 172, !8, i64 176, !11, i64 184, !11, i64 188, !8, i64 192, !11, i64 200, !12, i64 204, !8, i64 216}
!7 = !{!"thinker_s", !8, i64 0, !8, i64 8, !9, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !13, i64 8}
!13 = !{!"short", !9, i64 0}
!14 = !{!6, !11, i64 144}
!15 = !{!6, !8, i64 136}
!16 = !{!17, !11, i64 88}
!17 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !11, i64 52, !11, i64 56, !11, i64 60, !11, i64 64, !11, i64 68, !11, i64 72, !11, i64 76, !11, i64 80, !11, i64 84, !11, i64 88}
!18 = !{!17, !11, i64 64}
!19 = !{!6, !11, i64 24}
!20 = !{!11, !11, i64 0}
!21 = !{!6, !11, i64 28}
!22 = !{!8, !8, i64 0}
!23 = !{!6, !11, i64 116}
!24 = !{!6, !11, i64 112}
!25 = !{!6, !11, i64 108}


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