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

; 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.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 }
%struct.subsector_s = type { ptr, i16, i16 }
%struct.sector_t = type { i32, i32, i16, i16, i16, i16, i16, i32, ptr, [4 x i32], %struct.degenmobj_t, i32, ptr, ptr, i32, ptr }
%struct.degenmobj_t = type { %struct.thinker_s, i32, i32, i32 }

@bmaporgx = external global i32, align 4
@bmaporgy = external global i32, align 4
@bmapwidth = external global i32, align 4
@bmapheight = external global i32, align 4
@blocklinks = 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

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

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.mobj_s, ptr %11, i32 0, i32 4
  %13 = load ptr, ptr %12, align 8, !tbaa !15
  %14 = icmp ne ptr %13, null
  br i1 %14, label %15, label %23

15:                                               ; preds = %10
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.mobj_s, ptr %16, i32 0, i32 5
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.mobj_s, ptr %19, i32 0, i32 4
  %21 = load ptr, ptr %20, align 8, !tbaa !15
  %22 = getelementptr inbounds %struct.mobj_s, ptr %21, i32 0, i32 5
  store ptr %18, ptr %22, align 8, !tbaa !16
  br label %23

23:                                               ; preds = %15, %10
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.mobj_s, ptr %24, i32 0, i32 5
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %36

28:                                               ; preds = %23
  %29 = load ptr, ptr %2, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mobj_s, ptr %29, i32 0, i32 4
  %31 = load ptr, ptr %30, align 8, !tbaa !15
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.mobj_s, ptr %32, i32 0, i32 5
  %34 = load ptr, ptr %33, align 8, !tbaa !16
  %35 = getelementptr inbounds %struct.mobj_s, ptr %34, i32 0, i32 4
  store ptr %31, ptr %35, align 8, !tbaa !15
  br label %46

36:                                               ; preds = %23
  %37 = load ptr, ptr %2, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.mobj_s, ptr %37, i32 0, i32 4
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mobj_s, ptr %40, i32 0, i32 11
  %42 = load ptr, ptr %41, align 8, !tbaa !17
  %43 = getelementptr inbounds %struct.subsector_s, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !18
  %45 = getelementptr inbounds %struct.sector_t, ptr %44, i32 0, i32 12
  store ptr %39, ptr %45, align 8, !tbaa !20
  br label %46

46:                                               ; preds = %36, %28
  br label %47

47:                                               ; preds = %46, %1
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.mobj_s, ptr %48, i32 0, i32 24
  %50 = load i32, ptr %49, align 8, !tbaa !9
  %51 = and i32 %50, 16
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %119, label %53

53:                                               ; preds = %47
  %54 = load ptr, ptr %2, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.mobj_s, ptr %54, i32 0, i32 9
  %56 = load ptr, ptr %55, align 8, !tbaa !23
  %57 = icmp ne ptr %56, null
  br i1 %57, label %58, label %66

58:                                               ; preds = %53
  %59 = load ptr, ptr %2, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.mobj_s, ptr %59, i32 0, i32 10
  %61 = load ptr, ptr %60, align 8, !tbaa !24
  %62 = load ptr, ptr %2, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.mobj_s, ptr %62, i32 0, i32 9
  %64 = load ptr, ptr %63, align 8, !tbaa !23
  %65 = getelementptr inbounds %struct.mobj_s, ptr %64, i32 0, i32 10
  store ptr %61, ptr %65, align 8, !tbaa !24
  br label %66

66:                                               ; preds = %58, %53
  %67 = load ptr, ptr %2, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.mobj_s, ptr %67, i32 0, i32 10
  %69 = load ptr, ptr %68, align 8, !tbaa !24
  %70 = icmp ne ptr %69, null
  br i1 %70, label %71, label %79

71:                                               ; preds = %66
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.mobj_s, ptr %72, i32 0, i32 9
  %74 = load ptr, ptr %73, align 8, !tbaa !23
  %75 = load ptr, ptr %2, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.mobj_s, ptr %75, i32 0, i32 10
  %77 = load ptr, ptr %76, align 8, !tbaa !24
  %78 = getelementptr inbounds %struct.mobj_s, ptr %77, i32 0, i32 9
  store ptr %74, ptr %78, align 8, !tbaa !23
  br label %118

79:                                               ; preds = %66
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.mobj_s, ptr %80, i32 0, i32 1
  %82 = load i32, ptr %81, align 8, !tbaa !25
  %83 = load i32, ptr @bmaporgx, align 4, !tbaa !26
  %84 = sub nsw i32 %82, %83
  %85 = ashr i32 %84, 23
  store i32 %85, ptr %3, align 4, !tbaa !26
  %86 = load ptr, ptr %2, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.mobj_s, ptr %86, i32 0, i32 2
  %88 = load i32, ptr %87, align 4, !tbaa !27
  %89 = load i32, ptr @bmaporgy, align 4, !tbaa !26
  %90 = sub nsw i32 %88, %89
  %91 = ashr i32 %90, 23
  store i32 %91, ptr %4, align 4, !tbaa !26
  %92 = load i32, ptr %3, align 4, !tbaa !26
  %93 = icmp sge i32 %92, 0
  br i1 %93, label %94, label %117

94:                                               ; preds = %79
  %95 = load i32, ptr %3, align 4, !tbaa !26
  %96 = load i32, ptr @bmapwidth, align 4, !tbaa !26
  %97 = icmp slt i32 %95, %96
  br i1 %97, label %98, label %117

98:                                               ; preds = %94
  %99 = load i32, ptr %4, align 4, !tbaa !26
  %100 = icmp sge i32 %99, 0
  br i1 %100, label %101, label %117

101:                                              ; preds = %98
  %102 = load i32, ptr %4, align 4, !tbaa !26
  %103 = load i32, ptr @bmapheight, align 4, !tbaa !26
  %104 = icmp slt i32 %102, %103
  br i1 %104, label %105, label %117

105:                                              ; preds = %101
  %106 = load ptr, ptr %2, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.mobj_s, ptr %106, i32 0, i32 9
  %108 = load ptr, ptr %107, align 8, !tbaa !23
  %109 = load ptr, ptr @blocklinks, align 8, !tbaa !5
  %110 = load i32, ptr %4, align 4, !tbaa !26
  %111 = load i32, ptr @bmapwidth, align 4, !tbaa !26
  %112 = mul nsw i32 %110, %111
  %113 = load i32, ptr %3, align 4, !tbaa !26
  %114 = add nsw i32 %112, %113
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds ptr, ptr %109, i64 %115
  store ptr %108, ptr %116, align 8, !tbaa !5
  br label %117

117:                                              ; preds = %105, %101, %98, %94, %79
  br label %118

118:                                              ; preds = %117, %71
  br label %119

119:                                              ; preds = %118, %47
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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, !6, i64 40}
!16 = !{!10, !6, i64 48}
!17 = !{!10, !6, i64 88}
!18 = !{!19, !6, i64 0}
!19 = !{!"subsector_s", !6, i64 0, !14, i64 8, !14, i64 10}
!20 = !{!21, !6, i64 96}
!21 = !{!"", !12, i64 0, !12, i64 4, !14, i64 8, !14, i64 10, !14, i64 12, !14, i64 14, !14, i64 16, !12, i64 20, !6, i64 24, !7, i64 32, !22, i64 48, !12, i64 88, !6, i64 96, !6, i64 104, !12, i64 112, !6, i64 120}
!22 = !{!"", !11, i64 0, !12, i64 24, !12, i64 28, !12, i64 32}
!23 = !{!10, !6, i64 72}
!24 = !{!10, !6, i64 80}
!25 = !{!10, !12, i64 24}
!26 = !{!12, !12, i64 0}
!27 = !{!10, !12, 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"

@bmaporgx = external local_unnamed_addr global i32, align 4
@bmaporgy = external local_unnamed_addr global i32, align 4
@bmapwidth = external local_unnamed_addr global i32, align 4
@bmapheight = external local_unnamed_addr global i32, align 4
@blocklinks = external local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @P_UnsetThingPosition(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 160
  %3 = load i32, ptr %2, align 8, !tbaa !5
  %4 = and i32 %3, 8
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %5, label %17

5:                                                ; preds = %1
  %6 = getelementptr inbounds i8, ptr %0, i64 40
  %7 = load ptr, ptr %6, align 8, !tbaa !14
  %.not31 = icmp eq ptr %7, null
  %.phi.trans.insert = getelementptr inbounds i8, ptr %0, i64 48
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !15
  br i1 %.not31, label %._crit_edge, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %7, i64 48
  store ptr %.pre, ptr %9, align 8, !tbaa !15
  br label %._crit_edge

._crit_edge:                                      ; preds = %5, %8
  %.not32 = icmp eq ptr %.pre, null
  br i1 %.not32, label %12, label %10

10:                                               ; preds = %._crit_edge
  %11 = getelementptr inbounds i8, ptr %.pre, i64 40
  br label %.sink.split

12:                                               ; preds = %._crit_edge
  %13 = getelementptr inbounds i8, ptr %0, i64 88
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %15 = load ptr, ptr %14, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %15, i64 96
  br label %.sink.split

.sink.split:                                      ; preds = %12, %10
  %.sink = phi ptr [ %11, %10 ], [ %16, %12 ]
  store ptr %7, ptr %.sink, align 8, !tbaa !19
  br label %17

17:                                               ; preds = %.sink.split, %1
  %18 = and i32 %3, 16
  %.not33 = icmp eq i32 %18, 0
  br i1 %.not33, label %19, label %50

19:                                               ; preds = %17
  %20 = getelementptr inbounds i8, ptr %0, i64 72
  %21 = load ptr, ptr %20, align 8, !tbaa !20
  %.not34 = icmp eq ptr %21, null
  %.phi.trans.insert39 = getelementptr inbounds i8, ptr %0, i64 80
  %.pre40 = load ptr, ptr %.phi.trans.insert39, align 8, !tbaa !21
  br i1 %.not34, label %._crit_edge38, label %22

22:                                               ; preds = %19
  %23 = getelementptr inbounds i8, ptr %21, i64 80
  store ptr %.pre40, ptr %23, align 8, !tbaa !21
  br label %._crit_edge38

._crit_edge38:                                    ; preds = %19, %22
  %.not35 = icmp eq ptr %.pre40, null
  br i1 %.not35, label %26, label %24

24:                                               ; preds = %._crit_edge38
  %25 = getelementptr inbounds i8, ptr %.pre40, i64 72
  br label %.sink.split41

26:                                               ; preds = %._crit_edge38
  %27 = getelementptr inbounds i8, ptr %0, i64 24
  %28 = load i32, ptr %27, align 8, !tbaa !22
  %29 = load i32, ptr @bmaporgx, align 4, !tbaa !23
  %30 = sub nsw i32 %28, %29
  %31 = ashr i32 %30, 23
  %32 = getelementptr inbounds i8, ptr %0, i64 28
  %33 = load i32, ptr %32, align 4, !tbaa !24
  %34 = load i32, ptr @bmaporgy, align 4, !tbaa !23
  %35 = sub nsw i32 %33, %34
  %36 = ashr i32 %35, 23
  %37 = icmp sgt i32 %31, -1
  br i1 %37, label %38, label %50

38:                                               ; preds = %26
  %39 = load i32, ptr @bmapwidth, align 4, !tbaa !23
  %40 = icmp slt i32 %31, %39
  %41 = icmp sgt i32 %36, -1
  %or.cond = select i1 %40, i1 %41, i1 false
  %42 = load i32, ptr @bmapheight, align 4
  %43 = icmp slt i32 %36, %42
  %or.cond37 = select i1 %or.cond, i1 %43, i1 false
  br i1 %or.cond37, label %44, label %50

44:                                               ; preds = %38
  %45 = load ptr, ptr @blocklinks, align 8, !tbaa !19
  %46 = mul nsw i32 %39, %36
  %47 = add nuw nsw i32 %46, %31
  %48 = zext nneg i32 %47 to i64
  %49 = getelementptr inbounds ptr, ptr %45, i64 %48
  br label %.sink.split41

.sink.split41:                                    ; preds = %44, %24
  %.sink42 = phi ptr [ %25, %24 ], [ %49, %44 ]
  store ptr %21, ptr %.sink42, align 8, !tbaa !19
  br label %50

50:                                               ; preds = %.sink.split41, %38, %26, %17
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(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" }

!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, !8, i64 40}
!15 = !{!6, !8, i64 48}
!16 = !{!6, !8, i64 88}
!17 = !{!18, !8, i64 0}
!18 = !{!"subsector_s", !8, i64 0, !13, i64 8, !13, i64 10}
!19 = !{!8, !8, i64 0}
!20 = !{!6, !8, i64 72}
!21 = !{!6, !8, i64 80}
!22 = !{!6, !11, i64 24}
!23 = !{!11, !11, i64 0}
!24 = !{!6, !11, i64 28}


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