; LLVM IR from kazunetakahashi/atcoder :: 2019/0224_ABC119 (D)

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

@A = external dso_local global i32, align 4
@B = external dso_local global i32, align 4
@Q = external dso_local global i32, align 4
@s = external dso_local global [100010 x i64], align 16
@t = external dso_local global [100010 x i64], align 16
@x = external dso_local global [100010 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5flushx(i64 noundef) #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %6 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @A)
  %7 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 4 dereferenceable(4) @B)
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 4 dereferenceable(4) @Q)
  store i64 -10000000000000007, ptr @s, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %9

9:                                                ; preds = %19, %0
  %10 = load i32, ptr %2, align 4, !tbaa !9
  %11 = load i32, ptr @A, align 4, !tbaa !9
  %12 = icmp sle i32 %10, %11
  br i1 %12, label %14, label %13

13:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %22

14:                                               ; preds = %9
  %15 = load i32, ptr %2, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [100010 x i64], ptr @s, i64 0, i64 %16
  %18 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %17)
  br label %19

19:                                               ; preds = %14
  %20 = load i32, ptr %2, align 4, !tbaa !9
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %2, align 4, !tbaa !9
  br label %9, !llvm.loop !11

22:                                               ; preds = %13
  %23 = load i32, ptr @A, align 4, !tbaa !9
  %24 = add nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [100010 x i64], ptr @s, i64 0, i64 %25
  store i64 10000000000000007, ptr %26, align 8, !tbaa !5
  %27 = load i32, ptr @A, align 4, !tbaa !9
  %28 = add nsw i32 %27, 2
  store i32 %28, ptr @A, align 4, !tbaa !9
  store i64 -10000000000000007, ptr @t, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %39, %22
  %30 = load i32, ptr %3, align 4, !tbaa !9
  %31 = load i32, ptr @B, align 4, !tbaa !9
  %32 = icmp sle i32 %30, %31
  br i1 %32, label %34, label %33

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

34:                                               ; preds = %29
  %35 = load i32, ptr %3, align 4, !tbaa !9
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [100010 x i64], ptr @t, i64 0, i64 %36
  %38 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %37)
  br label %39

39:                                               ; preds = %34
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %3, align 4, !tbaa !9
  br label %29, !llvm.loop !13

42:                                               ; preds = %33
  %43 = load i32, ptr @B, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [100010 x i64], ptr @t, i64 0, i64 %45
  store i64 10000000000000007, ptr %46, align 8, !tbaa !5
  %47 = load i32, ptr @B, align 4, !tbaa !9
  %48 = add nsw i32 %47, 2
  store i32 %48, ptr @B, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !9
  br label %49

49:                                               ; preds = %59, %42
  %50 = load i32, ptr %4, align 4, !tbaa !9
  %51 = load i32, ptr @Q, align 4, !tbaa !9
  %52 = icmp slt i32 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %62

54:                                               ; preds = %49
  %55 = load i32, ptr %4, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [100010 x i64], ptr @x, i64 0, i64 %56
  %58 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %57)
  br label %59

59:                                               ; preds = %54
  %60 = load i32, ptr %4, align 4, !tbaa !9
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %4, align 4, !tbaa !9
  br label %49, !llvm.loop !14

62:                                               ; preds = %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %73, %62
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = load i32, ptr @Q, align 4, !tbaa !9
  %66 = icmp slt i32 %64, %65
  br i1 %66, label %68, label %67

67:                                               ; preds = %63
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  br label %76

68:                                               ; preds = %63
  %69 = load i32, ptr %5, align 4, !tbaa !9
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [100010 x i64], ptr @x, i64 0, i64 %70
  %72 = load i64, ptr %71, align 8, !tbaa !5
  call void @_Z5flushx(i64 noundef %72)
  br label %73

73:                                               ; preds = %68
  %74 = load i32, ptr %5, align 4, !tbaa !9
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %5, align 4, !tbaa !9
  br label %63, !llvm.loop !15

76:                                               ; preds = %67
  %77 = load i32, ptr %1, align 4
  ret i32 %77
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) #3

; 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)) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress norecurse 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 = { "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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !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"

%"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 }

@A = external dso_local global i32, align 4
@B = external dso_local global i32, align 4
@Q = external dso_local global i32, align 4
@s = external dso_local global [100010 x i64], align 16
@t = external dso_local global [100010 x i64], align 16
@x = external dso_local global [100010 x i64], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5flushx(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @A)
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 4 dereferenceable(4) @B)
  %3 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 4 dereferenceable(4) @Q)
  store i64 -10000000000000007, ptr @s, align 16, !tbaa !5
  %4 = load i32, ptr @A, align 4, !tbaa !9
  %.not20 = icmp slt i32 %4, 1
  br i1 %.not20, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa19 = phi i32 [ %4, %0 ], [ %12, %.lr.ph ]
  %5 = add nsw i32 %.lcssa19, 1
  %6 = sext i32 %5 to i64
  %7 = getelementptr inbounds [100010 x i64], ptr @s, i64 0, i64 %6
  store i64 10000000000000007, ptr %7, align 8, !tbaa !5
  %8 = add nsw i32 %.lcssa19, 2
  store i32 %8, ptr @A, align 4, !tbaa !9
  store i64 -10000000000000007, ptr @t, align 16, !tbaa !5
  %9 = load i32, ptr @B, align 4, !tbaa !9
  %.not1822 = icmp slt i32 %9, 1
  br i1 %.not1822, label %._crit_edge26, label %.lr.ph25

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %10 = getelementptr inbounds [100010 x i64], ptr @s, i64 0, i64 %indvars.iv
  %11 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %10)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i32, ptr @A, align 4, !tbaa !9
  %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 !11

._crit_edge26:                                    ; preds = %.lr.ph25, %._crit_edge
  %.lcssa = phi i32 [ %9, %._crit_edge ], [ %22, %.lr.ph25 ]
  %14 = add nsw i32 %.lcssa, 1
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100010 x i64], ptr @t, i64 0, i64 %15
  store i64 10000000000000007, ptr %16, align 8, !tbaa !5
  %17 = add nsw i32 %.lcssa, 2
  store i32 %17, ptr @B, align 4, !tbaa !9
  %18 = load i32, ptr @Q, align 4, !tbaa !9
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.lr.ph30, label %._crit_edge33

.lr.ph25:                                         ; preds = %._crit_edge, %.lr.ph25
  %indvars.iv37 = phi i64 [ %indvars.iv.next38, %.lr.ph25 ], [ 1, %._crit_edge ]
  %20 = getelementptr inbounds [100010 x i64], ptr @t, i64 0, i64 %indvars.iv37
  %21 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %20)
  %indvars.iv.next38 = add nuw nsw i64 %indvars.iv37, 1
  %22 = load i32, ptr @B, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %.not18.not = icmp slt i64 %indvars.iv37, %23
  br i1 %.not18.not, label %.lr.ph25, label %._crit_edge26, !llvm.loop !13

.preheader:                                       ; preds = %.lr.ph30
  %24 = icmp sgt i32 %27, 0
  br i1 %24, label %.lr.ph32, label %._crit_edge33

.lr.ph30:                                         ; preds = %._crit_edge26, %.lr.ph30
  %indvars.iv40 = phi i64 [ %indvars.iv.next41, %.lr.ph30 ], [ 0, %._crit_edge26 ]
  %25 = getelementptr inbounds [100010 x i64], ptr @x, i64 0, i64 %indvars.iv40
  %26 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %25)
  %indvars.iv.next41 = add nuw nsw i64 %indvars.iv40, 1
  %27 = load i32, ptr @Q, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = icmp slt i64 %indvars.iv.next41, %28
  br i1 %29, label %.lr.ph30, label %.preheader, !llvm.loop !14

._crit_edge33:                                    ; preds = %.lr.ph32, %._crit_edge26, %.preheader
  ret i32 0

.lr.ph32:                                         ; preds = %.preheader, %.lr.ph32
  %indvars.iv43 = phi i64 [ %indvars.iv.next44, %.lr.ph32 ], [ 0, %.preheader ]
  %30 = getelementptr inbounds [100010 x i64], ptr @x, i64 0, i64 %indvars.iv43
  %31 = load i64, ptr %30, align 8, !tbaa !5
  tail call void @_Z5flushx(i64 noundef %31)
  %indvars.iv.next44 = add nuw nsw i64 %indvars.iv43, 1
  %32 = load i32, ptr @Q, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = icmp slt i64 %indvars.iv.next44, %33
  br i1 %34, label %.lr.ph32, label %._crit_edge33, !llvm.loop !15
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #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)) 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 = { mustprogress norecurse 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" }

!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}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}


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