; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/Codesprints 2016/Codesprint July/Problem D/D.ll (Z5solvev)

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

@f = external dso_local global [500100 x i64], align 16
@inv = external dso_local global [500100 x i64], align 16
@p1 = external dso_local global [500100 x i64], align 16
@p2 = external dso_local global [500100 x i64], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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 @_Z5solvev() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  store i64 0, ptr %3, align 8, !tbaa !5
  store i64 1, ptr @p2, align 16, !tbaa !5
  store i64 1, ptr @p1, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 1, ptr %4, align 4, !tbaa !9
  br label %7

7:                                                ; preds = %38, %0
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = load i32, ptr %2, align 4, !tbaa !9
  %10 = icmp sle i32 %8, %9
  br i1 %10, label %12, label %11

11:                                               ; preds = %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %41

12:                                               ; preds = %7
  %13 = load i32, ptr %4, align 4, !tbaa !9
  %14 = sub nsw i32 %13, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [500100 x i64], ptr @p1, i64 0, i64 %15
  %17 = load i64, ptr %16, align 8, !tbaa !5
  %18 = load i32, ptr %1, align 4, !tbaa !9
  %19 = sub nsw i32 %18, 1
  %20 = sext i32 %19 to i64
  %21 = mul nsw i64 %17, %20
  %22 = srem i64 %21, 1000000007
  %23 = load i32, ptr %4, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [500100 x i64], ptr @p1, i64 0, i64 %24
  store i64 %22, ptr %25, align 8, !tbaa !5
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = sub nsw i32 %26, 1
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [500100 x i64], ptr @p2, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = load i32, ptr %1, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = mul nsw i64 %30, %32
  %34 = srem i64 %33, 1000000007
  %35 = load i32, ptr %4, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [500100 x i64], ptr @p2, i64 0, i64 %36
  store i64 %34, ptr %37, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %12
  %39 = load i32, ptr %4, align 4, !tbaa !9
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %4, align 4, !tbaa !9
  br label %7, !llvm.loop !11

41:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %42 = load i32, ptr %1, align 4, !tbaa !9
  store i32 %42, ptr %5, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %93, %41
  %44 = load i32, ptr %5, align 4, !tbaa !9
  %45 = load i32, ptr %2, align 4, !tbaa !9
  %46 = icmp sle i32 %44, %45
  br i1 %46, label %48, label %47

47:                                               ; preds = %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %96

48:                                               ; preds = %43
  %49 = load i32, ptr %5, align 4, !tbaa !9
  %50 = load i32, ptr %1, align 4, !tbaa !9
  %51 = sub nsw i32 %49, %50
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [500100 x i64], ptr @p1, i64 0, i64 %52
  %54 = load i64, ptr %53, align 8, !tbaa !5
  %55 = load i32, ptr %2, align 4, !tbaa !9
  %56 = load i32, ptr %5, align 4, !tbaa !9
  %57 = sub nsw i32 %55, %56
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [500100 x i64], ptr @p2, i64 0, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !5
  %61 = mul nsw i64 %54, %60
  %62 = srem i64 %61, 1000000007
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = sub nsw i32 %63, 1
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [500100 x i64], ptr @f, i64 0, i64 %65
  %67 = load i64, ptr %66, align 8, !tbaa !5
  %68 = load i32, ptr %1, align 4, !tbaa !9
  %69 = sub nsw i32 %68, 1
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [500100 x i64], ptr @inv, i64 0, i64 %70
  %72 = load i64, ptr %71, align 8, !tbaa !5
  %73 = mul nsw i64 %67, %72
  %74 = srem i64 %73, 1000000007
  %75 = load i32, ptr %5, align 4, !tbaa !9
  %76 = load i32, ptr %1, align 4, !tbaa !9
  %77 = sub nsw i32 %75, %76
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [500100 x i64], ptr @inv, i64 0, i64 %78
  %80 = load i64, ptr %79, align 8, !tbaa !5
  %81 = mul nsw i64 %74, %80
  %82 = srem i64 %81, 1000000007
  %83 = mul nsw i64 %62, %82
  %84 = srem i64 %83, 1000000007
  %85 = load i64, ptr %3, align 8, !tbaa !5
  %86 = add nsw i64 %85, %84
  store i64 %86, ptr %3, align 8, !tbaa !5
  %87 = load i64, ptr %3, align 8, !tbaa !5
  %88 = icmp sge i64 %87, 1000000007
  br i1 %88, label %89, label %92

89:                                               ; preds = %48
  %90 = load i64, ptr %3, align 8, !tbaa !5
  %91 = sub nsw i64 %90, 1000000007
  store i64 %91, ptr %3, align 8, !tbaa !5
  br label %92

92:                                               ; preds = %89, %48
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr %5, align 4, !tbaa !9
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %5, align 4, !tbaa !9
  br label %43, !llvm.loop !13

96:                                               ; preds = %47
  %97 = load i64, ptr %3, align 8, !tbaa !5
  %98 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %97)
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret void
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #2

declare i32 @printf(ptr noundef, ...) #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 = { "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"}
!13 = distinct !{!13, !12}


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

@f = external dso_local local_unnamed_addr global [500100 x i64], align 16
@inv = external dso_local local_unnamed_addr global [500100 x i64], align 16
@p1 = external dso_local local_unnamed_addr global [500100 x i64], align 16
@p2 = external dso_local local_unnamed_addr global [500100 x i64], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

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

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

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #3
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2, ptr noundef nonnull %1)
  store i64 1, ptr @p2, align 16, !tbaa !5
  store i64 1, ptr @p1, align 16, !tbaa !5
  %4 = load i32, ptr %2, align 4, !tbaa !9
  %.not22 = icmp slt i32 %4, 1
  %.pre = load i32, ptr %1, align 4, !tbaa !9
  br i1 %.not22, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0
  %5 = add nsw i32 %.pre, -1
  %6 = sext i32 %5 to i64
  %7 = sext i32 %.pre to i64
  %8 = add nuw i32 %4, 1
  %wide.trip.count = zext i32 %8 to i64
  br label %16

._crit_edge:                                      ; preds = %16, %0
  %.not2124 = icmp sgt i32 %.pre, %4
  br i1 %.not2124, label %._crit_edge29, label %.lr.ph28

.lr.ph28:                                         ; preds = %._crit_edge
  %9 = add nsw i32 %.pre, -1
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [500100 x i64], ptr @inv, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !5
  %13 = sext i32 %.pre to i64
  %14 = sext i32 %4 to i64
  %15 = add i32 %4, 1
  br label %26

16:                                               ; preds = %.lr.ph, %16
  %17 = phi i64 [ 1, %.lr.ph ], [ %23, %16 ]
  %18 = phi i64 [ 1, %.lr.ph ], [ %20, %16 ]
  %indvars.iv = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next, %16 ]
  %19 = mul nsw i64 %18, %6
  %20 = srem i64 %19, 1000000007
  %21 = getelementptr inbounds [500100 x i64], ptr @p1, i64 0, i64 %indvars.iv
  store i64 %20, ptr %21, align 8, !tbaa !5
  %22 = mul nsw i64 %17, %7
  %23 = srem i64 %22, 1000000007
  %24 = getelementptr inbounds [500100 x i64], ptr @p2, i64 0, i64 %indvars.iv
  store i64 %23, ptr %24, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %16, !llvm.loop !11

._crit_edge29:                                    ; preds = %26, %._crit_edge
  %.017.lcssa = phi i64 [ 0, %._crit_edge ], [ %spec.select, %26 ]
  %25 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.017.lcssa)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  ret void

26:                                               ; preds = %.lr.ph28, %26
  %indvars.iv32 = phi i64 [ %13, %.lr.ph28 ], [ %indvars.iv.next33, %26 ]
  %.01725 = phi i64 [ 0, %.lr.ph28 ], [ %spec.select, %26 ]
  %27 = sub nsw i64 %indvars.iv32, %13
  %28 = getelementptr inbounds [500100 x i64], ptr @p1, i64 0, i64 %27
  %29 = load i64, ptr %28, align 8, !tbaa !5
  %30 = sub nsw i64 %14, %indvars.iv32
  %31 = getelementptr inbounds [500100 x i64], ptr @p2, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = mul nsw i64 %32, %29
  %34 = srem i64 %33, 1000000007
  %35 = add nsw i64 %indvars.iv32, -1
  %36 = getelementptr inbounds [500100 x i64], ptr @f, i64 0, i64 %35
  %37 = load i64, ptr %36, align 8, !tbaa !5
  %38 = mul nsw i64 %12, %37
  %39 = srem i64 %38, 1000000007
  %40 = getelementptr inbounds [500100 x i64], ptr @inv, i64 0, i64 %27
  %41 = load i64, ptr %40, align 8, !tbaa !5
  %42 = mul nsw i64 %39, %41
  %43 = srem i64 %42, 1000000007
  %44 = mul nsw i64 %43, %34
  %45 = srem i64 %44, 1000000007
  %46 = add nsw i64 %45, %.01725
  %47 = icmp sgt i64 %46, 1000000006
  %48 = add nsw i64 %46, -1000000007
  %spec.select = select i1 %47, i64 %48, i64 %46
  %indvars.iv.next33 = add nsw i64 %indvars.iv32, 1
  %lftr.wideiv = trunc i64 %indvars.iv.next33 to i32
  %exitcond35.not = icmp eq i32 %15, %lftr.wideiv
  br i1 %exitcond35.not, label %._crit_edge29, label %26, !llvm.loop !13
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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


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