; 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.mline_t = type { %struct.mpoint_t, %struct.mpoint_t }
%struct.mpoint_t = type { i32, i32 }

; 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

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

; Function Attrs: nounwind uwtable
declare dso_local void @AM_drawMline(ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @AM_rotate(ptr noundef, ptr noundef, i32 noundef) #2

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

17:                                               ; preds = %133, %7
  %18 = load i32, ptr %15, align 4, !tbaa !9
  %19 = load i32, ptr %9, align 4, !tbaa !9
  %20 = icmp slt i32 %18, %19
  br i1 %20, label %21, label %136

21:                                               ; preds = %17
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load i32, ptr %15, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds %struct.mline_t, ptr %22, i64 %24
  %26 = getelementptr inbounds %struct.mline_t, ptr %25, i32 0, i32 0
  %27 = getelementptr inbounds %struct.mpoint_t, ptr %26, i32 0, i32 0
  %28 = load i32, ptr %27, align 4, !tbaa !11
  %29 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 0
  %30 = getelementptr inbounds %struct.mpoint_t, ptr %29, i32 0, i32 0
  store i32 %28, ptr %30, align 4, !tbaa !11
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load i32, ptr %15, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds %struct.mline_t, ptr %31, i64 %33
  %35 = getelementptr inbounds %struct.mline_t, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds %struct.mpoint_t, ptr %35, i32 0, i32 1
  %37 = load i32, ptr %36, align 4, !tbaa !14
  %38 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 0
  %39 = getelementptr inbounds %struct.mpoint_t, ptr %38, i32 0, i32 1
  store i32 %37, ptr %39, align 4, !tbaa !14
  %40 = load i32, ptr %10, align 4, !tbaa !9
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %57

42:                                               ; preds = %21
  %43 = load i32, ptr %10, align 4, !tbaa !9
  %44 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 0
  %45 = getelementptr inbounds %struct.mpoint_t, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !11
  %47 = call i32 @FixedMul(i32 noundef %43, i32 noundef %46)
  %48 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 0
  %49 = getelementptr inbounds %struct.mpoint_t, ptr %48, i32 0, i32 0
  store i32 %47, ptr %49, align 4, !tbaa !11
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 0
  %52 = getelementptr inbounds %struct.mpoint_t, ptr %51, i32 0, i32 1
  %53 = load i32, ptr %52, align 4, !tbaa !14
  %54 = call i32 @FixedMul(i32 noundef %50, i32 noundef %53)
  %55 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 0
  %56 = getelementptr inbounds %struct.mpoint_t, ptr %55, i32 0, i32 1
  store i32 %54, ptr %56, align 4, !tbaa !14
  br label %57

57:                                               ; preds = %42, %21
  %58 = load i32, ptr %11, align 4, !tbaa !9
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %66

60:                                               ; preds = %57
  %61 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 0
  %62 = getelementptr inbounds %struct.mpoint_t, ptr %61, i32 0, i32 0
  %63 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 0
  %64 = getelementptr inbounds %struct.mpoint_t, ptr %63, i32 0, i32 1
  %65 = load i32, ptr %11, align 4, !tbaa !9
  call void @AM_rotate(ptr noundef %62, ptr noundef %64, i32 noundef %65)
  br label %66

66:                                               ; preds = %60, %57
  %67 = load i32, ptr %13, align 4, !tbaa !9
  %68 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 0
  %69 = getelementptr inbounds %struct.mpoint_t, ptr %68, i32 0, i32 0
  %70 = load i32, ptr %69, align 4, !tbaa !11
  %71 = add nsw i32 %70, %67
  store i32 %71, ptr %69, align 4, !tbaa !11
  %72 = load i32, ptr %14, align 4, !tbaa !9
  %73 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 0
  %74 = getelementptr inbounds %struct.mpoint_t, ptr %73, i32 0, i32 1
  %75 = load i32, ptr %74, align 4, !tbaa !14
  %76 = add nsw i32 %75, %72
  store i32 %76, ptr %74, align 4, !tbaa !14
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = load i32, ptr %15, align 4, !tbaa !9
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds %struct.mline_t, ptr %77, i64 %79
  %81 = getelementptr inbounds %struct.mline_t, ptr %80, i32 0, i32 1
  %82 = getelementptr inbounds %struct.mpoint_t, ptr %81, i32 0, i32 0
  %83 = load i32, ptr %82, align 4, !tbaa !15
  %84 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 1
  %85 = getelementptr inbounds %struct.mpoint_t, ptr %84, i32 0, i32 0
  store i32 %83, ptr %85, align 4, !tbaa !15
  %86 = load ptr, ptr %8, align 8, !tbaa !5
  %87 = load i32, ptr %15, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = getelementptr inbounds %struct.mline_t, ptr %86, i64 %88
  %90 = getelementptr inbounds %struct.mline_t, ptr %89, i32 0, i32 1
  %91 = getelementptr inbounds %struct.mpoint_t, ptr %90, i32 0, i32 1
  %92 = load i32, ptr %91, align 4, !tbaa !16
  %93 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 1
  %94 = getelementptr inbounds %struct.mpoint_t, ptr %93, i32 0, i32 1
  store i32 %92, ptr %94, align 4, !tbaa !16
  %95 = load i32, ptr %10, align 4, !tbaa !9
  %96 = icmp ne i32 %95, 0
  br i1 %96, label %97, label %112

97:                                               ; preds = %66
  %98 = load i32, ptr %10, align 4, !tbaa !9
  %99 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 1
  %100 = getelementptr inbounds %struct.mpoint_t, ptr %99, i32 0, i32 0
  %101 = load i32, ptr %100, align 4, !tbaa !15
  %102 = call i32 @FixedMul(i32 noundef %98, i32 noundef %101)
  %103 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 1
  %104 = getelementptr inbounds %struct.mpoint_t, ptr %103, i32 0, i32 0
  store i32 %102, ptr %104, align 4, !tbaa !15
  %105 = load i32, ptr %10, align 4, !tbaa !9
  %106 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 1
  %107 = getelementptr inbounds %struct.mpoint_t, ptr %106, i32 0, i32 1
  %108 = load i32, ptr %107, align 4, !tbaa !16
  %109 = call i32 @FixedMul(i32 noundef %105, i32 noundef %108)
  %110 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 1
  %111 = getelementptr inbounds %struct.mpoint_t, ptr %110, i32 0, i32 1
  store i32 %109, ptr %111, align 4, !tbaa !16
  br label %112

112:                                              ; preds = %97, %66
  %113 = load i32, ptr %11, align 4, !tbaa !9
  %114 = icmp ne i32 %113, 0
  br i1 %114, label %115, label %121

115:                                              ; preds = %112
  %116 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 1
  %117 = getelementptr inbounds %struct.mpoint_t, ptr %116, i32 0, i32 0
  %118 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 1
  %119 = getelementptr inbounds %struct.mpoint_t, ptr %118, i32 0, i32 1
  %120 = load i32, ptr %11, align 4, !tbaa !9
  call void @AM_rotate(ptr noundef %117, ptr noundef %119, i32 noundef %120)
  br label %121

121:                                              ; preds = %115, %112
  %122 = load i32, ptr %13, align 4, !tbaa !9
  %123 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 1
  %124 = getelementptr inbounds %struct.mpoint_t, ptr %123, i32 0, i32 0
  %125 = load i32, ptr %124, align 4, !tbaa !15
  %126 = add nsw i32 %125, %122
  store i32 %126, ptr %124, align 4, !tbaa !15
  %127 = load i32, ptr %14, align 4, !tbaa !9
  %128 = getelementptr inbounds %struct.mline_t, ptr %16, i32 0, i32 1
  %129 = getelementptr inbounds %struct.mpoint_t, ptr %128, i32 0, i32 1
  %130 = load i32, ptr %129, align 4, !tbaa !16
  %131 = add nsw i32 %130, %127
  store i32 %131, ptr %129, align 4, !tbaa !16
  %132 = load i32, ptr %12, align 4, !tbaa !9
  call void @AM_drawMline(ptr noundef %16, i32 noundef %132)
  br label %133

133:                                              ; preds = %121
  %134 = load i32, ptr %15, align 4, !tbaa !9
  %135 = add nsw i32 %134, 1
  store i32 %135, ptr %15, align 4, !tbaa !9
  br label %17, !llvm.loop !17

136:                                              ; preds = %17
  call void @llvm.lifetime.end.p0(i64 16, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  ret void
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 0}
!12 = !{!"", !13, i64 0, !13, i64 8}
!13 = !{!"", !10, i64 0, !10, i64 4}
!14 = !{!12, !10, i64 4}
!15 = !{!12, !10, i64 8}
!16 = !{!12, !10, i64 12}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


; 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.mline_t = type { %struct.mpoint_t, %struct.mpoint_t }
%struct.mpoint_t = type { i32, i32 }

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @AM_drawMline(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare dso_local void @AM_rotate(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @AM_drawLineCharacter(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5, i32 noundef %6) local_unnamed_addr #2 {
  %8 = alloca %struct.mline_t, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %8) #3
  %9 = icmp sgt i32 %1, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %7
  %10 = getelementptr inbounds i8, ptr %8, i64 4
  %.not = icmp eq i32 %2, 0
  %.not28 = icmp eq i32 %3, 0
  %11 = getelementptr inbounds i8, ptr %8, i64 8
  %12 = getelementptr inbounds i8, ptr %8, i64 12
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %13

13:                                               ; preds = %.lr.ph, %41
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %41 ]
  %14 = getelementptr inbounds %struct.mline_t, ptr %0, i64 %indvars.iv
  %15 = load i32, ptr %14, align 4, !tbaa !5
  store i32 %15, ptr %8, align 4, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %14, i64 4
  %17 = load i32, ptr %16, align 4, !tbaa !11
  store i32 %17, ptr %10, align 4, !tbaa !11
  br i1 %.not, label %22, label %18

18:                                               ; preds = %13
  %19 = call i32 @FixedMul(i32 noundef %2, i32 noundef %15)
  store i32 %19, ptr %8, align 4, !tbaa !5
  %20 = load i32, ptr %10, align 4, !tbaa !11
  %21 = call i32 @FixedMul(i32 noundef %2, i32 noundef %20)
  store i32 %21, ptr %10, align 4, !tbaa !11
  br label %22

22:                                               ; preds = %18, %13
  %23 = phi i32 [ %21, %18 ], [ %17, %13 ]
  br i1 %.not28, label %25, label %24

24:                                               ; preds = %22
  call void @AM_rotate(ptr noundef nonnull %8, ptr noundef nonnull %10, i32 noundef %3)
  %.pre = load i32, ptr %10, align 4, !tbaa !11
  br label %25

25:                                               ; preds = %24, %22
  %26 = phi i32 [ %.pre, %24 ], [ %23, %22 ]
  %27 = load i32, ptr %8, align 4, !tbaa !5
  %28 = add nsw i32 %27, %5
  store i32 %28, ptr %8, align 4, !tbaa !5
  %29 = add nsw i32 %26, %6
  store i32 %29, ptr %10, align 4, !tbaa !11
  %30 = getelementptr inbounds i8, ptr %14, i64 8
  %31 = load i32, ptr %30, align 4, !tbaa !12
  store i32 %31, ptr %11, align 4, !tbaa !12
  %32 = getelementptr inbounds i8, ptr %14, i64 12
  %33 = load i32, ptr %32, align 4, !tbaa !13
  store i32 %33, ptr %12, align 4, !tbaa !13
  br i1 %.not, label %38, label %34

34:                                               ; preds = %25
  %35 = call i32 @FixedMul(i32 noundef %2, i32 noundef %31)
  store i32 %35, ptr %11, align 4, !tbaa !12
  %36 = load i32, ptr %12, align 4, !tbaa !13
  %37 = call i32 @FixedMul(i32 noundef %2, i32 noundef %36)
  store i32 %37, ptr %12, align 4, !tbaa !13
  br label %38

38:                                               ; preds = %34, %25
  %39 = phi i32 [ %37, %34 ], [ %33, %25 ]
  br i1 %.not28, label %41, label %40

40:                                               ; preds = %38
  call void @AM_rotate(ptr noundef nonnull %11, ptr noundef nonnull %12, i32 noundef %3)
  %.pre31 = load i32, ptr %12, align 4, !tbaa !13
  br label %41

41:                                               ; preds = %40, %38
  %42 = phi i32 [ %.pre31, %40 ], [ %39, %38 ]
  %43 = load i32, ptr %11, align 4, !tbaa !12
  %44 = add nsw i32 %43, %5
  store i32 %44, ptr %11, align 4, !tbaa !12
  %45 = add nsw i32 %42, %6
  store i32 %45, ptr %12, align 4, !tbaa !13
  call void @AM_drawMline(ptr noundef nonnull %8, i32 noundef %4)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %13, !llvm.loop !14

._crit_edge:                                      ; preds = %41, %7
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %8) #3
  ret void
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
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 = { 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, !8, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8}
!7 = !{!"", !8, i64 0, !8, i64 4}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!6, !8, i64 4}
!12 = !{!6, !8, i64 8}
!13 = !{!6, !8, i64 12}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass