; LLVM IR from BrunoLevy/learn-fpga :: LiteX/software/Doom/mc1-doom/src (f_wipe)

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

@wipe_scr = external hidden global ptr, align 8
@screens = external global [5 x ptr], align 16
@wipe_ScreenWipe.wipes = external hidden global [6 x ptr], align 16
@go = external hidden global i32, align 4

; 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: nounwind uwtable
define dso_local i32 @wipe_ScreenWipe(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) #1 {
  %7 = alloca i32, align 4
  %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
  %13 = alloca i32, align 4
  store i32 %0, ptr %7, align 4, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !5
  store i32 %3, ptr %10, align 4, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !5
  store i32 %5, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #3
  %14 = load i32, ptr %8, align 4, !tbaa !5
  %15 = load i32, ptr %9, align 4, !tbaa !5
  %16 = load i32, ptr @go, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %29, label %18

18:                                               ; preds = %6
  store i32 1, ptr @go, align 4, !tbaa !5
  %19 = load ptr, ptr @screens, align 16, !tbaa !9
  store ptr %19, ptr @wipe_scr, align 8, !tbaa !9
  %20 = load i32, ptr %7, align 4, !tbaa !5
  %21 = mul nsw i32 %20, 3
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [6 x ptr], ptr @wipe_ScreenWipe.wipes, i64 0, i64 %22
  %24 = load ptr, ptr %23, align 8, !tbaa !9
  %25 = load i32, ptr %10, align 4, !tbaa !5
  %26 = load i32, ptr %11, align 4, !tbaa !5
  %27 = load i32, ptr %12, align 4, !tbaa !5
  %28 = call i32 %24(i32 noundef %25, i32 noundef %26, i32 noundef %27)
  br label %29

29:                                               ; preds = %18, %6
  %30 = load i32, ptr %10, align 4, !tbaa !5
  %31 = load i32, ptr %11, align 4, !tbaa !5
  call void @V_MarkRect(i32 noundef 0, i32 noundef 0, i32 noundef %30, i32 noundef %31)
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = mul nsw i32 %32, 3
  %34 = add nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [6 x ptr], ptr @wipe_ScreenWipe.wipes, i64 0, i64 %35
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  %38 = load i32, ptr %10, align 4, !tbaa !5
  %39 = load i32, ptr %11, align 4, !tbaa !5
  %40 = load i32, ptr %12, align 4, !tbaa !5
  %41 = call i32 %37(i32 noundef %38, i32 noundef %39, i32 noundef %40)
  store i32 %41, ptr %13, align 4, !tbaa !5
  %42 = load i32, ptr %13, align 4, !tbaa !5
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %55

44:                                               ; preds = %29
  store i32 0, ptr @go, align 4, !tbaa !5
  %45 = load i32, ptr %7, align 4, !tbaa !5
  %46 = mul nsw i32 %45, 3
  %47 = add nsw i32 %46, 2
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [6 x ptr], ptr @wipe_ScreenWipe.wipes, i64 0, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !9
  %51 = load i32, ptr %10, align 4, !tbaa !5
  %52 = load i32, ptr %11, align 4, !tbaa !5
  %53 = load i32, ptr %12, align 4, !tbaa !5
  %54 = call i32 %50(i32 noundef %51, i32 noundef %52, i32 noundef %53)
  br label %55

55:                                               ; preds = %44, %29
  %56 = load i32, ptr @go, align 4, !tbaa !5
  %57 = icmp ne i32 %56, 0
  %58 = xor i1 %57, true
  %59 = zext i1 %58 to i32
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  ret i32 %59
}

declare void @V_MarkRect(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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}


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

@wipe_scr = external hidden local_unnamed_addr global ptr, align 8
@screens = external local_unnamed_addr global [5 x ptr], align 16
@wipe_ScreenWipe.wipes = external hidden local_unnamed_addr global [6 x ptr], align 16
@go = external hidden local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @wipe_ScreenWipe(i32 noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4, i32 noundef %5) local_unnamed_addr #0 {
  %7 = load i32, ptr @go, align 4, !tbaa !5
  %.not = icmp eq i32 %7, 0
  br i1 %.not, label %8, label %._crit_edge

._crit_edge:                                      ; preds = %6
  %.pre = mul nsw i32 %0, 3
  br label %15

8:                                                ; preds = %6
  store i32 1, ptr @go, align 4, !tbaa !5
  %9 = load ptr, ptr @screens, align 16, !tbaa !9
  store ptr %9, ptr @wipe_scr, align 8, !tbaa !9
  %10 = mul nsw i32 %0, 3
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [6 x ptr], ptr @wipe_ScreenWipe.wipes, i64 0, i64 %11
  %13 = load ptr, ptr %12, align 8, !tbaa !9
  %14 = tail call i32 %13(i32 noundef %3, i32 noundef %4, i32 noundef %5) #2
  br label %15

15:                                               ; preds = %._crit_edge, %8
  %.pre-phi = phi i32 [ %.pre, %._crit_edge ], [ %10, %8 ]
  tail call void @V_MarkRect(i32 noundef 0, i32 noundef 0, i32 noundef %3, i32 noundef %4) #2
  %16 = add nsw i32 %.pre-phi, 1
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [6 x ptr], ptr @wipe_ScreenWipe.wipes, i64 0, i64 %17
  %19 = load ptr, ptr %18, align 8, !tbaa !9
  %20 = tail call i32 %19(i32 noundef %3, i32 noundef %4, i32 noundef %5) #2
  %.not17 = icmp eq i32 %20, 0
  br i1 %.not17, label %27, label %21

21:                                               ; preds = %15
  store i32 0, ptr @go, align 4, !tbaa !5
  %22 = add nsw i32 %.pre-phi, 2
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [6 x ptr], ptr @wipe_ScreenWipe.wipes, i64 0, i64 %23
  %25 = load ptr, ptr %24, align 8, !tbaa !9
  %26 = tail call i32 %25(i32 noundef %3, i32 noundef %4, i32 noundef %5) #2
  br label %27

27:                                               ; preds = %21, %15
  %28 = load i32, ptr @go, align 4, !tbaa !5
  %.not18 = icmp eq i32 %28, 0
  %29 = zext i1 %.not18 to i32
  ret i32 %29
}

declare void @V_MarkRect(i32 noundef, i32 noundef, 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 = { "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 }

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


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