; 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
@wipe_scr_start = external hidden global ptr, align 8
@wipe_scr_end = external hidden global ptr, align 8
@y = external hidden global ptr, align 8

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

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

declare ptr @Z_Malloc(i32 noundef, i32 noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

; Function Attrs: nounwind uwtable
define dso_local i32 @wipe_initMelt(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %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
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %9 = load i32, ptr %6, align 4, !tbaa !5
  %10 = load ptr, ptr @wipe_scr, align 8, !tbaa !9
  %11 = load ptr, ptr @wipe_scr_start, align 8, !tbaa !9
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = mul nsw i32 %12, %13
  %15 = sext i32 %14 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %10, ptr align 1 %11, i64 %15, i1 false)
  %16 = load ptr, ptr @wipe_scr_start, align 8, !tbaa !9
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sdiv i32 %17, 2
  %19 = load i32, ptr %5, align 4, !tbaa !5
  call void @wipe_shittyColMajorXform(ptr noundef %16, i32 noundef %18, i32 noundef %19)
  %20 = load ptr, ptr @wipe_scr_end, align 8, !tbaa !9
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sdiv i32 %21, 2
  %23 = load i32, ptr %5, align 4, !tbaa !5
  call void @wipe_shittyColMajorXform(ptr noundef %20, i32 noundef %22, i32 noundef %23)
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = mul i64 %25, 4
  %27 = trunc i64 %26 to i32
  %28 = call ptr @Z_Malloc(i32 noundef %27, i32 noundef 1, ptr noundef null)
  store ptr %28, ptr @y, align 8, !tbaa !9
  %29 = call i32 @M_Random()
  %30 = srem i32 %29, 16
  %31 = sub nsw i32 0, %30
  %32 = load ptr, ptr @y, align 8, !tbaa !9
  %33 = getelementptr inbounds i32, ptr %32, i64 0
  store i32 %31, ptr %33, align 4, !tbaa !5
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %79, %3
  %35 = load i32, ptr %7, align 4, !tbaa !5
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %38, label %82

38:                                               ; preds = %34
  %39 = call i32 @M_Random()
  %40 = srem i32 %39, 3
  %41 = sub nsw i32 %40, 1
  store i32 %41, ptr %8, align 4, !tbaa !5
  %42 = load ptr, ptr @y, align 8, !tbaa !9
  %43 = load i32, ptr %7, align 4, !tbaa !5
  %44 = sub nsw i32 %43, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %42, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr %8, align 4, !tbaa !5
  %49 = add nsw i32 %47, %48
  %50 = load ptr, ptr @y, align 8, !tbaa !9
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i32, ptr %50, i64 %52
  store i32 %49, ptr %53, align 4, !tbaa !5
  %54 = load ptr, ptr @y, align 8, !tbaa !9
  %55 = load i32, ptr %7, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = icmp sgt i32 %58, 0
  br i1 %59, label %60, label %65

60:                                               ; preds = %38
  %61 = load ptr, ptr @y, align 8, !tbaa !9
  %62 = load i32, ptr %7, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr %61, i64 %63
  store i32 0, ptr %64, align 4, !tbaa !5
  br label %78

65:                                               ; preds = %38
  %66 = load ptr, ptr @y, align 8, !tbaa !9
  %67 = load i32, ptr %7, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds i32, ptr %66, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = icmp eq i32 %70, -16
  br i1 %71, label %72, label %77

72:                                               ; preds = %65
  %73 = load ptr, ptr @y, align 8, !tbaa !9
  %74 = load i32, ptr %7, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds i32, ptr %73, i64 %75
  store i32 -15, ptr %76, align 4, !tbaa !5
  br label %77

77:                                               ; preds = %72, %65
  br label %78

78:                                               ; preds = %77, %60
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %7, align 4, !tbaa !5
  %81 = add nsw i32 %80, 1
  store i32 %81, ptr %7, align 4, !tbaa !5
  br label %34, !llvm.loop !11

82:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i32 0
}

declare i32 @M_Random() #2

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

@wipe_scr = external hidden local_unnamed_addr global ptr, align 8
@wipe_scr_start = external hidden local_unnamed_addr global ptr, align 8
@wipe_scr_end = external hidden local_unnamed_addr global ptr, align 8
@y = external hidden local_unnamed_addr global ptr, align 8

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @wipe_initMelt(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load ptr, ptr @wipe_scr, align 8, !tbaa !5
  %5 = load ptr, ptr @wipe_scr_start, align 8, !tbaa !5
  %6 = mul nsw i32 %1, %0
  %7 = sext i32 %6 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %4, ptr align 1 %5, i64 %7, i1 false)
  %8 = load ptr, ptr @wipe_scr_start, align 8, !tbaa !5
  %9 = sdiv i32 %0, 2
  tail call void @wipe_shittyColMajorXform(ptr noundef %8, i32 noundef %9, i32 noundef %1)
  %10 = load ptr, ptr @wipe_scr_end, align 8, !tbaa !5
  tail call void @wipe_shittyColMajorXform(ptr noundef %10, i32 noundef %9, i32 noundef %1)
  %11 = shl i32 %0, 2
  %12 = tail call ptr @Z_Malloc(i32 noundef %11, i32 noundef 1, ptr noundef null) #3
  store ptr %12, ptr @y, align 8, !tbaa !5
  %13 = tail call i32 @M_Random() #3
  %14 = srem i32 %13, 16
  %15 = sub nsw i32 0, %14
  %16 = load ptr, ptr @y, align 8, !tbaa !5
  store i32 %15, ptr %16, align 4, !tbaa !9
  %17 = icmp sgt i32 %0, 1
  br i1 %17, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %3
  %wide.trip.count = zext nneg i32 %0 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %29
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %29 ]
  %18 = tail call i32 @M_Random() #3
  %19 = srem i32 %18, 3
  %20 = add nsw i32 %19, -1
  %21 = load ptr, ptr @y, align 8, !tbaa !5
  %22 = getelementptr i32, ptr %21, i64 %indvars.iv
  %23 = getelementptr i8, ptr %22, i64 -4
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = add nsw i32 %20, %24
  store i32 %25, ptr %22, align 4, !tbaa !9
  %26 = icmp sgt i32 %25, 0
  br i1 %26, label %.sink.split, label %27

27:                                               ; preds = %.lr.ph
  %28 = icmp eq i32 %25, -16
  br i1 %28, label %.sink.split, label %29

.sink.split:                                      ; preds = %27, %.lr.ph
  %.sink = phi i32 [ 0, %.lr.ph ], [ -15, %27 ]
  store i32 %.sink, ptr %22, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %.sink.split, %27
  %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 %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %29, %3
  ret i32 0
}

declare i32 @M_Random() 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass