; LLVM IR from tangjz/acm-icpc :: codeforces/complete/1480B.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"

%"struct.std::pair" = type { i32, i32 }

@_ZZ5solvevE1a = external hidden global [100001 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5solvev() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @_ZZ5solvevE1a, ptr noundef getelementptr inbounds (%"struct.std::pair", ptr @_ZZ5solvevE1a, i32 0, i32 1), ptr noundef %1)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %24, %0
  %8 = load i32, ptr %3, align 4, !tbaa !5
  %9 = load i32, ptr %1, align 4, !tbaa !5
  %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 %3) #4
  br label %27

12:                                               ; preds = %7
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @_ZZ5solvevE1a, i64 0, i64 %14
  %16 = getelementptr inbounds %"struct.std::pair", ptr %15, i32 0, i32 0
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %16)
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @_ZZ5solvevE1a, i64 0, i64 %19
  %21 = getelementptr inbounds %"struct.std::pair", ptr %20, i32 0, i32 0
  %22 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %21)
  %23 = load i32, ptr %22, align 4, !tbaa !5
  store i32 %23, ptr %2, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %12
  %25 = load i32, ptr %3, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %3, align 4, !tbaa !5
  br label %7, !llvm.loop !9

27:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = sub nsw i32 0, %28
  %30 = sext i32 %29 to i64
  store i64 %30, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %61, %27
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr %1, align 4, !tbaa !5
  %34 = icmp sle i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %64

36:                                               ; preds = %31
  %37 = load i32, ptr %5, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @_ZZ5solvevE1a, i64 0, i64 %38
  %40 = getelementptr inbounds %"struct.std::pair", ptr %39, i32 0, i32 1
  %41 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %40)
  %42 = load i32, ptr %5, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @_ZZ5solvevE1a, i64 0, i64 %43
  %45 = getelementptr inbounds %"struct.std::pair", ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 4, !tbaa !13
  %47 = sub nsw i32 %46, 1
  %48 = load i32, ptr @_ZZ5solvevE1a, align 16, !tbaa !15
  %49 = sdiv i32 %47, %48
  %50 = sext i32 %49 to i64
  %51 = add nsw i64 %50, 1
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @_ZZ5solvevE1a, i64 0, i64 %53
  %55 = getelementptr inbounds %"struct.std::pair", ptr %54, i32 0, i32 0
  %56 = load i32, ptr %55, align 8, !tbaa !15
  %57 = sext i32 %56 to i64
  %58 = mul nsw i64 %51, %57
  %59 = load i64, ptr %4, align 8, !tbaa !11
  %60 = add nsw i64 %59, %58
  store i64 %60, ptr %4, align 8, !tbaa !11
  br label %61

61:                                               ; preds = %36
  %62 = load i32, ptr %5, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %5, align 4, !tbaa !5
  br label %31, !llvm.loop !16

64:                                               ; preds = %35
  %65 = load i64, ptr %4, align 8, !tbaa !11
  %66 = load i32, ptr getelementptr inbounds (%"struct.std::pair", ptr @_ZZ5solvevE1a, i32 0, i32 1), align 4, !tbaa !13
  %67 = sext i32 %66 to i64
  %68 = icmp slt i64 %65, %67
  %69 = zext i1 %68 to i64
  %70 = select i1 %68, ptr @.str.3, ptr @.str.4
  %71 = call i32 @puts(ptr noundef %70)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #4
  ret void
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_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

declare i32 @puts(ptr noundef) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"int", !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 = !{!"long long", !7, i64 0}
!13 = !{!14, !6, i64 4}
!14 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!15 = !{!14, !6, i64 0}
!16 = distinct !{!16, !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"

%"struct.std::pair" = type { i32, i32 }

@_ZZ5solvevE1a = external hidden global [100001 x %"struct.std::pair"], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5solvev() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @_ZZ5solvevE1a, ptr noundef nonnull getelementptr inbounds (i8, ptr @_ZZ5solvevE1a, i64 4), ptr noundef nonnull %1)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %.not14 = icmp slt i32 %4, 1
  br i1 %.not14, label %._crit_edge21, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %5 = icmp slt i32 %12, 1
  %6 = sub nsw i32 0, %11
  %7 = sext i32 %6 to i64
  br i1 %5, label %._crit_edge21, label %.lr.ph20

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %8 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @_ZZ5solvevE1a, i64 0, i64 %indvars.iv
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %8)
  %10 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %11 = load i32, ptr %10, align 4, !tbaa !5
  store i32 %11, ptr %2, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %.not.not = icmp slt i64 %indvars.iv, %13
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge21:                                    ; preds = %.lr.ph20, %0, %._crit_edge
  %.011.lcssa = phi i64 [ %7, %._crit_edge ], [ 0, %0 ], [ %31, %.lr.ph20 ]
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @_ZZ5solvevE1a, i64 4), align 4, !tbaa !11
  %15 = sext i32 %14 to i64
  %16 = icmp slt i64 %.011.lcssa, %15
  %17 = select i1 %16, ptr @.str.3, ptr @.str.4
  %18 = call i32 @puts(ptr noundef nonnull dereferenceable(1) %17)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret void

.lr.ph20:                                         ; preds = %._crit_edge, %.lr.ph20
  %indvars.iv23 = phi i64 [ %indvars.iv.next24, %.lr.ph20 ], [ 1, %._crit_edge ]
  %.01117 = phi i64 [ %31, %.lr.ph20 ], [ %7, %._crit_edge ]
  %19 = getelementptr inbounds [100001 x %"struct.std::pair"], ptr @_ZZ5solvevE1a, i64 0, i64 %indvars.iv23
  %20 = getelementptr inbounds i8, ptr %19, i64 4
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %20)
  %22 = load i32, ptr %20, align 4, !tbaa !11
  %23 = add nsw i32 %22, -1
  %24 = load i32, ptr @_ZZ5solvevE1a, align 16, !tbaa !13
  %25 = sdiv i32 %23, %24
  %26 = sext i32 %25 to i64
  %27 = add nsw i64 %26, 1
  %28 = load i32, ptr %19, align 8, !tbaa !13
  %29 = sext i32 %28 to i64
  %30 = mul nsw i64 %27, %29
  %31 = add nsw i64 %30, %.01117
  %indvars.iv.next24 = add nuw nsw i64 %indvars.iv23, 1
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %.not13.not = icmp slt i64 %indvars.iv23, %33
  br i1 %.not13.not, label %.lr.ph20, label %._crit_edge21, !llvm.loop !14
}

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #3

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

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !6, i64 4}
!12 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!13 = !{!12, !6, i64 0}
!14 = distinct !{!14, !10}


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