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

; 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.line_s = type { ptr, ptr, i32, i32, i16, i16, i16, [2 x i16], [4 x i32], i32, ptr, ptr, i32, ptr }
%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 }

@tmthing = external dso_local global ptr, align 8
@tmbbox = external dso_local global [4 x i32], align 16
@ceilingline = external dso_local global ptr, align 8
@tmdropoffz = external dso_local global i32, align 4
@tmfloorz = external dso_local global i32, align 4
@tmceilingz = external dso_local global i32, align 4
@numspechit = external dso_local global i32, align 4
@opentop = external global i32, align 4
@openbottom = external global i32, align 4
@lowfloor = external global i32, align 4
@spechit = external dso_local global [8 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @PIT_CheckLine(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @tmbbox, i64 0, i64 3), align 4, !tbaa !9
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct.line_s, ptr %5, i32 0, i32 8
  %7 = getelementptr inbounds [4 x i32], ptr %6, i64 0, i64 2
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = icmp sle i32 %4, %8
  br i1 %9, label %31, label %10

10:                                               ; preds = %1
  %11 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @tmbbox, i64 0, i64 2), align 8, !tbaa !9
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.line_s, ptr %12, i32 0, i32 8
  %14 = getelementptr inbounds [4 x i32], ptr %13, i64 0, i64 3
  %15 = load i32, ptr %14, align 4, !tbaa !9
  %16 = icmp sge i32 %11, %15
  br i1 %16, label %31, label %17

17:                                               ; preds = %10
  %18 = load i32, ptr @tmbbox, align 16, !tbaa !9
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.line_s, ptr %19, i32 0, i32 8
  %21 = getelementptr inbounds [4 x i32], ptr %20, i64 0, i64 1
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = icmp sle i32 %18, %22
  br i1 %23, label %31, label %24

24:                                               ; preds = %17
  %25 = load i32, ptr getelementptr inbounds ([4 x i32], ptr @tmbbox, i64 0, i64 1), align 4, !tbaa !9
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.line_s, ptr %26, i32 0, i32 8
  %28 = getelementptr inbounds [4 x i32], ptr %27, i64 0, i64 0
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = icmp sge i32 %25, %29
  br i1 %30, label %31, label %32

31:                                               ; preds = %24, %17, %10, %1
  store i32 1, ptr %2, align 4
  br label %104

32:                                               ; preds = %24
  %33 = load ptr, ptr %3, align 8, !tbaa !5
  %34 = call i32 @P_BoxOnLineSide(ptr noundef @tmbbox, ptr noundef %33)
  %35 = icmp ne i32 %34, -1
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  store i32 1, ptr %2, align 4
  br label %104

37:                                               ; preds = %32
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.line_s, ptr %38, i32 0, i32 11
  %40 = load ptr, ptr %39, align 8, !tbaa !11
  %41 = icmp ne ptr %40, null
  br i1 %41, label %43, label %42

42:                                               ; preds = %37
  store i32 0, ptr %2, align 4
  br label %104

43:                                               ; preds = %37
  %44 = load ptr, ptr @tmthing, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.mobj_s, ptr %44, i32 0, i32 24
  %46 = load i32, ptr %45, align 8, !tbaa !14
  %47 = and i32 %46, 65536
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %71, label %49

49:                                               ; preds = %43
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.line_s, ptr %50, i32 0, i32 4
  %52 = load i16, ptr %51, align 8, !tbaa !18
  %53 = sext i16 %52 to i32
  %54 = and i32 %53, 1
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %49
  store i32 0, ptr %2, align 4
  br label %104

57:                                               ; preds = %49
  %58 = load ptr, ptr @tmthing, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.mobj_s, ptr %58, i32 0, i32 31
  %60 = load ptr, ptr %59, align 8, !tbaa !19
  %61 = icmp ne ptr %60, null
  br i1 %61, label %70, label %62

62:                                               ; preds = %57
  %63 = load ptr, ptr %3, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.line_s, ptr %63, i32 0, i32 4
  %65 = load i16, ptr %64, align 8, !tbaa !18
  %66 = sext i16 %65 to i32
  %67 = and i32 %66, 2
  %68 = icmp ne i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %62
  store i32 0, ptr %2, align 4
  br label %104

70:                                               ; preds = %62, %57
  br label %71

71:                                               ; preds = %70, %43
  %72 = load ptr, ptr %3, align 8, !tbaa !5
  call void @P_LineOpening(ptr noundef %72)
  %73 = load i32, ptr @opentop, align 4, !tbaa !9
  %74 = load i32, ptr @tmceilingz, align 4, !tbaa !9
  %75 = icmp slt i32 %73, %74
  br i1 %75, label %76, label %79

76:                                               ; preds = %71
  %77 = load i32, ptr @opentop, align 4, !tbaa !9
  store i32 %77, ptr @tmceilingz, align 4, !tbaa !9
  %78 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %78, ptr @ceilingline, align 8, !tbaa !5
  br label %79

79:                                               ; preds = %76, %71
  %80 = load i32, ptr @openbottom, align 4, !tbaa !9
  %81 = load i32, ptr @tmfloorz, align 4, !tbaa !9
  %82 = icmp sgt i32 %80, %81
  br i1 %82, label %83, label %85

83:                                               ; preds = %79
  %84 = load i32, ptr @openbottom, align 4, !tbaa !9
  store i32 %84, ptr @tmfloorz, align 4, !tbaa !9
  br label %85

85:                                               ; preds = %83, %79
  %86 = load i32, ptr @lowfloor, align 4, !tbaa !9
  %87 = load i32, ptr @tmdropoffz, align 4, !tbaa !9
  %88 = icmp slt i32 %86, %87
  br i1 %88, label %89, label %91

89:                                               ; preds = %85
  %90 = load i32, ptr @lowfloor, align 4, !tbaa !9
  store i32 %90, ptr @tmdropoffz, align 4, !tbaa !9
  br label %91

91:                                               ; preds = %89, %85
  %92 = load ptr, ptr %3, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.line_s, ptr %92, i32 0, i32 5
  %94 = load i16, ptr %93, align 2, !tbaa !20
  %95 = icmp ne i16 %94, 0
  br i1 %95, label %96, label %103

96:                                               ; preds = %91
  %97 = load ptr, ptr %3, align 8, !tbaa !5
  %98 = load i32, ptr @numspechit, align 4, !tbaa !9
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [8 x ptr], ptr @spechit, i64 0, i64 %99
  store ptr %97, ptr %100, align 8, !tbaa !5
  %101 = load i32, ptr @numspechit, align 4, !tbaa !9
  %102 = add nsw i32 %101, 1
  store i32 %102, ptr @numspechit, align 4, !tbaa !9
  br label %103

103:                                              ; preds = %96, %91
  store i32 1, ptr %2, align 4
  br label %104

104:                                              ; preds = %103, %69, %56, %42, %36, %31
  %105 = load i32, ptr %2, align 4
  ret i32 %105
}

declare i32 @P_BoxOnLineSide(ptr noundef, ptr noundef) #1

declare void @P_LineOpening(ptr noundef) #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" }

!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, !6, i64 64}
!12 = !{!"line_s", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !13, i64 24, !13, i64 26, !13, i64 28, !7, i64 30, !7, i64 36, !10, i64 52, !6, i64 56, !6, i64 64, !10, i64 72, !6, i64 80}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !10, i64 160}
!15 = !{!"mobj_s", !16, 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, !17, i64 204, !6, i64 216}
!16 = !{!"thinker_s", !6, i64 0, !6, i64 8, !7, i64 16}
!17 = !{!"", !13, i64 0, !13, i64 2, !13, i64 4, !13, i64 6, !13, i64 8}
!18 = !{!12, !13, i64 24}
!19 = !{!15, !6, i64 192}
!20 = !{!12, !13, i64 26}


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

@tmthing = external dso_local local_unnamed_addr global ptr, align 8
@tmbbox = external dso_local global [4 x i32], align 16
@ceilingline = external dso_local local_unnamed_addr global ptr, align 8
@tmdropoffz = external dso_local local_unnamed_addr global i32, align 4
@tmfloorz = external dso_local local_unnamed_addr global i32, align 4
@tmceilingz = external dso_local local_unnamed_addr global i32, align 4
@numspechit = external dso_local local_unnamed_addr global i32, align 4
@opentop = external local_unnamed_addr global i32, align 4
@openbottom = external local_unnamed_addr global i32, align 4
@lowfloor = external local_unnamed_addr global i32, align 4
@spechit = external dso_local local_unnamed_addr global [8 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @PIT_CheckLine(ptr noundef %0) local_unnamed_addr #0 {
  %2 = load i32, ptr getelementptr inbounds (i8, ptr @tmbbox, i64 12), align 4, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 36
  %4 = getelementptr inbounds i8, ptr %0, i64 44
  %5 = load i32, ptr %4, align 4, !tbaa !5
  %.not = icmp sgt i32 %2, %5
  br i1 %.not, label %6, label %59

6:                                                ; preds = %1
  %7 = load i32, ptr getelementptr inbounds (i8, ptr @tmbbox, i64 8), align 8, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 48
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not15 = icmp slt i32 %7, %9
  br i1 %.not15, label %10, label %59

10:                                               ; preds = %6
  %11 = load i32, ptr @tmbbox, align 16, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 40
  %13 = load i32, ptr %12, align 4, !tbaa !5
  %.not16 = icmp sgt i32 %11, %13
  br i1 %.not16, label %14, label %59

14:                                               ; preds = %10
  %15 = load i32, ptr getelementptr inbounds (i8, ptr @tmbbox, i64 4), align 4, !tbaa !5
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %.not17 = icmp slt i32 %15, %16
  br i1 %.not17, label %17, label %59

17:                                               ; preds = %14
  %18 = tail call i32 @P_BoxOnLineSide(ptr noundef nonnull @tmbbox, ptr noundef nonnull %0) #2
  %.not18 = icmp eq i32 %18, -1
  br i1 %.not18, label %19, label %59

19:                                               ; preds = %17
  %20 = getelementptr inbounds i8, ptr %0, i64 64
  %21 = load ptr, ptr %20, align 8, !tbaa !9
  %.not19 = icmp eq ptr %21, null
  br i1 %.not19, label %59, label %22

22:                                               ; preds = %19
  %23 = load ptr, ptr @tmthing, align 8, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %23, i64 160
  %25 = load i32, ptr %24, align 8, !tbaa !14
  %26 = and i32 %25, 65536
  %.not20 = icmp eq i32 %26, 0
  br i1 %.not20, label %27, label %36

27:                                               ; preds = %22
  %28 = getelementptr inbounds i8, ptr %0, i64 24
  %29 = load i16, ptr %28, align 8, !tbaa !18
  %30 = zext i16 %29 to i32
  %31 = and i32 %30, 1
  %.not21 = icmp eq i32 %31, 0
  br i1 %.not21, label %32, label %59

32:                                               ; preds = %27
  %33 = getelementptr inbounds i8, ptr %23, i64 192
  %34 = load ptr, ptr %33, align 8, !tbaa !19
  %.not22 = icmp ne ptr %34, null
  %35 = and i32 %30, 2
  %.not23 = icmp eq i32 %35, 0
  %or.cond = or i1 %.not23, %.not22
  br i1 %or.cond, label %36, label %59

36:                                               ; preds = %32, %22
  tail call void @P_LineOpening(ptr noundef nonnull %0) #2
  %37 = load i32, ptr @opentop, align 4, !tbaa !5
  %38 = load i32, ptr @tmceilingz, align 4, !tbaa !5
  %39 = icmp slt i32 %37, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %36
  store i32 %37, ptr @tmceilingz, align 4, !tbaa !5
  store ptr %0, ptr @ceilingline, align 8, !tbaa !13
  br label %41

41:                                               ; preds = %40, %36
  %42 = load i32, ptr @openbottom, align 4, !tbaa !5
  %43 = load i32, ptr @tmfloorz, align 4, !tbaa !5
  %44 = icmp sgt i32 %42, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %41
  store i32 %42, ptr @tmfloorz, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %45, %41
  %47 = load i32, ptr @lowfloor, align 4, !tbaa !5
  %48 = load i32, ptr @tmdropoffz, align 4, !tbaa !5
  %49 = icmp slt i32 %47, %48
  br i1 %49, label %50, label %51

50:                                               ; preds = %46
  store i32 %47, ptr @tmdropoffz, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %50, %46
  %52 = getelementptr inbounds i8, ptr %0, i64 26
  %53 = load i16, ptr %52, align 2, !tbaa !20
  %.not24 = icmp eq i16 %53, 0
  br i1 %.not24, label %59, label %54

54:                                               ; preds = %51
  %55 = load i32, ptr @numspechit, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [8 x ptr], ptr @spechit, i64 0, i64 %56
  store ptr %0, ptr %57, align 8, !tbaa !13
  %58 = add nsw i32 %55, 1
  store i32 %58, ptr @numspechit, align 4, !tbaa !5
  br label %59

59:                                               ; preds = %51, %54, %32, %27, %19, %17, %1, %6, %10, %14
  %.0 = phi i32 [ 1, %14 ], [ 1, %10 ], [ 1, %6 ], [ 1, %1 ], [ 1, %17 ], [ 0, %19 ], [ 0, %27 ], [ 0, %32 ], [ 1, %54 ], [ 1, %51 ]
  ret i32 %.0
}

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

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


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