; LLVM IR from eyangch/competitive-programming :: AdventOfCode/2022/day4/1.ll (Z4stufxxxx)

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_Z4stufxxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) #0 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca [1000 x i64], align 16
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store i64 %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8000, ptr %10) #3
  %14 = getelementptr inbounds [1000 x i64], ptr %10, i64 0, i64 0
  %15 = getelementptr inbounds [1000 x i64], ptr %10, i64 0, i64 0
  %16 = getelementptr inbounds i64, ptr %15, i64 1000
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @_ZSt4fillIPxiEvT_S1_RKT0_(ptr noundef %14, ptr noundef %16, ptr noundef nonnull align 4 dereferenceable(4) %11)
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %17 = load i64, ptr %6, align 8, !tbaa !5
  store i64 %17, ptr %12, align 8, !tbaa !5
  br label %18

18:                                               ; preds = %26, %4
  %19 = load i64, ptr %12, align 8, !tbaa !5
  %20 = load i64, ptr %7, align 8, !tbaa !5
  %21 = icmp sle i64 %19, %20
  br i1 %21, label %23, label %22

22:                                               ; preds = %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %29

23:                                               ; preds = %18
  %24 = load i64, ptr %12, align 8, !tbaa !5
  %25 = getelementptr inbounds [1000 x i64], ptr %10, i64 0, i64 %24
  store i64 1, ptr %25, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %23
  %27 = load i64, ptr %12, align 8, !tbaa !5
  %28 = add nsw i64 %27, 1
  store i64 %28, ptr %12, align 8, !tbaa !5
  br label %18, !llvm.loop !11

29:                                               ; preds = %22
  %30 = load i64, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds [1000 x i64], ptr %10, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = icmp eq i64 %32, 1
  br i1 %33, label %34, label %40

34:                                               ; preds = %29
  %35 = load i64, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds [1000 x i64], ptr %10, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = icmp eq i64 %37, 1
  br i1 %38, label %39, label %40

39:                                               ; preds = %34
  store i64 1, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %41

40:                                               ; preds = %34, %29
  store i64 0, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %41

41:                                               ; preds = %40, %39
  call void @llvm.lifetime.end.p0(i64 8000, ptr %10) #3
  %42 = load i64, ptr %5, align 8
  ret i64 %42
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPxiEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) #2

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

attributes #0 = { mustprogress 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 = { inlinehint mustprogress 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple 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"

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i64 0, 2) i64 @_Z4stufxxxx(i64 noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = alloca [1000 x i64], align 16
  %6 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8000, ptr nonnull %5) #3
  %7 = getelementptr inbounds i8, ptr %5, i64 8000
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #3
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @_ZSt4fillIPxiEvT_S1_RKT0_(ptr noundef nonnull %5, ptr noundef nonnull %7, ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #3
  %.not9 = icmp sgt i64 %0, %1
  br i1 %.not9, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %4
  %8 = add i64 %1, 1
  %9 = sub i64 %8, %0
  %min.iters.check = icmp ult i64 %9, 4
  br i1 %min.iters.check, label %.lr.ph.preheader11, label %vector.ph

.lr.ph.preheader11:                               ; preds = %middle.block, %.lr.ph.preheader
  %.010.ph = phi i64 [ %0, %.lr.ph.preheader ], [ %ind.end, %middle.block ]
  br label %.lr.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %9, -4
  %ind.end = add i64 %n.vec, %0
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %offset.idx = add i64 %index, %0
  %10 = getelementptr inbounds [1000 x i64], ptr %5, i64 0, i64 %offset.idx
  %11 = getelementptr inbounds i8, ptr %10, i64 16
  store <2 x i64> <i64 1, i64 1>, ptr %10, align 8, !tbaa !9
  store <2 x i64> <i64 1, i64 1>, ptr %11, align 8, !tbaa !9
  %index.next = add nuw i64 %index, 4
  %12 = icmp eq i64 %index.next, %n.vec
  br i1 %12, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %9, %n.vec
  br i1 %cmp.n, label %._crit_edge, label %.lr.ph.preheader11

._crit_edge:                                      ; preds = %.lr.ph, %middle.block, %4
  %13 = getelementptr inbounds [1000 x i64], ptr %5, i64 0, i64 %2
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = icmp eq i64 %14, 1
  br i1 %15, label %18, label %22

.lr.ph:                                           ; preds = %.lr.ph.preheader11, %.lr.ph
  %.010 = phi i64 [ %17, %.lr.ph ], [ %.010.ph, %.lr.ph.preheader11 ]
  %16 = getelementptr inbounds [1000 x i64], ptr %5, i64 0, i64 %.010
  store i64 1, ptr %16, align 8, !tbaa !9
  %17 = add i64 %.010, 1
  %exitcond.not = icmp eq i64 %.010, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !15

18:                                               ; preds = %._crit_edge
  %19 = getelementptr inbounds [1000 x i64], ptr %5, i64 0, i64 %3
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = icmp eq i64 %20, 1
  br i1 %21, label %23, label %22

22:                                               ; preds = %18, %._crit_edge
  br label %23

23:                                               ; preds = %18, %22
  %.08 = phi i64 [ 0, %22 ], [ 1, %18 ]
  call void @llvm.lifetime.end.p0(i64 8000, ptr nonnull %5) #3
  ret i64 %.08
}

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPxiEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass