; LLVM IR from BrunoLevy/learn-fpga :: LiteX/software/Doom/mc1-doom/src (am_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.mpoint_t = type { i32, i32 }

@m_w = external hidden global i32, align 4
@m_x = external hidden global i32, align 4
@m_h = external hidden global i32, align 4
@m_y = external hidden global i32, align 4
@m_x2 = external hidden global i32, align 4
@m_y2 = external hidden global i32, align 4
@followplayer = external hidden global i32, align 4
@min_y = external hidden global i32, align 4
@min_x = external hidden global i32, align 4
@max_y = external hidden global i32, align 4
@max_x = external hidden global i32, align 4
@m_paninc = external hidden global %struct.mpoint_t, align 4
@f_oldloc = external hidden global %struct.mpoint_t, align 4

; Function Attrs: nounwind uwtable
define dso_local void @AM_changeWindowLoc() #0 {
  %1 = load i32, ptr @m_paninc, align 4, !tbaa !5
  %2 = icmp ne i32 %1, 0
  br i1 %2, label %6, label %3

3:                                                ; preds = %0
  %4 = load i32, ptr getelementptr inbounds (%struct.mpoint_t, ptr @m_paninc, i32 0, i32 1), align 4, !tbaa !10
  %5 = icmp ne i32 %4, 0
  br i1 %5, label %6, label %7

6:                                                ; preds = %3, %0
  store i32 0, ptr @followplayer, align 4, !tbaa !11
  store i32 2147483647, ptr @f_oldloc, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %6, %3
  %8 = load i32, ptr @m_paninc, align 4, !tbaa !5
  %9 = load i32, ptr @m_x, align 4, !tbaa !11
  %10 = add nsw i32 %9, %8
  store i32 %10, ptr @m_x, align 4, !tbaa !11
  %11 = load i32, ptr getelementptr inbounds (%struct.mpoint_t, ptr @m_paninc, i32 0, i32 1), align 4, !tbaa !10
  %12 = load i32, ptr @m_y, align 4, !tbaa !11
  %13 = add nsw i32 %12, %11
  store i32 %13, ptr @m_y, align 4, !tbaa !11
  %14 = load i32, ptr @m_x, align 4, !tbaa !11
  %15 = load i32, ptr @m_w, align 4, !tbaa !11
  %16 = sdiv i32 %15, 2
  %17 = add nsw i32 %14, %16
  %18 = load i32, ptr @max_x, align 4, !tbaa !11
  %19 = icmp sgt i32 %17, %18
  br i1 %19, label %20, label %25

20:                                               ; preds = %7
  %21 = load i32, ptr @max_x, align 4, !tbaa !11
  %22 = load i32, ptr @m_w, align 4, !tbaa !11
  %23 = sdiv i32 %22, 2
  %24 = sub nsw i32 %21, %23
  store i32 %24, ptr @m_x, align 4, !tbaa !11
  br label %38

25:                                               ; preds = %7
  %26 = load i32, ptr @m_x, align 4, !tbaa !11
  %27 = load i32, ptr @m_w, align 4, !tbaa !11
  %28 = sdiv i32 %27, 2
  %29 = add nsw i32 %26, %28
  %30 = load i32, ptr @min_x, align 4, !tbaa !11
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %37

32:                                               ; preds = %25
  %33 = load i32, ptr @min_x, align 4, !tbaa !11
  %34 = load i32, ptr @m_w, align 4, !tbaa !11
  %35 = sdiv i32 %34, 2
  %36 = sub nsw i32 %33, %35
  store i32 %36, ptr @m_x, align 4, !tbaa !11
  br label %37

37:                                               ; preds = %32, %25
  br label %38

38:                                               ; preds = %37, %20
  %39 = load i32, ptr @m_y, align 4, !tbaa !11
  %40 = load i32, ptr @m_h, align 4, !tbaa !11
  %41 = sdiv i32 %40, 2
  %42 = add nsw i32 %39, %41
  %43 = load i32, ptr @max_y, align 4, !tbaa !11
  %44 = icmp sgt i32 %42, %43
  br i1 %44, label %45, label %50

45:                                               ; preds = %38
  %46 = load i32, ptr @max_y, align 4, !tbaa !11
  %47 = load i32, ptr @m_h, align 4, !tbaa !11
  %48 = sdiv i32 %47, 2
  %49 = sub nsw i32 %46, %48
  store i32 %49, ptr @m_y, align 4, !tbaa !11
  br label %63

50:                                               ; preds = %38
  %51 = load i32, ptr @m_y, align 4, !tbaa !11
  %52 = load i32, ptr @m_h, align 4, !tbaa !11
  %53 = sdiv i32 %52, 2
  %54 = add nsw i32 %51, %53
  %55 = load i32, ptr @min_y, align 4, !tbaa !11
  %56 = icmp slt i32 %54, %55
  br i1 %56, label %57, label %62

57:                                               ; preds = %50
  %58 = load i32, ptr @min_y, align 4, !tbaa !11
  %59 = load i32, ptr @m_h, align 4, !tbaa !11
  %60 = sdiv i32 %59, 2
  %61 = sub nsw i32 %58, %60
  store i32 %61, ptr @m_y, align 4, !tbaa !11
  br label %62

62:                                               ; preds = %57, %50
  br label %63

63:                                               ; preds = %62, %45
  %64 = load i32, ptr @m_x, align 4, !tbaa !11
  %65 = load i32, ptr @m_w, align 4, !tbaa !11
  %66 = add nsw i32 %64, %65
  store i32 %66, ptr @m_x2, align 4, !tbaa !11
  %67 = load i32, ptr @m_y, align 4, !tbaa !11
  %68 = load i32, ptr @m_h, align 4, !tbaa !11
  %69 = add nsw i32 %67, %68
  store i32 %69, ptr @m_y2, align 4, !tbaa !11
  ret void
}

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

!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 = !{!"", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!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.mpoint_t = type { i32, i32 }

@m_w = external hidden local_unnamed_addr global i32, align 4
@m_x = external hidden local_unnamed_addr global i32, align 4
@m_h = external hidden local_unnamed_addr global i32, align 4
@m_y = external hidden local_unnamed_addr global i32, align 4
@m_x2 = external hidden local_unnamed_addr global i32, align 4
@m_y2 = external hidden local_unnamed_addr global i32, align 4
@followplayer = external hidden local_unnamed_addr global i32, align 4
@min_y = external hidden local_unnamed_addr global i32, align 4
@min_x = external hidden local_unnamed_addr global i32, align 4
@max_y = external hidden local_unnamed_addr global i32, align 4
@max_x = external hidden local_unnamed_addr global i32, align 4
@m_paninc = external hidden local_unnamed_addr global %struct.mpoint_t, align 4
@f_oldloc = external hidden local_unnamed_addr global %struct.mpoint_t, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @AM_changeWindowLoc() local_unnamed_addr #0 {
  %1 = load i32, ptr @m_paninc, align 4, !tbaa !5
  %2 = icmp ne i32 %1, 0
  %3 = load i32, ptr getelementptr inbounds (i8, ptr @m_paninc, i64 4), align 4
  %4 = icmp ne i32 %3, 0
  %or.cond = select i1 %2, i1 true, i1 %4
  br i1 %or.cond, label %5, label %6

5:                                                ; preds = %0
  store i32 0, ptr @followplayer, align 4, !tbaa !10
  store i32 2147483647, ptr @f_oldloc, align 4, !tbaa !5
  br label %6

6:                                                ; preds = %0, %5
  %7 = load i32, ptr @m_x, align 4, !tbaa !10
  %8 = add nsw i32 %7, %1
  store i32 %8, ptr @m_x, align 4, !tbaa !10
  %9 = load i32, ptr @m_y, align 4, !tbaa !10
  %10 = add nsw i32 %9, %3
  store i32 %10, ptr @m_y, align 4, !tbaa !10
  %11 = load i32, ptr @m_w, align 4, !tbaa !10
  %12 = sdiv i32 %11, 2
  %13 = add nsw i32 %12, %8
  %14 = load i32, ptr @max_x, align 4, !tbaa !10
  %15 = icmp sgt i32 %13, %14
  br i1 %15, label %.sink.split, label %16

16:                                               ; preds = %6
  %17 = load i32, ptr @min_x, align 4, !tbaa !10
  %18 = icmp slt i32 %13, %17
  br i1 %18, label %.sink.split, label %20

.sink.split:                                      ; preds = %16, %6
  %.sink7 = phi i32 [ %14, %6 ], [ %17, %16 ]
  %19 = sub nsw i32 %.sink7, %12
  store i32 %19, ptr @m_x, align 4, !tbaa !10
  br label %20

20:                                               ; preds = %.sink.split, %16
  %21 = phi i32 [ %8, %16 ], [ %19, %.sink.split ]
  %22 = load i32, ptr @m_h, align 4, !tbaa !10
  %23 = sdiv i32 %22, 2
  %24 = add nsw i32 %23, %10
  %25 = load i32, ptr @max_y, align 4, !tbaa !10
  %26 = icmp sgt i32 %24, %25
  br i1 %26, label %.sink.split8, label %27

27:                                               ; preds = %20
  %28 = load i32, ptr @min_y, align 4, !tbaa !10
  %29 = icmp slt i32 %24, %28
  br i1 %29, label %.sink.split8, label %31

.sink.split8:                                     ; preds = %27, %20
  %.sink9 = phi i32 [ %25, %20 ], [ %28, %27 ]
  %30 = sub nsw i32 %.sink9, %23
  store i32 %30, ptr @m_y, align 4, !tbaa !10
  br label %31

31:                                               ; preds = %.sink.split8, %27
  %32 = phi i32 [ %10, %27 ], [ %30, %.sink.split8 ]
  %33 = add nsw i32 %21, %11
  store i32 %33, ptr @m_x2, align 4, !tbaa !10
  %34 = add nsw i32 %32, %22
  store i32 %34, ptr @m_y2, align 4, !tbaa !10
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SimplifyCFGPass