; 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.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 }

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

17:                                               ; preds = %3
  %18 = load i32, ptr %5, align 4, !tbaa !5
  %19 = load ptr, ptr %7, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.line_s, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !14
  %22 = getelementptr inbounds %struct.vertex_t, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 4, !tbaa !15
  %24 = icmp sle i32 %18, %23
  br i1 %24, label %25, label %31

25:                                               ; preds = %17
  %26 = load ptr, ptr %7, align 8, !tbaa !9
  %27 = getelementptr inbounds %struct.line_s, ptr %26, i32 0, i32 3
  %28 = load i32, ptr %27, align 4, !tbaa !17
  %29 = icmp sgt i32 %28, 0
  %30 = zext i1 %29 to i32
  store i32 %30, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %94

31:                                               ; preds = %17
  %32 = load ptr, ptr %7, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.line_s, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 4, !tbaa !17
  %35 = icmp slt i32 %34, 0
  %36 = zext i1 %35 to i32
  store i32 %36, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %94

37:                                               ; preds = %3
  %38 = load ptr, ptr %7, align 8, !tbaa !9
  %39 = getelementptr inbounds %struct.line_s, ptr %38, i32 0, i32 3
  %40 = load i32, ptr %39, align 4, !tbaa !17
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %62, label %42

42:                                               ; preds = %37
  %43 = load i32, ptr %6, align 4, !tbaa !5
  %44 = load ptr, ptr %7, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.line_s, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !14
  %47 = getelementptr inbounds %struct.vertex_t, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !18
  %49 = icmp sle i32 %43, %48
  br i1 %49, label %50, label %56

50:                                               ; preds = %42
  %51 = load ptr, ptr %7, align 8, !tbaa !9
  %52 = getelementptr inbounds %struct.line_s, ptr %51, i32 0, i32 2
  %53 = load i32, ptr %52, align 8, !tbaa !11
  %54 = icmp slt i32 %53, 0
  %55 = zext i1 %54 to i32
  store i32 %55, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %94

56:                                               ; preds = %42
  %57 = load ptr, ptr %7, align 8, !tbaa !9
  %58 = getelementptr inbounds %struct.line_s, ptr %57, i32 0, i32 2
  %59 = load i32, ptr %58, align 8, !tbaa !11
  %60 = icmp sgt i32 %59, 0
  %61 = zext i1 %60 to i32
  store i32 %61, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %94

62:                                               ; preds = %37
  %63 = load i32, ptr %5, align 4, !tbaa !5
  %64 = load ptr, ptr %7, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.line_s, ptr %64, i32 0, i32 0
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  %67 = getelementptr inbounds %struct.vertex_t, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %67, align 4, !tbaa !15
  %69 = sub nsw i32 %63, %68
  store i32 %69, ptr %8, align 4, !tbaa !5
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = load ptr, ptr %7, align 8, !tbaa !9
  %72 = getelementptr inbounds %struct.line_s, ptr %71, i32 0, i32 0
  %73 = load ptr, ptr %72, align 8, !tbaa !14
  %74 = getelementptr inbounds %struct.vertex_t, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 4, !tbaa !18
  %76 = sub nsw i32 %70, %75
  store i32 %76, ptr %9, align 4, !tbaa !5
  %77 = load ptr, ptr %7, align 8, !tbaa !9
  %78 = getelementptr inbounds %struct.line_s, ptr %77, i32 0, i32 3
  %79 = load i32, ptr %78, align 4, !tbaa !17
  %80 = ashr i32 %79, 16
  %81 = load i32, ptr %8, align 4, !tbaa !5
  %82 = call i32 @FixedMul(i32 noundef %80, i32 noundef %81)
  store i32 %82, ptr %10, align 4, !tbaa !5
  %83 = load i32, ptr %9, align 4, !tbaa !5
  %84 = load ptr, ptr %7, align 8, !tbaa !9
  %85 = getelementptr inbounds %struct.line_s, ptr %84, i32 0, i32 2
  %86 = load i32, ptr %85, align 8, !tbaa !11
  %87 = ashr i32 %86, 16
  %88 = call i32 @FixedMul(i32 noundef %83, i32 noundef %87)
  store i32 %88, ptr %11, align 4, !tbaa !5
  %89 = load i32, ptr %11, align 4, !tbaa !5
  %90 = load i32, ptr %10, align 4, !tbaa !5
  %91 = icmp slt i32 %89, %90
  br i1 %91, label %92, label %93

92:                                               ; preds = %62
  store i32 0, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %94

93:                                               ; preds = %62
  store i32 1, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %94

94:                                               ; preds = %93, %92, %56, %50, %31, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %95 = load i32, ptr %4, align 4
  ret i32 %95
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @FixedMul(i32 noundef, i32 noundef) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = { 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"line_s", !10, i64 0, !10, i64 8, !6, i64 16, !6, i64 20, !13, i64 24, !13, i64 26, !13, i64 28, !7, i64 30, !7, i64 36, !6, i64 52, !10, i64 56, !10, i64 64, !6, i64 72, !10, i64 80}
!13 = !{!"short", !7, i64 0}
!14 = !{!12, !10, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"", !6, i64 0, !6, i64 4}
!17 = !{!12, !6, i64 20}
!18 = !{!16, !6, i64 4}


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

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @P_PointOnLineSide(i32 noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %2, i64 16
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %6, label %15

6:                                                ; preds = %3
  %7 = load ptr, ptr %2, align 8, !tbaa !12
  %8 = load i32, ptr %7, align 4, !tbaa !13
  %.not22 = icmp slt i32 %8, %0
  %9 = getelementptr inbounds i8, ptr %2, i64 20
  %10 = load i32, ptr %9, align 4, !tbaa !15
  br i1 %.not22, label %14, label %11

11:                                               ; preds = %6
  %12 = icmp sgt i32 %10, 0
  %13 = zext i1 %12 to i32
  br label %38

14:                                               ; preds = %6
  %.lobit = lshr i32 %10, 31
  br label %38

15:                                               ; preds = %3
  %16 = getelementptr inbounds i8, ptr %2, i64 20
  %17 = load i32, ptr %16, align 4, !tbaa !15
  %.not23 = icmp eq i32 %17, 0
  %18 = load ptr, ptr %2, align 8, !tbaa !12
  br i1 %.not23, label %19, label %26

19:                                               ; preds = %15
  %20 = getelementptr inbounds i8, ptr %18, i64 4
  %21 = load i32, ptr %20, align 4, !tbaa !16
  %.not24 = icmp slt i32 %21, %1
  br i1 %.not24, label %23, label %22

22:                                               ; preds = %19
  %.lobit25 = lshr i32 %5, 31
  br label %38

23:                                               ; preds = %19
  %24 = icmp sgt i32 %5, 0
  %25 = zext i1 %24 to i32
  br label %38

26:                                               ; preds = %15
  %27 = load i32, ptr %18, align 4, !tbaa !13
  %28 = sub nsw i32 %0, %27
  %29 = getelementptr inbounds i8, ptr %18, i64 4
  %30 = load i32, ptr %29, align 4, !tbaa !16
  %31 = sub nsw i32 %1, %30
  %32 = ashr i32 %17, 16
  %33 = tail call i32 @FixedMul(i32 noundef %32, i32 noundef %28)
  %34 = load i32, ptr %4, align 8, !tbaa !5
  %35 = ashr i32 %34, 16
  %36 = tail call i32 @FixedMul(i32 noundef %31, i32 noundef %35)
  %37 = icmp sge i32 %36, %33
  %. = zext i1 %37 to i32
  br label %38

38:                                               ; preds = %26, %23, %22, %14, %11
  %.0 = phi i32 [ %.lobit25, %22 ], [ %25, %23 ], [ %13, %11 ], [ %.lobit, %14 ], [ %., %26 ]
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @FixedMul(i32 noundef, i32 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 = { inlinehint 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" }

!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, !10, i64 16}
!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 = !{!6, !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !10, i64 4}
!15 = !{!6, !10, i64 20}
!16 = !{!14, !10, i64 4}


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