; 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.divline_t = type { 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 }
%struct.intercept_t = type { i32, i32, %union.anon }
%union.anon = type { ptr }

@trace = external dso_local global %struct.divline_t, align 4
@intercept_p = 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: nounwind uwtable
declare dso_local i32 @P_PointOnDivlineSide(i32 noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @P_InterceptVector(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @PIT_AddThingIntercepts(ptr noundef %0) #1 {
  %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
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %struct.divline_t, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 16, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  %14 = load i32, ptr getelementptr inbounds (%struct.divline_t, ptr @trace, i32 0, i32 2), align 4, !tbaa !9
  %15 = load i32, ptr getelementptr inbounds (%struct.divline_t, ptr @trace, i32 0, i32 3), align 4, !tbaa !12
  %16 = xor i32 %14, %15
  %17 = icmp sgt i32 %16, 0
  %18 = zext i1 %17 to i32
  store i32 %18, ptr %10, align 4, !tbaa !13
  %19 = load i32, ptr %10, align 4, !tbaa !13
  %20 = icmp ne i32 %19, 0
  br i1 %20, label %21, label %50

21:                                               ; preds = %1
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mobj_s, ptr %22, i32 0, i32 1
  %24 = load i32, ptr %23, align 8, !tbaa !14
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mobj_s, ptr %25, i32 0, i32 14
  %27 = load i32, ptr %26, align 8, !tbaa !19
  %28 = sub nsw i32 %24, %27
  store i32 %28, ptr %4, align 4, !tbaa !13
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mobj_s, ptr %29, i32 0, i32 2
  %31 = load i32, ptr %30, align 4, !tbaa !20
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.mobj_s, ptr %32, i32 0, i32 14
  %34 = load i32, ptr %33, align 8, !tbaa !19
  %35 = add nsw i32 %31, %34
  store i32 %35, ptr %5, align 4, !tbaa !13
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.mobj_s, ptr %36, i32 0, i32 1
  %38 = load i32, ptr %37, align 8, !tbaa !14
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.mobj_s, ptr %39, i32 0, i32 14
  %41 = load i32, ptr %40, align 8, !tbaa !19
  %42 = add nsw i32 %38, %41
  store i32 %42, ptr %6, align 4, !tbaa !13
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.mobj_s, ptr %43, i32 0, i32 2
  %45 = load i32, ptr %44, align 4, !tbaa !20
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.mobj_s, ptr %46, i32 0, i32 14
  %48 = load i32, ptr %47, align 8, !tbaa !19
  %49 = sub nsw i32 %45, %48
  store i32 %49, ptr %7, align 4, !tbaa !13
  br label %79

50:                                               ; preds = %1
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.mobj_s, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 8, !tbaa !14
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.mobj_s, ptr %54, i32 0, i32 14
  %56 = load i32, ptr %55, align 8, !tbaa !19
  %57 = sub nsw i32 %53, %56
  store i32 %57, ptr %4, align 4, !tbaa !13
  %58 = load ptr, ptr %3, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.mobj_s, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 4, !tbaa !20
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.mobj_s, ptr %61, i32 0, i32 14
  %63 = load i32, ptr %62, align 8, !tbaa !19
  %64 = sub nsw i32 %60, %63
  store i32 %64, ptr %5, align 4, !tbaa !13
  %65 = load ptr, ptr %3, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.mobj_s, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 8, !tbaa !14
  %68 = load ptr, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.mobj_s, ptr %68, i32 0, i32 14
  %70 = load i32, ptr %69, align 8, !tbaa !19
  %71 = add nsw i32 %67, %70
  store i32 %71, ptr %6, align 4, !tbaa !13
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.mobj_s, ptr %72, i32 0, i32 2
  %74 = load i32, ptr %73, align 4, !tbaa !20
  %75 = load ptr, ptr %3, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.mobj_s, ptr %75, i32 0, i32 14
  %77 = load i32, ptr %76, align 8, !tbaa !19
  %78 = add nsw i32 %74, %77
  store i32 %78, ptr %7, align 4, !tbaa !13
  br label %79

79:                                               ; preds = %50, %21
  %80 = load i32, ptr %4, align 4, !tbaa !13
  %81 = load i32, ptr %5, align 4, !tbaa !13
  %82 = call i32 @P_PointOnDivlineSide(i32 noundef %80, i32 noundef %81, ptr noundef @trace)
  store i32 %82, ptr %8, align 4, !tbaa !13
  %83 = load i32, ptr %6, align 4, !tbaa !13
  %84 = load i32, ptr %7, align 4, !tbaa !13
  %85 = call i32 @P_PointOnDivlineSide(i32 noundef %83, i32 noundef %84, ptr noundef @trace)
  store i32 %85, ptr %9, align 4, !tbaa !13
  %86 = load i32, ptr %8, align 4, !tbaa !13
  %87 = load i32, ptr %9, align 4, !tbaa !13
  %88 = icmp eq i32 %86, %87
  br i1 %88, label %89, label %90

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

90:                                               ; preds = %79
  %91 = load i32, ptr %4, align 4, !tbaa !13
  %92 = getelementptr inbounds %struct.divline_t, ptr %11, i32 0, i32 0
  store i32 %91, ptr %92, align 4, !tbaa !21
  %93 = load i32, ptr %5, align 4, !tbaa !13
  %94 = getelementptr inbounds %struct.divline_t, ptr %11, i32 0, i32 1
  store i32 %93, ptr %94, align 4, !tbaa !22
  %95 = load i32, ptr %6, align 4, !tbaa !13
  %96 = load i32, ptr %4, align 4, !tbaa !13
  %97 = sub nsw i32 %95, %96
  %98 = getelementptr inbounds %struct.divline_t, ptr %11, i32 0, i32 2
  store i32 %97, ptr %98, align 4, !tbaa !9
  %99 = load i32, ptr %7, align 4, !tbaa !13
  %100 = load i32, ptr %5, align 4, !tbaa !13
  %101 = sub nsw i32 %99, %100
  %102 = getelementptr inbounds %struct.divline_t, ptr %11, i32 0, i32 3
  store i32 %101, ptr %102, align 4, !tbaa !12
  %103 = call i32 @P_InterceptVector(ptr noundef @trace, ptr noundef %11)
  store i32 %103, ptr %12, align 4, !tbaa !13
  %104 = load i32, ptr %12, align 4, !tbaa !13
  %105 = icmp slt i32 %104, 0
  br i1 %105, label %106, label %107

106:                                              ; preds = %90
  store i32 1, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %118

107:                                              ; preds = %90
  %108 = load i32, ptr %12, align 4, !tbaa !13
  %109 = load ptr, ptr @intercept_p, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.intercept_t, ptr %109, i32 0, i32 0
  store i32 %108, ptr %110, align 8, !tbaa !23
  %111 = load ptr, ptr @intercept_p, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.intercept_t, ptr %111, i32 0, i32 1
  store i32 0, ptr %112, align 4, !tbaa !25
  %113 = load ptr, ptr %3, align 8, !tbaa !5
  %114 = load ptr, ptr @intercept_p, align 8, !tbaa !5
  %115 = getelementptr inbounds %struct.intercept_t, ptr %114, i32 0, i32 2
  store ptr %113, ptr %115, align 8, !tbaa !26
  %116 = load ptr, ptr @intercept_p, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.intercept_t, ptr %116, i32 1
  store ptr %117, ptr @intercept_p, align 8, !tbaa !5
  store i32 1, ptr %2, align 4
  store i32 1, ptr %13, align 4
  br label %118

118:                                              ; preds = %107, %106, %89
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %119 = load i32, ptr %2, align 4
  ret i32 %119
}

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


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

@trace = external dso_local global %struct.divline_t, align 4
@intercept_p = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @P_PointOnDivlineSide(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @P_InterceptVector(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @PIT_AddThingIntercepts(ptr noundef %0) local_unnamed_addr #1 {
  %2 = alloca %struct.divline_t, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #2
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @trace, i64 8), align 4, !tbaa !5
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @trace, i64 12), align 4, !tbaa !10
  %5 = xor i32 %4, %3
  %6 = icmp sgt i32 %5, 0
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %0, i64 104
  %10 = load i32, ptr %9, align 8, !tbaa !17
  %11 = sub nsw i32 %8, %10
  %12 = getelementptr inbounds i8, ptr %0, i64 28
  %13 = load i32, ptr %12, align 4, !tbaa !18
  %14 = add nsw i32 %10, %8
  %15 = sub i32 0, %10
  %.035.p = select i1 %6, i32 %15, i32 %10
  %.035 = add i32 %13, %.035.p
  %16 = sub i32 0, %10
  %.033.p = select i1 %6, i32 %10, i32 %16
  %.033 = add i32 %13, %.033.p
  %17 = tail call i32 @P_PointOnDivlineSide(i32 noundef %11, i32 noundef %.033, ptr noundef nonnull @trace)
  %18 = tail call i32 @P_PointOnDivlineSide(i32 noundef %14, i32 noundef %.035, ptr noundef nonnull @trace)
  %19 = icmp eq i32 %17, %18
  br i1 %19, label %33, label %20

20:                                               ; preds = %1
  store i32 %11, ptr %2, align 4, !tbaa !19
  %21 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 %.033, ptr %21, align 4, !tbaa !20
  %22 = sub nsw i32 %14, %11
  %23 = getelementptr inbounds i8, ptr %2, i64 8
  store i32 %22, ptr %23, align 4, !tbaa !5
  %24 = sub nsw i32 %.035, %.033
  %25 = getelementptr inbounds i8, ptr %2, i64 12
  store i32 %24, ptr %25, align 4, !tbaa !10
  %26 = call i32 @P_InterceptVector(ptr noundef nonnull @trace, ptr noundef nonnull %2)
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %33, label %28

28:                                               ; preds = %20
  %29 = load ptr, ptr @intercept_p, align 8, !tbaa !21
  store i32 %26, ptr %29, align 8, !tbaa !22
  %30 = getelementptr inbounds i8, ptr %29, i64 4
  store i32 0, ptr %30, align 4, !tbaa !24
  %31 = getelementptr inbounds i8, ptr %29, i64 8
  store ptr %0, ptr %31, align 8, !tbaa !25
  %32 = getelementptr inbounds i8, ptr %29, i64 16
  store ptr %32, ptr @intercept_p, align 8, !tbaa !21
  br label %33

33:                                               ; preds = %20, %1, %28
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #2
  ret i32 1
}

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


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