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

@tmymove = external dso_local global i32, align 4
@tmxmove = external dso_local global i32, align 4
@slidemo = external dso_local global ptr, align 8
@finecosine = external global ptr, align 8
@finesine = external global [10240 x i32], align 16

; 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

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

; Function Attrs: nounwind uwtable
define dso_local void @P_HitSlideLine(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %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
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.line_s, ptr %10, i32 0, i32 9
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %1
  store i32 0, ptr @tmymove, align 4, !tbaa !13
  store i32 1, ptr %9, align 4
  br label %82

15:                                               ; preds = %1
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.line_s, ptr %16, i32 0, i32 9
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 1
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store i32 0, ptr @tmxmove, align 4, !tbaa !13
  store i32 1, ptr %9, align 4
  br label %82

21:                                               ; preds = %15
  %22 = load ptr, ptr @slidemo, 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 @slidemo, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mobj_s, ptr %25, i32 0, i32 2
  %27 = load i32, ptr %26, align 4, !tbaa !18
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = call i32 @P_PointOnLineSide(i32 noundef %24, i32 noundef %27, ptr noundef %28)
  store i32 %29, ptr %3, align 4, !tbaa !13
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.line_s, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 8, !tbaa !19
  %33 = load ptr, ptr %2, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.line_s, ptr %33, i32 0, i32 3
  %35 = load i32, ptr %34, align 4, !tbaa !20
  %36 = call i32 @R_PointToAngle2(i32 noundef 0, i32 noundef 0, i32 noundef %32, i32 noundef %35)
  store i32 %36, ptr %4, align 4, !tbaa !13
  %37 = load i32, ptr %3, align 4, !tbaa !13
  %38 = icmp eq i32 %37, 1
  br i1 %38, label %39, label %42

39:                                               ; preds = %21
  %40 = load i32, ptr %4, align 4, !tbaa !13
  %41 = add i32 %40, -2147483648
  store i32 %41, ptr %4, align 4, !tbaa !13
  br label %42

42:                                               ; preds = %39, %21
  %43 = load i32, ptr @tmxmove, align 4, !tbaa !13
  %44 = load i32, ptr @tmymove, align 4, !tbaa !13
  %45 = call i32 @R_PointToAngle2(i32 noundef 0, i32 noundef 0, i32 noundef %43, i32 noundef %44)
  store i32 %45, ptr %5, align 4, !tbaa !13
  %46 = load i32, ptr %5, align 4, !tbaa !13
  %47 = load i32, ptr %4, align 4, !tbaa !13
  %48 = sub i32 %46, %47
  store i32 %48, ptr %6, align 4, !tbaa !13
  %49 = load i32, ptr %6, align 4, !tbaa !13
  %50 = icmp ugt i32 %49, -2147483648
  br i1 %50, label %51, label %54

51:                                               ; preds = %42
  %52 = load i32, ptr %6, align 4, !tbaa !13
  %53 = add i32 %52, -2147483648
  store i32 %53, ptr %6, align 4, !tbaa !13
  br label %54

54:                                               ; preds = %51, %42
  %55 = load i32, ptr %4, align 4, !tbaa !13
  %56 = lshr i32 %55, 19
  store i32 %56, ptr %4, align 4, !tbaa !13
  %57 = load i32, ptr %6, align 4, !tbaa !13
  %58 = lshr i32 %57, 19
  store i32 %58, ptr %6, align 4, !tbaa !13
  %59 = load i32, ptr @tmxmove, align 4, !tbaa !13
  %60 = load i32, ptr @tmymove, align 4, !tbaa !13
  %61 = call i32 @P_AproxDistance(i32 noundef %59, i32 noundef %60)
  store i32 %61, ptr %7, align 4, !tbaa !13
  %62 = load i32, ptr %7, align 4, !tbaa !13
  %63 = load ptr, ptr @finecosine, align 8, !tbaa !5
  %64 = load i32, ptr %6, align 4, !tbaa !13
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds i32, ptr %63, i64 %65
  %67 = load i32, ptr %66, align 4, !tbaa !13
  %68 = call i32 @FixedMul(i32 noundef %62, i32 noundef %67)
  store i32 %68, ptr %8, align 4, !tbaa !13
  %69 = load i32, ptr %8, align 4, !tbaa !13
  %70 = load ptr, ptr @finecosine, align 8, !tbaa !5
  %71 = load i32, ptr %4, align 4, !tbaa !13
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds i32, ptr %70, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !13
  %75 = call i32 @FixedMul(i32 noundef %69, i32 noundef %74)
  store i32 %75, ptr @tmxmove, align 4, !tbaa !13
  %76 = load i32, ptr %8, align 4, !tbaa !13
  %77 = load i32, ptr %4, align 4, !tbaa !13
  %78 = zext i32 %77 to i64
  %79 = getelementptr inbounds [10240 x i32], ptr @finesine, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !13
  %81 = call i32 @FixedMul(i32 noundef %76, i32 noundef %80)
  store i32 %81, ptr @tmymove, align 4, !tbaa !13
  store i32 0, ptr %9, align 4
  br label %82

82:                                               ; preds = %54, %20, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  %83 = load i32, ptr %9, align 4
  switch i32 %83, label %85 [
    i32 0, label %84
    i32 1, label %84
  ]

84:                                               ; preds = %82, %82
  ret void

85:                                               ; preds = %82
  unreachable
}

declare i32 @R_PointToAngle2(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #1

declare i32 @P_AproxDistance(i32 noundef, i32 noundef) #1

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 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 = { 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 #4 = { 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 52}
!10 = !{!"line_s", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !12, i64 24, !12, i64 26, !12, i64 28, !7, i64 30, !7, i64 36, !11, i64 52, !6, i64 56, !6, i64 64, !11, i64 72, !6, i64 80}
!11 = !{!"int", !7, i64 0}
!12 = !{!"short", !7, i64 0}
!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 = !{!"", !12, i64 0, !12, i64 2, !12, i64 4, !12, i64 6, !12, i64 8}
!18 = !{!15, !11, i64 28}
!19 = !{!10, !11, i64 16}
!20 = !{!10, !11, i64 20}


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

@tmymove = external dso_local local_unnamed_addr global i32, align 4
@tmxmove = external dso_local local_unnamed_addr global i32, align 4
@slidemo = external dso_local local_unnamed_addr global ptr, align 8
@finecosine = external local_unnamed_addr global ptr, align 8
@finesine = external local_unnamed_addr global [10240 x i32], align 16

declare i32 @P_PointOnLineSide(i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @P_HitSlideLine(ptr noundef %0) local_unnamed_addr #1 {
  %2 = getelementptr inbounds i8, ptr %0, i64 52
  %3 = load i32, ptr %2, align 4, !tbaa !5
  switch i32 %3, label %6 [
    i32 0, label %4
    i32 1, label %5
  ]

4:                                                ; preds = %1
  store i32 0, ptr @tmymove, align 4, !tbaa !12
  br label %45

5:                                                ; preds = %1
  store i32 0, ptr @tmxmove, align 4, !tbaa !12
  br label %45

6:                                                ; preds = %1
  %7 = load ptr, ptr @slidemo, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %7, i64 24
  %9 = load i32, ptr %8, align 8, !tbaa !14
  %10 = getelementptr inbounds i8, ptr %7, i64 28
  %11 = load i32, ptr %10, align 4, !tbaa !18
  %12 = tail call i32 @P_PointOnLineSide(i32 noundef %9, i32 noundef %11, ptr noundef nonnull %0) #3
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  %14 = load i32, ptr %13, align 8, !tbaa !19
  %15 = getelementptr inbounds i8, ptr %0, i64 20
  %16 = load i32, ptr %15, align 4, !tbaa !20
  %17 = tail call i32 @R_PointToAngle2(i32 noundef 0, i32 noundef 0, i32 noundef %14, i32 noundef %16) #3
  %18 = icmp eq i32 %12, 1
  %19 = xor i32 %17, -2147483648
  %spec.select = select i1 %18, i32 %19, i32 %17
  %20 = load i32, ptr @tmxmove, align 4, !tbaa !12
  %21 = load i32, ptr @tmymove, align 4, !tbaa !12
  %22 = tail call i32 @R_PointToAngle2(i32 noundef 0, i32 noundef 0, i32 noundef %20, i32 noundef %21) #3
  %23 = sub i32 %22, %spec.select
  %24 = icmp ugt i32 %23, -2147483648
  %25 = lshr i32 %spec.select, 19
  %26 = lshr i32 %23, 19
  %27 = and i32 %26, 4095
  %28 = select i1 %24, i32 %27, i32 %26
  %29 = load i32, ptr @tmxmove, align 4, !tbaa !12
  %30 = load i32, ptr @tmymove, align 4, !tbaa !12
  %31 = tail call i32 @P_AproxDistance(i32 noundef %29, i32 noundef %30) #3
  %32 = load ptr, ptr @finecosine, align 8, !tbaa !13
  %33 = zext nneg i32 %28 to i64
  %34 = getelementptr inbounds i32, ptr %32, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !12
  %36 = tail call i32 @FixedMul(i32 noundef %31, i32 noundef %35)
  %37 = load ptr, ptr @finecosine, align 8, !tbaa !13
  %38 = zext nneg i32 %25 to i64
  %39 = getelementptr inbounds i32, ptr %37, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !12
  %41 = tail call i32 @FixedMul(i32 noundef %36, i32 noundef %40)
  store i32 %41, ptr @tmxmove, align 4, !tbaa !12
  %42 = getelementptr inbounds [10240 x i32], ptr @finesine, i64 0, i64 %38
  %43 = load i32, ptr %42, align 4, !tbaa !12
  %44 = tail call i32 @FixedMul(i32 noundef %36, i32 noundef %43)
  store i32 %44, ptr @tmymove, align 4, !tbaa !12
  br label %45

45:                                               ; preds = %6, %5, %4
  ret void
}

declare i32 @R_PointToAngle2(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

declare i32 @P_AproxDistance(i32 noundef, i32 noundef) local_unnamed_addr #0

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

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


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