; LLVM IR from eyangch/competitive-programming :: AdventOfCode/2020/day11/2.ll (Z3cntxx)

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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@dx = external dso_local global [8 x i64], align 16
@dy = external dso_local global [8 x i64], align 16
@N = external dso_local global i64, align 8
@M = external dso_local global i64, align 8
@_Z1bB5cxx11 = external dso_local global %"class.std::vector", align 8

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

11:                                               ; preds = %75, %2
  %12 = load i64, ptr %6, align 8, !tbaa !5
  %13 = icmp slt i64 %12, 8
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  br label %78

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 1, ptr %8, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %70, %15
  br i1 true, label %18, label %17

17:                                               ; preds = %16
  store i32 5, ptr %7, align 4
  br label %73

18:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %19 = load i64, ptr %3, align 8, !tbaa !5
  %20 = load i64, ptr %8, align 8, !tbaa !5
  %21 = load i64, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds [8 x i64], ptr @dx, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = mul nsw i64 %20, %23
  %25 = add nsw i64 %19, %24
  store i64 %25, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %26 = load i64, ptr %4, align 8, !tbaa !5
  %27 = load i64, ptr %8, align 8, !tbaa !5
  %28 = load i64, ptr %6, align 8, !tbaa !5
  %29 = getelementptr inbounds [8 x i64], ptr @dy, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = mul nsw i64 %27, %30
  %32 = add nsw i64 %26, %31
  store i64 %32, ptr %10, align 8, !tbaa !5
  %33 = load i64, ptr %9, align 8, !tbaa !5
  %34 = icmp slt i64 %33, 0
  br i1 %34, label %54, label %35

35:                                               ; preds = %18
  %36 = load i64, ptr %10, align 8, !tbaa !5
  %37 = icmp slt i64 %36, 0
  br i1 %37, label %54, label %38

38:                                               ; preds = %35
  %39 = load i64, ptr %9, align 8, !tbaa !5
  %40 = load i64, ptr @N, align 8, !tbaa !5
  %41 = icmp sge i64 %39, %40
  br i1 %41, label %54, label %42

42:                                               ; preds = %38
  %43 = load i64, ptr %10, align 8, !tbaa !5
  %44 = load i64, ptr @M, align 8, !tbaa !5
  %45 = icmp sge i64 %43, %44
  br i1 %45, label %54, label %46

46:                                               ; preds = %42
  %47 = load i64, ptr %9, align 8, !tbaa !5
  %48 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @_Z1bB5cxx11, i64 noundef %47) #3
  %49 = load i64, ptr %10, align 8, !tbaa !5
  %50 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %48, i64 noundef %49)
  %51 = load i8, ptr %50, align 1, !tbaa !9
  %52 = sext i8 %51 to i32
  %53 = icmp eq i32 %52, 76
  br i1 %53, label %54, label %55

54:                                               ; preds = %46, %42, %38, %35, %18
  store i32 5, ptr %7, align 4
  br label %67

55:                                               ; preds = %46
  %56 = load i64, ptr %9, align 8, !tbaa !5
  %57 = call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @_Z1bB5cxx11, i64 noundef %56) #3
  %58 = load i64, ptr %10, align 8, !tbaa !5
  %59 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %57, i64 noundef %58)
  %60 = load i8, ptr %59, align 1, !tbaa !9
  %61 = sext i8 %60 to i32
  %62 = icmp eq i32 %61, 35
  br i1 %62, label %63, label %66

63:                                               ; preds = %55
  %64 = load i64, ptr %5, align 8, !tbaa !5
  %65 = add nsw i64 %64, 1
  store i64 %65, ptr %5, align 8, !tbaa !5
  store i32 5, ptr %7, align 4
  br label %67

66:                                               ; preds = %55
  store i32 0, ptr %7, align 4
  br label %67

67:                                               ; preds = %66, %63, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %68 = load i32, ptr %7, align 4
  switch i32 %68, label %73 [
    i32 0, label %69
  ]

69:                                               ; preds = %67
  br label %70

70:                                               ; preds = %69
  %71 = load i64, ptr %8, align 8, !tbaa !5
  %72 = add nsw i64 %71, 1
  store i64 %72, ptr %8, align 8, !tbaa !5
  br label %16, !llvm.loop !10

73:                                               ; preds = %67, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %74

74:                                               ; preds = %73
  br label %75

75:                                               ; preds = %74
  %76 = load i64, ptr %6, align 8, !tbaa !5
  %77 = add nsw i64 %76, 1
  store i64 %77, ptr %6, align 8, !tbaa !5
  br label %11, !llvm.loop !12

78:                                               ; preds = %14
  %79 = load i64, ptr %5, align 8, !tbaa !5
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret i64 %79
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #2 align 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 = { mustprogress 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 }

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}


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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::__cxx11::basic_string<char>, std::allocator<std::__cxx11::basic_string<char>>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@dx = external dso_local local_unnamed_addr global [8 x i64], align 16
@dy = external dso_local local_unnamed_addr global [8 x i64], align 16
@N = external dso_local local_unnamed_addr global i64, align 8
@M = external dso_local local_unnamed_addr global i64, align 8
@_Z1bB5cxx11 = external dso_local global %"class.std::vector", align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z3cntxx(i64 noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  br label %.preheader

.preheader:                                       ; preds = %2, %.thread
  %.049 = phi i64 [ 0, %2 ], [ %.232, %.thread ]
  %.02148 = phi i64 [ 0, %2 ], [ %37, %.thread ]
  %3 = getelementptr inbounds [8 x i64], ptr @dx, i64 0, i64 %.02148
  %4 = getelementptr inbounds [8 x i64], ptr @dy, i64 0, i64 %.02148
  %5 = load i64, ptr %3, align 8, !tbaa !5
  %6 = add nsw i64 %5, %0
  %7 = load i64, ptr %4, align 8, !tbaa !5
  %8 = add nsw i64 %7, %1
  %9 = icmp sgt i64 %6, -1
  %10 = icmp sgt i64 %8, -1
  %or.cond.not3537 = select i1 %9, i1 %10, i1 false
  %11 = load i64, ptr @N, align 8
  %.not38 = icmp slt i64 %6, %11
  %or.cond2739 = select i1 %or.cond.not3537, i1 %.not38, i1 false
  %12 = load i64, ptr @M, align 8
  %.not2640 = icmp slt i64 %8, %12
  %or.cond2841 = select i1 %or.cond2739, i1 %.not2640, i1 false
  br i1 %or.cond2841, label %.lr.ph, label %.thread

13:                                               ; preds = %.thread
  ret i64 %.232

14:                                               ; preds = %32
  %15 = add nuw nsw i64 %.02242, 1
  %16 = load i64, ptr %3, align 8, !tbaa !5
  %17 = mul nsw i64 %16, %15
  %18 = add nsw i64 %17, %0
  %19 = load i64, ptr %4, align 8, !tbaa !5
  %20 = mul nsw i64 %19, %15
  %21 = add nsw i64 %20, %1
  %22 = icmp sgt i64 %18, -1
  %23 = icmp sgt i64 %21, -1
  %or.cond.not35 = select i1 %22, i1 %23, i1 false
  %24 = load i64, ptr @N, align 8
  %.not = icmp slt i64 %18, %24
  %or.cond27 = select i1 %or.cond.not35, i1 %.not, i1 false
  %25 = load i64, ptr @M, align 8
  %.not26 = icmp slt i64 %21, %25
  %or.cond28 = select i1 %or.cond27, i1 %.not26, i1 false
  br i1 %or.cond28, label %.lr.ph, label %.thread, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader, %14
  %26 = phi i64 [ %21, %14 ], [ %8, %.preheader ]
  %27 = phi i64 [ %18, %14 ], [ %6, %.preheader ]
  %.143 = phi i64 [ %spec.select29, %14 ], [ %.049, %.preheader ]
  %.02242 = phi i64 [ %15, %14 ], [ 1, %.preheader ]
  %28 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @_Z1bB5cxx11, i64 noundef %27) #1
  %29 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %28, i64 noundef %26)
  %30 = load i8, ptr %29, align 1, !tbaa !11
  %31 = icmp eq i8 %30, 76
  br i1 %31, label %.thread, label %32

32:                                               ; preds = %.lr.ph
  %33 = tail call noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) @_Z1bB5cxx11, i64 noundef %27) #1
  %34 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %33, i64 noundef %26)
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %.not36 = icmp eq i8 %35, 35
  %36 = zext i1 %.not36 to i64
  %spec.select29 = add nsw i64 %.143, %36
  br i1 %.not36, label %.thread, label %14

.thread:                                          ; preds = %32, %.lr.ph, %14, %.preheader
  %.232 = phi i64 [ %.049, %.preheader ], [ %spec.select29, %14 ], [ %.143, %.lr.ph ], [ %spec.select29, %32 ]
  %37 = add nuw nsw i64 %.02148, 1
  %exitcond.not = icmp eq i64 %37, 8
  br i1 %exitcond.not, label %13, label %.preheader, !llvm.loop !12
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(32) ptr @_ZNSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS5_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #0 align 2

attributes #0 = { mustprogress 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 = { 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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass