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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @P_PointOnLineSide(i32 noundef, i32 noundef, ptr 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
declare dso_local i32 @P_PointOnDivlineSide(i32 noundef, i32 noundef, ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @PIT_AddLineIntercepts(ptr noundef %0) #0 {
  %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 %struct.divline_t, align 4
  %8 = 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 16, ptr %7) #2
  %9 = load i32, ptr getelementptr inbounds (%struct.divline_t, ptr @trace, i32 0, i32 2), align 4, !tbaa !9
  %10 = icmp sgt i32 %9, 1048576
  br i1 %10, label %20, label %11

11:                                               ; preds = %1
  %12 = load i32, ptr getelementptr inbounds (%struct.divline_t, ptr @trace, i32 0, i32 3), align 4, !tbaa !12
  %13 = icmp sgt i32 %12, 1048576
  br i1 %13, label %20, label %14

14:                                               ; preds = %11
  %15 = load i32, ptr getelementptr inbounds (%struct.divline_t, ptr @trace, i32 0, i32 2), align 4, !tbaa !9
  %16 = icmp slt i32 %15, -1048576
  br i1 %16, label %20, label %17

17:                                               ; preds = %14
  %18 = load i32, ptr getelementptr inbounds (%struct.divline_t, ptr @trace, i32 0, i32 3), align 4, !tbaa !12
  %19 = icmp slt i32 %18, -1048576
  br i1 %19, label %20, label %43

20:                                               ; preds = %17, %14, %11, %1
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.line_s, ptr %21, i32 0, i32 0
  %23 = load ptr, ptr %22, align 8, !tbaa !13
  %24 = getelementptr inbounds %struct.vertex_t, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %24, align 4, !tbaa !16
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.line_s, ptr %26, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !13
  %29 = getelementptr inbounds %struct.vertex_t, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !18
  %31 = call i32 @P_PointOnDivlineSide(i32 noundef %25, i32 noundef %30, ptr noundef @trace)
  store i32 %31, ptr %4, align 4, !tbaa !19
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.line_s, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !20
  %35 = getelementptr inbounds %struct.vertex_t, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 4, !tbaa !16
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.line_s, ptr %37, i32 0, i32 1
  %39 = load ptr, ptr %38, align 8, !tbaa !20
  %40 = getelementptr inbounds %struct.vertex_t, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !18
  %42 = call i32 @P_PointOnDivlineSide(i32 noundef %36, i32 noundef %41, ptr noundef @trace)
  store i32 %42, ptr %5, align 4, !tbaa !19
  br label %56

43:                                               ; preds = %17
  %44 = load i32, ptr @trace, align 4, !tbaa !21
  %45 = load i32, ptr getelementptr inbounds (%struct.divline_t, ptr @trace, i32 0, i32 1), align 4, !tbaa !22
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = call i32 @P_PointOnLineSide(i32 noundef %44, i32 noundef %45, ptr noundef %46)
  store i32 %47, ptr %4, align 4, !tbaa !19
  %48 = load i32, ptr @trace, align 4, !tbaa !21
  %49 = load i32, ptr getelementptr inbounds (%struct.divline_t, ptr @trace, i32 0, i32 2), align 4, !tbaa !9
  %50 = add nsw i32 %48, %49
  %51 = load i32, ptr getelementptr inbounds (%struct.divline_t, ptr @trace, i32 0, i32 1), align 4, !tbaa !22
  %52 = load i32, ptr getelementptr inbounds (%struct.divline_t, ptr @trace, i32 0, i32 3), align 4, !tbaa !12
  %53 = add nsw i32 %51, %52
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = call i32 @P_PointOnLineSide(i32 noundef %50, i32 noundef %53, ptr noundef %54)
  store i32 %55, ptr %5, align 4, !tbaa !19
  br label %56

56:                                               ; preds = %43, %20
  %57 = load i32, ptr %4, align 4, !tbaa !19
  %58 = load i32, ptr %5, align 4, !tbaa !19
  %59 = icmp eq i32 %57, %58
  br i1 %59, label %60, label %61

60:                                               ; preds = %56
  store i32 1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %90

61:                                               ; preds = %56
  %62 = load ptr, ptr %3, align 8, !tbaa !5
  call void @P_MakeDivline(ptr noundef %62, ptr noundef %7)
  %63 = call i32 @P_InterceptVector(ptr noundef @trace, ptr noundef %7)
  store i32 %63, ptr %6, align 4, !tbaa !19
  %64 = load i32, ptr %6, align 4, !tbaa !19
  %65 = icmp slt i32 %64, 0
  br i1 %65, label %66, label %67

66:                                               ; preds = %61
  store i32 1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %90

67:                                               ; preds = %61
  %68 = load i32, ptr @earlyout, align 4, !tbaa !19
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %79

70:                                               ; preds = %67
  %71 = load i32, ptr %6, align 4, !tbaa !19
  %72 = icmp slt i32 %71, 65536
  br i1 %72, label %73, label %79

73:                                               ; preds = %70
  %74 = load ptr, ptr %3, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.line_s, ptr %74, i32 0, i32 11
  %76 = load ptr, ptr %75, align 8, !tbaa !23
  %77 = icmp ne ptr %76, null
  br i1 %77, label %79, label %78

78:                                               ; preds = %73
  store i32 0, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %90

79:                                               ; preds = %73, %70, %67
  %80 = load i32, ptr %6, align 4, !tbaa !19
  %81 = load ptr, ptr @intercept_p, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.intercept_t, ptr %81, i32 0, i32 0
  store i32 %80, ptr %82, align 8, !tbaa !24
  %83 = load ptr, ptr @intercept_p, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.intercept_t, ptr %83, i32 0, i32 1
  store i32 1, ptr %84, align 4, !tbaa !26
  %85 = load ptr, ptr %3, align 8, !tbaa !5
  %86 = load ptr, ptr @intercept_p, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.intercept_t, ptr %86, i32 0, i32 2
  store ptr %85, ptr %87, align 8, !tbaa !27
  %88 = load ptr, ptr @intercept_p, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.intercept_t, ptr %88, i32 1
  store ptr %89, ptr @intercept_p, align 8, !tbaa !5
  store i32 1, ptr %2, align 4
  store i32 1, ptr %8, align 4
  br label %90

90:                                               ; preds = %79, %78, %66, %60
  call void @llvm.lifetime.end.p0(i64 16, 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
  %91 = load i32, ptr %2, align 4
  ret i32 %91
}

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 = { 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 = !{!14, !6, i64 0}
!14 = !{!"line_s", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !15, i64 24, !15, i64 26, !15, i64 28, !7, i64 30, !7, i64 36, !11, i64 52, !6, i64 56, !6, i64 64, !11, i64 72, !6, i64 80}
!15 = !{!"short", !7, i64 0}
!16 = !{!17, !11, i64 0}
!17 = !{!"", !11, i64 0, !11, i64 4}
!18 = !{!17, !11, i64 4}
!19 = !{!11, !11, i64 0}
!20 = !{!14, !6, i64 8}
!21 = !{!10, !11, i64 0}
!22 = !{!10, !11, i64 4}
!23 = !{!14, !6, i64 64}
!24 = !{!25, !11, i64 0}
!25 = !{!"", !11, i64 0, !11, i64 4, !7, i64 8}
!26 = !{!25, !11, i64 4}
!27 = !{!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
@earlyout = external dso_local local_unnamed_addr global i32, align 4
@intercept_p = external dso_local local_unnamed_addr global ptr, align 8

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @PIT_AddLineIntercepts(ptr noundef %0) local_unnamed_addr #0 {
  %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
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @trace, i64 12), align 4
  %5 = add i32 %3, -1048577
  %6 = icmp ult i32 %5, -2097153
  %7 = add i32 %4, -1048577
  %8 = icmp ult i32 %7, -2097153
  %or.cond5 = select i1 %6, i1 true, i1 %8
  br i1 %or.cond5, label %9, label %21

9:                                                ; preds = %1
  %10 = load ptr, ptr %0, align 8, !tbaa !5
  %11 = load i32, ptr %10, align 4, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %10, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !14
  %14 = tail call i32 @P_PointOnDivlineSide(i32 noundef %11, i32 noundef %13, ptr noundef nonnull @trace)
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load ptr, ptr %15, align 8, !tbaa !15
  %17 = load i32, ptr %16, align 4, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %16, i64 4
  %19 = load i32, ptr %18, align 4, !tbaa !14
  %20 = tail call i32 @P_PointOnDivlineSide(i32 noundef %17, i32 noundef %19, ptr noundef nonnull @trace)
  br label %32

21:                                               ; preds = %1
  %22 = load i32, ptr @trace, align 4, !tbaa !16
  %23 = load i32, ptr getelementptr inbounds (i8, ptr @trace, i64 4), align 4, !tbaa !18
  %24 = tail call i32 @P_PointOnLineSide(i32 noundef %22, i32 noundef %23, ptr noundef %0)
  %25 = load i32, ptr @trace, align 4, !tbaa !16
  %26 = load i32, ptr getelementptr inbounds (i8, ptr @trace, i64 8), align 4, !tbaa !19
  %27 = add nsw i32 %26, %25
  %28 = load i32, ptr getelementptr inbounds (i8, ptr @trace, i64 4), align 4, !tbaa !18
  %29 = load i32, ptr getelementptr inbounds (i8, ptr @trace, i64 12), align 4, !tbaa !20
  %30 = add nsw i32 %29, %28
  %31 = tail call i32 @P_PointOnLineSide(i32 noundef %27, i32 noundef %30, ptr noundef %0)
  br label %32

32:                                               ; preds = %21, %9
  %.022 = phi i32 [ %14, %9 ], [ %24, %21 ]
  %.021 = phi i32 [ %20, %9 ], [ %31, %21 ]
  %33 = icmp eq i32 %.022, %.021
  br i1 %33, label %49, label %34

34:                                               ; preds = %32
  call void @P_MakeDivline(ptr noundef %0, ptr noundef nonnull %2)
  %35 = call i32 @P_InterceptVector(ptr noundef nonnull @trace, ptr noundef nonnull %2)
  %36 = icmp slt i32 %35, 0
  br i1 %36, label %49, label %37

37:                                               ; preds = %34
  %38 = load i32, ptr @earlyout, align 4, !tbaa !21
  %39 = icmp ne i32 %38, 0
  %40 = icmp ult i32 %35, 65536
  %or.cond7 = and i1 %40, %39
  br i1 %or.cond7, label %41, label %44

41:                                               ; preds = %37
  %42 = getelementptr inbounds i8, ptr %0, i64 64
  %43 = load ptr, ptr %42, align 8, !tbaa !22
  %.not = icmp eq ptr %43, null
  br i1 %.not, label %49, label %44

44:                                               ; preds = %41, %37
  %45 = load ptr, ptr @intercept_p, align 8, !tbaa !23
  store i32 %35, ptr %45, align 8, !tbaa !24
  %46 = getelementptr inbounds i8, ptr %45, i64 4
  store i32 1, ptr %46, align 4, !tbaa !26
  %47 = getelementptr inbounds i8, ptr %45, i64 8
  store ptr %0, ptr %47, align 8, !tbaa !27
  %48 = getelementptr inbounds i8, ptr %45, i64 16
  store ptr %48, ptr @intercept_p, align 8, !tbaa !23
  br label %49

49:                                               ; preds = %41, %34, %32, %44
  %.0 = phi i32 [ 1, %44 ], [ 1, %32 ], [ 1, %34 ], [ 0, %41 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #2
  ret i32 %.0
}

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 0}
!6 = !{!"line_s", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !11, i64 24, !11, i64 26, !11, i64 28, !8, i64 30, !8, i64 36, !10, i64 52, !7, i64 56, !7, i64 64, !10, i64 72, !7, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"short", !8, i64 0}
!12 = !{!13, !10, i64 0}
!13 = !{!"", !10, i64 0, !10, i64 4}
!14 = !{!13, !10, i64 4}
!15 = !{!6, !7, i64 8}
!16 = !{!17, !10, i64 0}
!17 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!18 = !{!17, !10, i64 4}
!19 = !{!17, !10, i64 8}
!20 = !{!17, !10, i64 12}
!21 = !{!10, !10, i64 0}
!22 = !{!6, !7, i64 64}
!23 = !{!7, !7, i64 0}
!24 = !{!25, !10, i64 0}
!25 = !{!"", !10, i64 0, !10, i64 4, !8, i64 8}
!26 = !{!25, !10, i64 4}
!27 = !{!8, !8, i64 0}


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