; LLVM IR from Aryansh-S/USACO :: USACO/2022/January/Bronze (moo_operations)

; 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 i32 @_Z5solveNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 1000000000, ptr %4, align 4, !tbaa !9
  %8 = call noundef i64 @_ZSt4sizeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEDTcldtfp_4sizeEERKT_(ptr noundef nonnull align 8 dereferenceable(32) %0) #4
  %9 = trunc i64 %8 to i32
  %10 = icmp eq i32 %9, 1
  br i1 %10, label %15, label %11

11:                                               ; preds = %1
  %12 = call noundef i64 @_ZSt4sizeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEDTcldtfp_4sizeEERKT_(ptr noundef nonnull align 8 dereferenceable(32) %0) #4
  %13 = trunc i64 %12 to i32
  %14 = icmp eq i32 %13, 2
  br i1 %14, label %15, label %16

15:                                               ; preds = %11, %1
  store i32 -1, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %68

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !9
  br label %17

17:                                               ; preds = %56, %16
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = call noundef i64 @_ZSt4sizeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEDTcldtfp_4sizeEERKT_(ptr noundef nonnull align 8 dereferenceable(32) %0) #4
  %20 = trunc i64 %19 to i32
  %21 = sub nsw i32 %20, 1
  %22 = icmp slt i32 %18, %21
  br i1 %22, label %24, label %23

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

24:                                               ; preds = %17
  %25 = load i32, ptr %6, align 4, !tbaa !9
  %26 = sext i32 %25 to i64
  %27 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %26)
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = sext i8 %28 to i32
  %30 = icmp eq i32 %29, 79
  br i1 %30, label %31, label %55

31:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %32 = call noundef i64 @_ZSt4sizeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEDTcldtfp_4sizeEERKT_(ptr noundef nonnull align 8 dereferenceable(32) %0) #4
  %33 = trunc i64 %32 to i32
  %34 = sub nsw i32 %33, 3
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = sub nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %37)
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = sext i8 %39 to i32
  %41 = icmp ne i32 %40, 77
  %42 = zext i1 %41 to i32
  %43 = add nsw i32 %34, %42
  %44 = load i32, ptr %6, align 4, !tbaa !9
  %45 = add nsw i32 %44, 1
  %46 = sext i32 %45 to i64
  %47 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %46)
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = sext i8 %48 to i32
  %50 = icmp ne i32 %49, 79
  %51 = zext i1 %50 to i32
  %52 = add nsw i32 %43, %51
  store i32 %52, ptr %7, align 4, !tbaa !9
  %53 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %54 = load i32, ptr %53, align 4, !tbaa !9
  store i32 %54, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %55

55:                                               ; preds = %31, %24
  br label %56

56:                                               ; preds = %55
  %57 = load i32, ptr %6, align 4, !tbaa !9
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %6, align 4, !tbaa !9
  br label %17, !llvm.loop !12

59:                                               ; preds = %23
  %60 = load i32, ptr %4, align 4, !tbaa !9
  %61 = sitofp i32 %60 to double
  %62 = fcmp oeq double %61, 1.000000e+09
  br i1 %62, label %63, label %64

63:                                               ; preds = %59
  br label %66

64:                                               ; preds = %59
  %65 = load i32, ptr %4, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %64, %63
  %67 = phi i32 [ -1, %63 ], [ %65, %64 ]
  store i32 %67, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %68

68:                                               ; preds = %66, %15
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %69 = load i32, ptr %2, align 4
  ret i32 %69
}

; 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 i64 @_ZSt4sizeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEDTcldtfp_4sizeEERKT_(ptr noundef nonnull align 8 dereferenceable(32)) #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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

; 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 = { inlinehint 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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 nounwind uwtable
define dso_local noundef i32 @_Z5solveNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE(ptr noundef nonnull %0) local_unnamed_addr #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  store i32 1000000000, ptr %2, align 4, !tbaa !5
  %4 = tail call noundef i64 @_ZSt4sizeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEDTcldtfp_4sizeEERKT_(ptr noundef nonnull align 8 dereferenceable(32) %0) #3
  %5 = and i64 %4, 4294967295
  %6 = icmp eq i64 %5, 1
  br i1 %6, label %41, label %7

7:                                                ; preds = %1
  %8 = tail call noundef i64 @_ZSt4sizeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEDTcldtfp_4sizeEERKT_(ptr noundef nonnull align 8 dereferenceable(32) %0) #3
  %9 = and i64 %8, 4294967295
  %10 = icmp eq i64 %9, 2
  br i1 %10, label %41, label %.preheader

.preheader:                                       ; preds = %7
  %11 = tail call noundef i64 @_ZSt4sizeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEDTcldtfp_4sizeEERKT_(ptr noundef nonnull align 8 dereferenceable(32) %0) #3
  %12 = trunc i64 %11 to i32
  %13 = icmp sgt i32 %12, 2
  br i1 %13, label %.lr.ph, label %._crit_edge.thread

._crit_edge:                                      ; preds = %36
  %.pre = load i32, ptr %2, align 4
  %.pre.fr = freeze i32 %.pre
  %14 = icmp eq i32 %.pre.fr, 1000000000
  br i1 %14, label %._crit_edge.thread, label %41

._crit_edge.thread:                               ; preds = %.preheader, %._crit_edge
  br label %41

.lr.ph:                                           ; preds = %.preheader, %36
  %indvars.iv = phi i64 [ %indvars.iv.next.pre-phi, %36 ], [ 1, %.preheader ]
  %15 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %indvars.iv)
  %16 = load i8, ptr %15, align 1, !tbaa !9
  %17 = icmp eq i8 %16, 79
  br i1 %17, label %18, label %.lr.ph._crit_edge

.lr.ph._crit_edge:                                ; preds = %.lr.ph
  %.pre9 = add nuw nsw i64 %indvars.iv, 1
  br label %36

18:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #3
  %19 = call noundef i64 @_ZSt4sizeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEDTcldtfp_4sizeEERKT_(ptr noundef nonnull align 8 dereferenceable(32) %0) #3
  %20 = trunc i64 %19 to i32
  %21 = add nsw i32 %20, -3
  %22 = add nsw i64 %indvars.iv, -1
  %23 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %22)
  %24 = load i8, ptr %23, align 1, !tbaa !9
  %25 = icmp ne i8 %24, 77
  %26 = zext i1 %25 to i32
  %27 = add nsw i32 %21, %26
  %28 = add nuw nsw i64 %indvars.iv, 1
  %29 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %28)
  %30 = load i8, ptr %29, align 1, !tbaa !9
  %31 = icmp ne i8 %30, 79
  %32 = zext i1 %31 to i32
  %33 = add nsw i32 %27, %32
  store i32 %33, ptr %3, align 4, !tbaa !5
  %34 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %35 = load i32, ptr %34, align 4, !tbaa !5
  store i32 %35, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  br label %36

36:                                               ; preds = %.lr.ph._crit_edge, %18
  %indvars.iv.next.pre-phi = phi i64 [ %.pre9, %.lr.ph._crit_edge ], [ %28, %18 ]
  %37 = call noundef i64 @_ZSt4sizeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEDTcldtfp_4sizeEERKT_(ptr noundef nonnull align 8 dereferenceable(32) %0) #3
  %38 = shl i64 %37, 32
  %sext = add i64 %38, -4294967296
  %39 = ashr exact i64 %sext, 32
  %40 = icmp slt i64 %indvars.iv.next.pre-phi, %39
  br i1 %40, label %.lr.ph, label %._crit_edge, !llvm.loop !10

41:                                               ; preds = %._crit_edge.thread, %._crit_edge, %1, %7
  %.06 = phi i32 [ -1, %7 ], [ -1, %1 ], [ -1, %._crit_edge.thread ], [ %.pre.fr, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  ret i32 %.06
}

; Function Attrs: mustprogress 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 i64 @_ZSt4sizeINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEDTcldtfp_4sizeEERKT_(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0

; 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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), 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 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 = !{!"int", !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"}


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