; LLVM IR from eyangch/competitive-programming :: AdventOfCode/2022/day8/day8.ll (Z5part1v)

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

@N = external dso_local global i64, align 8
@M = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@vis = external dso_local global [1000 x [1000 x i8]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3auxxxxx(i64 noundef, i64 noundef, i64 noundef, i64 noundef) #0

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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5part1v() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  store i64 0, ptr %1, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %16, %0
  %7 = load i64, ptr %1, align 8, !tbaa !5
  %8 = load i64, ptr @N, align 8, !tbaa !5
  %9 = icmp slt i64 %7, %8
  br i1 %9, label %11, label %10

10:                                               ; preds = %6
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  br label %19

11:                                               ; preds = %6
  %12 = load i64, ptr %1, align 8, !tbaa !5
  call void @_Z3auxxxxx(i64 noundef %12, i64 noundef 0, i64 noundef 0, i64 noundef 1)
  %13 = load i64, ptr %1, align 8, !tbaa !5
  %14 = load i64, ptr @M, align 8, !tbaa !5
  %15 = sub nsw i64 %14, 1
  call void @_Z3auxxxxx(i64 noundef %13, i64 noundef %15, i64 noundef 0, i64 noundef -1)
  br label %16

16:                                               ; preds = %11
  %17 = load i64, ptr %1, align 8, !tbaa !5
  %18 = add nsw i64 %17, 1
  store i64 %18, ptr %1, align 8, !tbaa !5
  br label %6, !llvm.loop !9

19:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %30, %19
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = load i64, ptr @M, align 8, !tbaa !5
  %23 = icmp slt i64 %21, %22
  br i1 %23, label %25, label %24

24:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  br label %33

25:                                               ; preds = %20
  %26 = load i64, ptr %2, align 8, !tbaa !5
  call void @_Z3auxxxxx(i64 noundef 0, i64 noundef %26, i64 noundef 1, i64 noundef 0)
  %27 = load i64, ptr @N, align 8, !tbaa !5
  %28 = sub nsw i64 %27, 1
  %29 = load i64, ptr %2, align 8, !tbaa !5
  call void @_Z3auxxxxx(i64 noundef %28, i64 noundef %29, i64 noundef -1, i64 noundef 0)
  br label %30

30:                                               ; preds = %25
  %31 = load i64, ptr %2, align 8, !tbaa !5
  %32 = add nsw i64 %31, 1
  store i64 %32, ptr %2, align 8, !tbaa !5
  br label %20, !llvm.loop !11

33:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %34

34:                                               ; preds = %60, %33
  %35 = load i64, ptr %3, align 8, !tbaa !5
  %36 = load i64, ptr @N, align 8, !tbaa !5
  %37 = icmp slt i64 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  br label %63

39:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %40

40:                                               ; preds = %56, %39
  %41 = load i64, ptr %5, align 8, !tbaa !5
  %42 = load i64, ptr @M, align 8, !tbaa !5
  %43 = icmp slt i64 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  br label %59

45:                                               ; preds = %40
  %46 = load i64, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds [1000 x [1000 x i8]], ptr @vis, i64 0, i64 %46
  %48 = load i64, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds [1000 x i8], ptr %47, i64 0, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !12, !range !14, !noundef !15
  %51 = trunc i8 %50 to i1
  br i1 %51, label %52, label %55

52:                                               ; preds = %45
  %53 = load i64, ptr @ans, align 8, !tbaa !5
  %54 = add nsw i64 %53, 1
  store i64 %54, ptr @ans, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %52, %45
  br label %56

56:                                               ; preds = %55
  %57 = load i64, ptr %5, align 8, !tbaa !5
  %58 = add nsw i64 %57, 1
  store i64 %58, ptr %5, align 8, !tbaa !5
  br label %40, !llvm.loop !16

59:                                               ; preds = %44
  br label %60

60:                                               ; preds = %59
  %61 = load i64, ptr %3, align 8, !tbaa !5
  %62 = add nsw i64 %61, 1
  store i64 %62, ptr %3, align 8, !tbaa !5
  br label %34, !llvm.loop !17

63:                                               ; preds = %38
  ret void
}

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 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = !{!13, !13, i64 0}
!13 = !{!"bool", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}


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

@N = external dso_local local_unnamed_addr global i64, align 8
@M = external dso_local local_unnamed_addr global i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@vis = external dso_local local_unnamed_addr global [1000 x [1000 x i8]], align 16

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z3auxxxxx(i64 noundef, i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5part1v() local_unnamed_addr #0 {
  %1 = load i64, ptr @N, align 8, !tbaa !5
  %2 = icmp sgt i64 %1, 0
  br i1 %2, label %.lr.ph, label %.preheader18

.preheader18:                                     ; preds = %.lr.ph, %0
  %3 = phi i64 [ %1, %0 ], [ %9, %.lr.ph ]
  %4 = load i64, ptr @M, align 8, !tbaa !5
  %5 = icmp sgt i64 %4, 0
  br i1 %5, label %.lr.ph21, label %.preheader17

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.01619 = phi i64 [ %8, %.lr.ph ], [ 0, %0 ]
  tail call void @_Z3auxxxxx(i64 noundef %.01619, i64 noundef 0, i64 noundef 0, i64 noundef 1)
  %6 = load i64, ptr @M, align 8, !tbaa !5
  %7 = add nsw i64 %6, -1
  tail call void @_Z3auxxxxx(i64 noundef %.01619, i64 noundef %7, i64 noundef 0, i64 noundef -1)
  %8 = add nuw nsw i64 %.01619, 1
  %9 = load i64, ptr @N, align 8, !tbaa !5
  %10 = icmp slt i64 %8, %9
  br i1 %10, label %.lr.ph, label %.preheader18, !llvm.loop !9

.preheader17.loopexit:                            ; preds = %.lr.ph21
  %.pre = load i64, ptr @N, align 8, !tbaa !5
  br label %.preheader17

.preheader17:                                     ; preds = %.preheader17.loopexit, %.preheader18
  %11 = phi i64 [ %3, %.preheader18 ], [ %.pre, %.preheader17.loopexit ]
  %.lcssa = phi i64 [ %4, %.preheader18 ], [ %41, %.preheader17.loopexit ]
  %12 = icmp sgt i64 %11, 0
  %13 = icmp sgt i64 %.lcssa, 0
  %or.cond = and i1 %12, %13
  br i1 %or.cond, label %.preheader.us.preheader, label %._crit_edge31

.preheader.us.preheader:                          ; preds = %.preheader17
  %ans.promoted24 = load i64, ptr @ans, align 8, !tbaa !5
  %xtraiter = and i64 %.lcssa, 1
  %14 = icmp eq i64 %.lcssa, 1
  %unroll_iter = and i64 %.lcssa, 9223372036854775806
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.preheader.us

.preheader.us:                                    ; preds = %.preheader.us.preheader, %._crit_edge.us
  %.01430.us = phi i64 [ %37, %._crit_edge.us ], [ 0, %.preheader.us.preheader ]
  %ans.promoted2829.us = phi i64 [ %ans.promoted26.us.lcssa, %._crit_edge.us ], [ %ans.promoted24, %.preheader.us.preheader ]
  br i1 %14, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new

.preheader.us.new:                                ; preds = %.preheader.us, %29
  %ans.promoted27.us = phi i64 [ %ans.promoted26.us.1, %29 ], [ %ans.promoted2829.us, %.preheader.us ]
  %.022.us = phi i64 [ %31, %29 ], [ 0, %.preheader.us ]
  %15 = phi i64 [ %30, %29 ], [ %ans.promoted2829.us, %.preheader.us ]
  %niter = phi i64 [ %niter.next.1, %29 ], [ 0, %.preheader.us ]
  %16 = getelementptr inbounds [1000 x [1000 x i8]], ptr @vis, i64 0, i64 %.01430.us, i64 %.022.us
  %17 = load i8, ptr %16, align 2, !tbaa !11, !range !13, !noundef !14
  %18 = trunc nuw i8 %17 to i1
  br i1 %18, label %19, label %21

19:                                               ; preds = %.preheader.us.new
  %20 = add nsw i64 %15, 1
  store i64 %20, ptr @ans, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %19, %.preheader.us.new
  %ans.promoted26.us = phi i64 [ %ans.promoted27.us, %.preheader.us.new ], [ %20, %19 ]
  %22 = phi i64 [ %15, %.preheader.us.new ], [ %20, %19 ]
  %23 = or disjoint i64 %.022.us, 1
  %24 = getelementptr inbounds [1000 x [1000 x i8]], ptr @vis, i64 0, i64 %.01430.us, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !11, !range !13, !noundef !14
  %26 = trunc nuw i8 %25 to i1
  br i1 %26, label %27, label %29

27:                                               ; preds = %21
  %28 = add nsw i64 %22, 1
  store i64 %28, ptr @ans, align 8, !tbaa !5
  br label %29

29:                                               ; preds = %27, %21
  %ans.promoted26.us.1 = phi i64 [ %ans.promoted26.us, %21 ], [ %28, %27 ]
  %30 = phi i64 [ %22, %21 ], [ %28, %27 ]
  %31 = add nuw nsw i64 %.022.us, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.us.unr-lcssa, label %.preheader.us.new, !llvm.loop !15

._crit_edge.us.unr-lcssa:                         ; preds = %29, %.preheader.us
  %ans.promoted26.us.lcssa.ph = phi i64 [ poison, %.preheader.us ], [ %ans.promoted26.us.1, %29 ]
  %ans.promoted27.us.unr = phi i64 [ %ans.promoted2829.us, %.preheader.us ], [ %ans.promoted26.us.1, %29 ]
  %.022.us.unr = phi i64 [ 0, %.preheader.us ], [ %31, %29 ]
  %.unr = phi i64 [ %ans.promoted2829.us, %.preheader.us ], [ %30, %29 ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa
  %32 = getelementptr inbounds [1000 x [1000 x i8]], ptr @vis, i64 0, i64 %.01430.us, i64 %.022.us.unr
  %33 = load i8, ptr %32, align 1, !tbaa !11, !range !13, !noundef !14
  %34 = trunc nuw i8 %33 to i1
  br i1 %34, label %35, label %._crit_edge.us

35:                                               ; preds = %.epil.preheader
  %36 = add nsw i64 %.unr, 1
  store i64 %36, ptr @ans, align 8, !tbaa !5
  br label %._crit_edge.us

._crit_edge.us:                                   ; preds = %.epil.preheader, %35, %._crit_edge.us.unr-lcssa
  %ans.promoted26.us.lcssa = phi i64 [ %ans.promoted26.us.lcssa.ph, %._crit_edge.us.unr-lcssa ], [ %ans.promoted27.us.unr, %.epil.preheader ], [ %36, %35 ]
  %37 = add nuw nsw i64 %.01430.us, 1
  %exitcond34.not = icmp eq i64 %37, %11
  br i1 %exitcond34.not, label %._crit_edge31, label %.preheader.us, !llvm.loop !16

.lr.ph21:                                         ; preds = %.preheader18, %.lr.ph21
  %.01520 = phi i64 [ %40, %.lr.ph21 ], [ 0, %.preheader18 ]
  tail call void @_Z3auxxxxx(i64 noundef 0, i64 noundef %.01520, i64 noundef 1, i64 noundef 0)
  %38 = load i64, ptr @N, align 8, !tbaa !5
  %39 = add nsw i64 %38, -1
  tail call void @_Z3auxxxxx(i64 noundef %39, i64 noundef %.01520, i64 noundef -1, i64 noundef 0)
  %40 = add nuw nsw i64 %.01520, 1
  %41 = load i64, ptr @M, align 8, !tbaa !5
  %42 = icmp slt i64 %40, %41
  br i1 %42, label %.lr.ph21, label %.preheader17.loopexit, !llvm.loop !17

._crit_edge31:                                    ; preds = %._crit_edge.us, %.preheader17
  ret void
}

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

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass