; LLVM IR from AdarshGaur/Competitive-Programming :: SPOJ/UCV2013E - Greedy Walking.ll (Z5solvex)

; 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::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@f = external dso_local global [10001 x i64], align 16
@invf = external dso_local global [10001 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

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

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

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

16:                                               ; preds = %25, %1
  %17 = load i64, ptr %8, align 8, !tbaa !5
  %18 = load i64, ptr %2, align 8, !tbaa !5
  %19 = icmp slt i64 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %28

21:                                               ; preds = %16
  %22 = load i64, ptr %8, align 8, !tbaa !5
  %23 = getelementptr inbounds i64, ptr %13, i64 %22
  %24 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %23)
  br label %25

25:                                               ; preds = %21
  %26 = load i64, ptr %8, align 8, !tbaa !5
  %27 = add nsw i64 %26, 1
  store i64 %27, ptr %8, align 8, !tbaa !5
  br label %16, !llvm.loop !9

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

29:                                               ; preds = %47, %28
  %30 = load i64, ptr %9, align 8, !tbaa !5
  %31 = load i64, ptr %2, align 8, !tbaa !5
  %32 = icmp slt i64 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %50

34:                                               ; preds = %29
  %35 = load i64, ptr %9, align 8, !tbaa !5
  %36 = getelementptr inbounds i64, ptr %15, i64 %35
  %37 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %36)
  %38 = load i64, ptr %9, align 8, !tbaa !5
  %39 = getelementptr inbounds i64, ptr %15, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = load i64, ptr %9, align 8, !tbaa !5
  %42 = getelementptr inbounds i64, ptr %13, i64 %41
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = sub nsw i64 %40, %43
  %45 = load i64, ptr %3, align 8, !tbaa !5
  %46 = add nsw i64 %45, %44
  store i64 %46, ptr %3, align 8, !tbaa !5
  br label %47

47:                                               ; preds = %34
  %48 = load i64, ptr %9, align 8, !tbaa !5
  %49 = add nsw i64 %48, 1
  store i64 %49, ptr %9, align 8, !tbaa !5
  br label %29, !llvm.loop !11

50:                                               ; preds = %33
  %51 = load i64, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds [10001 x i64], ptr @f, i64 0, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !5
  store i64 %53, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %73, %50
  %55 = load i64, ptr %10, align 8, !tbaa !5
  %56 = load i64, ptr %2, align 8, !tbaa !5
  %57 = icmp slt i64 %55, %56
  br i1 %57, label %59, label %58

58:                                               ; preds = %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %76

59:                                               ; preds = %54
  %60 = load i64, ptr %10, align 8, !tbaa !5
  %61 = getelementptr inbounds i64, ptr %15, i64 %60
  %62 = load i64, ptr %61, align 8, !tbaa !5
  %63 = load i64, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds i64, ptr %13, i64 %63
  %65 = load i64, ptr %64, align 8, !tbaa !5
  %66 = sub nsw i64 %62, %65
  store i64 %66, ptr %3, align 8, !tbaa !5
  %67 = load i64, ptr %4, align 8, !tbaa !5
  %68 = load i64, ptr %3, align 8, !tbaa !5
  %69 = getelementptr inbounds [10001 x i64], ptr @invf, i64 0, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !5
  %71 = mul i64 %67, %70
  %72 = urem i64 %71, 1000000007
  store i64 %72, ptr %4, align 8, !tbaa !5
  br label %73

73:                                               ; preds = %59
  %74 = load i64, ptr %10, align 8, !tbaa !5
  %75 = add nsw i64 %74, 1
  store i64 %75, ptr %10, align 8, !tbaa !5
  br label %54, !llvm.loop !12

76:                                               ; preds = %58
  %77 = load i64, ptr %4, align 8, !tbaa !5
  %78 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %77)
  %79 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %78, ptr noundef @.str)
  %80 = load ptr, ptr %5, align 8
  call void @llvm.stackrestore.p0(ptr %80)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #1 align 2

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { 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 #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 = !{!"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 = distinct !{!12, !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"

%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }

@f = external dso_local local_unnamed_addr global [10001 x i64], align 16
@invf = external dso_local local_unnamed_addr global [10001 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvex(i64 noundef %0) local_unnamed_addr #0 {
  %2 = alloca i64, i64 %0, align 16
  %3 = alloca i64, i64 %0, align 16
  %4 = icmp sgt i64 %0, 0
  br i1 %4, label %.lr.ph, label %._crit_edge.thread

.preheader:                                       ; preds = %.lr.ph
  br i1 %4, label %.lr.ph30, label %._crit_edge.thread

.lr.ph:                                           ; preds = %1, %.lr.ph
  %.02327 = phi i64 [ %7, %.lr.ph ], [ 0, %1 ]
  %5 = getelementptr inbounds i64, ptr %2, i64 %.02327
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %7 = add nuw nsw i64 %.02327, 1
  %exitcond.not = icmp eq i64 %7, %0
  br i1 %exitcond.not, label %.preheader, label %.lr.ph, !llvm.loop !5

._crit_edge.thread:                               ; preds = %.preheader, %1
  %8 = load i64, ptr @f, align 16, !tbaa !7
  br label %._crit_edge35

._crit_edge:                                      ; preds = %.lr.ph30
  %9 = getelementptr inbounds [10001 x i64], ptr @f, i64 0, i64 %18
  %10 = load i64, ptr %9, align 8, !tbaa !7
  br i1 %4, label %.lr.ph34.preheader, label %._crit_edge35

.lr.ph34.preheader:                               ; preds = %._crit_edge
  %xtraiter = and i64 %0, 1
  %11 = icmp eq i64 %0, 1
  br i1 %11, label %._crit_edge35.loopexit.unr-lcssa, label %.lr.ph34.preheader.new

.lr.ph34.preheader.new:                           ; preds = %.lr.ph34.preheader
  %unroll_iter = and i64 %0, 9223372036854775806
  br label %.lr.ph34

.lr.ph30:                                         ; preds = %.preheader, %.lr.ph30
  %.02229 = phi i64 [ %19, %.lr.ph30 ], [ 0, %.preheader ]
  %.02428 = phi i64 [ %18, %.lr.ph30 ], [ 0, %.preheader ]
  %12 = getelementptr inbounds i64, ptr %3, i64 %.02229
  %13 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %12)
  %14 = load i64, ptr %12, align 8, !tbaa !7
  %15 = getelementptr inbounds i64, ptr %2, i64 %.02229
  %16 = load i64, ptr %15, align 8, !tbaa !7
  %17 = add i64 %14, %.02428
  %18 = sub i64 %17, %16
  %19 = add nuw nsw i64 %.02229, 1
  %exitcond38.not = icmp eq i64 %19, %0
  br i1 %exitcond38.not, label %._crit_edge, label %.lr.ph30, !llvm.loop !11

._crit_edge35.loopexit.unr-lcssa:                 ; preds = %.lr.ph34, %.lr.ph34.preheader
  %.lcssa.ph = phi i64 [ poison, %.lr.ph34.preheader ], [ %49, %.lr.ph34 ]
  %.032.unr = phi i64 [ 0, %.lr.ph34.preheader ], [ %50, %.lr.ph34 ]
  %.02531.unr = phi i64 [ %10, %.lr.ph34.preheader ], [ %49, %.lr.ph34 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge35, label %.lr.ph34.epil

.lr.ph34.epil:                                    ; preds = %._crit_edge35.loopexit.unr-lcssa
  %20 = getelementptr inbounds i64, ptr %3, i64 %.032.unr
  %21 = load i64, ptr %20, align 8, !tbaa !7
  %22 = getelementptr inbounds i64, ptr %2, i64 %.032.unr
  %23 = load i64, ptr %22, align 8, !tbaa !7
  %24 = sub nsw i64 %21, %23
  %25 = getelementptr inbounds [10001 x i64], ptr @invf, i64 0, i64 %24
  %26 = load i64, ptr %25, align 8, !tbaa !7
  %27 = mul i64 %26, %.02531.unr
  %28 = urem i64 %27, 1000000007
  br label %._crit_edge35

._crit_edge35:                                    ; preds = %.lr.ph34.epil, %._crit_edge35.loopexit.unr-lcssa, %._crit_edge.thread, %._crit_edge
  %.025.lcssa = phi i64 [ %10, %._crit_edge ], [ %8, %._crit_edge.thread ], [ %.lcssa.ph, %._crit_edge35.loopexit.unr-lcssa ], [ %28, %.lr.ph34.epil ]
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.025.lcssa)
  %30 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %29, ptr noundef nonnull @.str)
  ret void

.lr.ph34:                                         ; preds = %.lr.ph34, %.lr.ph34.preheader.new
  %.032 = phi i64 [ 0, %.lr.ph34.preheader.new ], [ %50, %.lr.ph34 ]
  %.02531 = phi i64 [ %10, %.lr.ph34.preheader.new ], [ %49, %.lr.ph34 ]
  %niter = phi i64 [ 0, %.lr.ph34.preheader.new ], [ %niter.next.1, %.lr.ph34 ]
  %31 = getelementptr inbounds i64, ptr %3, i64 %.032
  %32 = load i64, ptr %31, align 16, !tbaa !7
  %33 = getelementptr inbounds i64, ptr %2, i64 %.032
  %34 = load i64, ptr %33, align 16, !tbaa !7
  %35 = sub nsw i64 %32, %34
  %36 = getelementptr inbounds [10001 x i64], ptr @invf, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !7
  %38 = mul i64 %37, %.02531
  %39 = urem i64 %38, 1000000007
  %40 = or disjoint i64 %.032, 1
  %41 = getelementptr inbounds i64, ptr %3, i64 %40
  %42 = load i64, ptr %41, align 8, !tbaa !7
  %43 = getelementptr inbounds i64, ptr %2, i64 %40
  %44 = load i64, ptr %43, align 8, !tbaa !7
  %45 = sub nsw i64 %42, %44
  %46 = getelementptr inbounds [10001 x i64], ptr @invf, i64 0, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !7
  %48 = mul i64 %47, %39
  %49 = urem i64 %48, 1000000007
  %50 = add nuw nsw i64 %.032, 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_edge35.loopexit.unr-lcssa, label %.lr.ph34, !llvm.loop !12
}

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #1

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

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"long long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}
!12 = distinct !{!12, !6}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass