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

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

@finalecount = external dso_local global i32, align 4
@F_BunnyScroll.laststage = external hidden global i32, align 4
@.str.51 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.53 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.54 = external hidden unnamed_addr constant [6 x i8], align 1

; 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 ptr @W_CacheLumpName(ptr noundef, i32 noundef) #1

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

declare void @V_DrawPatch(i32 noundef, i32 noundef, i32 noundef, ptr noundef) #1

declare void @S_StartSound(ptr noundef, i32 noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @F_BunnyScroll() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [10 x i8], align 1
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 10, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %8 = call ptr @W_CacheLumpName(ptr noundef @.str.51, i32 noundef 50)
  store ptr %8, ptr %3, align 8, !tbaa !5
  %9 = call ptr @W_CacheLumpName(ptr noundef @.str.52, i32 noundef 50)
  store ptr %9, ptr %4, align 8, !tbaa !5
  call void @V_MarkRect(i32 noundef 0, i32 noundef 0, i32 noundef 320, i32 noundef 200)
  %10 = load i32, ptr @finalecount, align 4, !tbaa !9
  %11 = sub nsw i32 %10, 230
  %12 = sdiv i32 %11, 2
  %13 = sub nsw i32 320, %12
  store i32 %13, ptr %1, align 4, !tbaa !9
  %14 = load i32, ptr %1, align 4, !tbaa !9
  %15 = icmp sgt i32 %14, 320
  br i1 %15, label %16, label %17

16:                                               ; preds = %0
  store i32 320, ptr %1, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %16, %0
  %18 = load i32, ptr %1, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  store i32 0, ptr %1, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %20, %17
  store i32 0, ptr %2, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %44, %21
  %23 = load i32, ptr %2, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 320
  br i1 %24, label %25, label %47

25:                                               ; preds = %22
  %26 = load i32, ptr %2, align 4, !tbaa !9
  %27 = load i32, ptr %1, align 4, !tbaa !9
  %28 = add nsw i32 %26, %27
  %29 = icmp slt i32 %28, 320
  br i1 %29, label %30, label %36

30:                                               ; preds = %25
  %31 = load i32, ptr %2, align 4, !tbaa !9
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = load i32, ptr %2, align 4, !tbaa !9
  %34 = load i32, ptr %1, align 4, !tbaa !9
  %35 = add nsw i32 %33, %34
  call void @F_DrawPatchCol(i32 noundef %31, ptr noundef %32, i32 noundef %35)
  br label %43

36:                                               ; preds = %25
  %37 = load i32, ptr %2, align 4, !tbaa !9
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = load i32, ptr %2, align 4, !tbaa !9
  %40 = load i32, ptr %1, align 4, !tbaa !9
  %41 = add nsw i32 %39, %40
  %42 = sub nsw i32 %41, 320
  call void @F_DrawPatchCol(i32 noundef %37, ptr noundef %38, i32 noundef %42)
  br label %43

43:                                               ; preds = %36, %30
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %2, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %2, align 4, !tbaa !9
  br label %22, !llvm.loop !11

47:                                               ; preds = %22
  %48 = load i32, ptr @finalecount, align 4, !tbaa !9
  %49 = icmp slt i32 %48, 1130
  br i1 %49, label %50, label %51

50:                                               ; preds = %47
  store i32 1, ptr %7, align 4
  br label %75

51:                                               ; preds = %47
  %52 = load i32, ptr @finalecount, align 4, !tbaa !9
  %53 = icmp slt i32 %52, 1180
  br i1 %53, label %54, label %56

54:                                               ; preds = %51
  %55 = call ptr @W_CacheLumpName(ptr noundef @.str.53, i32 noundef 101)
  call void @V_DrawPatch(i32 noundef 108, i32 noundef 68, i32 noundef 0, ptr noundef %55)
  store i32 0, ptr @F_BunnyScroll.laststage, align 4, !tbaa !9
  store i32 1, ptr %7, align 4
  br label %75

56:                                               ; preds = %51
  %57 = load i32, ptr @finalecount, align 4, !tbaa !9
  %58 = sub nsw i32 %57, 1180
  %59 = sdiv i32 %58, 5
  store i32 %59, ptr %6, align 4, !tbaa !9
  %60 = load i32, ptr %6, align 4, !tbaa !9
  %61 = icmp sgt i32 %60, 6
  br i1 %61, label %62, label %63

62:                                               ; preds = %56
  store i32 6, ptr %6, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %62, %56
  %64 = load i32, ptr %6, align 4, !tbaa !9
  %65 = load i32, ptr @F_BunnyScroll.laststage, align 4, !tbaa !9
  %66 = icmp sgt i32 %64, %65
  br i1 %66, label %67, label %69

67:                                               ; preds = %63
  call void @S_StartSound(ptr noundef null, i32 noundef 1)
  %68 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %68, ptr @F_BunnyScroll.laststage, align 4, !tbaa !9
  br label %69

69:                                               ; preds = %67, %63
  %70 = getelementptr inbounds [10 x i8], ptr %5, i64 0, i64 0
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef %70, ptr noundef @.str.54, i32 noundef %71) #4
  %73 = getelementptr inbounds [10 x i8], ptr %5, i64 0, i64 0
  %74 = call ptr @W_CacheLumpName(ptr noundef %73, i32 noundef 101)
  call void @V_DrawPatch(i32 noundef 108, i32 noundef 68, i32 noundef 0, ptr noundef %74)
  store i32 0, ptr %7, align 4
  br label %75

75:                                               ; preds = %69, %54, %50
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 10, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  %76 = load i32, ptr %7, align 4
  switch i32 %76, label %78 [
    i32 0, label %77
    i32 1, label %77
  ]

77:                                               ; preds = %75, %75
  ret void

78:                                               ; preds = %75
  unreachable
}

; Function Attrs: nounwind
declare i32 @sprintf(ptr noundef, ptr 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 = { nounwind "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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"

@finalecount = external dso_local local_unnamed_addr global i32, align 4
@F_BunnyScroll.laststage = external hidden local_unnamed_addr global i32, align 4
@.str.51 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.52 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.53 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.54 = external hidden unnamed_addr constant [6 x i8], align 1

; 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

declare ptr @W_CacheLumpName(ptr noundef, i32 noundef) local_unnamed_addr #1

declare void @V_MarkRect(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare void @V_DrawPatch(i32 noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

declare void @S_StartSound(ptr noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local void @F_BunnyScroll() local_unnamed_addr #2 {
  %1 = alloca [10 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 10, ptr nonnull %1) #5
  %2 = tail call ptr @W_CacheLumpName(ptr noundef nonnull @.str.51, i32 noundef 50) #5
  %3 = tail call ptr @W_CacheLumpName(ptr noundef nonnull @.str.52, i32 noundef 50) #5
  tail call void @V_MarkRect(i32 noundef 0, i32 noundef 0, i32 noundef 320, i32 noundef 200) #5
  %4 = load i32, ptr @finalecount, align 4, !tbaa !5
  %5 = add nsw i32 %4, -230
  %.neg = sdiv i32 %5, -2
  %6 = tail call i32 @llvm.smin.i32(i32 %.neg, i32 0)
  %7 = tail call i32 @llvm.smax.i32(i32 %6, i32 -320)
  %spec.store.select2 = add nsw i32 %7, 320
  br label %8

8:                                                ; preds = %0, %14
  %.021 = phi i32 [ 0, %0 ], [ %15, %14 ]
  %9 = add nuw nsw i32 %spec.store.select2, %.021
  %10 = icmp ult i32 %9, 320
  br i1 %10, label %11, label %12

11:                                               ; preds = %8
  tail call void @F_DrawPatchCol(i32 noundef %.021, ptr noundef %2, i32 noundef %9)
  br label %14

12:                                               ; preds = %8
  %13 = add nsw i32 %.021, %7
  tail call void @F_DrawPatchCol(i32 noundef %.021, ptr noundef %3, i32 noundef %13)
  br label %14

14:                                               ; preds = %11, %12
  %15 = add nuw nsw i32 %.021, 1
  %exitcond.not = icmp eq i32 %15, 320
  br i1 %exitcond.not, label %16, label %8, !llvm.loop !9

16:                                               ; preds = %14
  %17 = load i32, ptr @finalecount, align 4, !tbaa !5
  %18 = icmp slt i32 %17, 1130
  br i1 %18, label %32, label %19

19:                                               ; preds = %16
  %20 = icmp ult i32 %17, 1180
  br i1 %20, label %21, label %23

21:                                               ; preds = %19
  %22 = tail call ptr @W_CacheLumpName(ptr noundef nonnull @.str.53, i32 noundef 101) #5
  tail call void @V_DrawPatch(i32 noundef 108, i32 noundef 68, i32 noundef 0, ptr noundef %22) #5
  store i32 0, ptr @F_BunnyScroll.laststage, align 4, !tbaa !5
  br label %32

23:                                               ; preds = %19
  %24 = add nsw i32 %17, -1180
  %25 = udiv i32 %24, 5
  %spec.store.select1 = tail call i32 @llvm.umin.i32(i32 %25, i32 6)
  %26 = load i32, ptr @F_BunnyScroll.laststage, align 4, !tbaa !5
  %27 = icmp sgt i32 %spec.store.select1, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %23
  tail call void @S_StartSound(ptr noundef null, i32 noundef 1) #5
  store i32 %spec.store.select1, ptr @F_BunnyScroll.laststage, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %28, %23
  %30 = call i32 (ptr, ptr, ...) @sprintf(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.54, i32 noundef %spec.store.select1) #5
  %31 = call ptr @W_CacheLumpName(ptr noundef nonnull %1, i32 noundef 101) #5
  call void @V_DrawPatch(i32 noundef 108, i32 noundef 68, i32 noundef 0, ptr noundef %31) #5
  br label %32

32:                                               ; preds = %16, %29, %21
  call void @llvm.lifetime.end.p0(i64 10, ptr nonnull %1) #5
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @sprintf(ptr noalias nocapture noundef writeonly, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #4

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #4

attributes #0 = { mustprogress 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 = { nofree nounwind "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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