; LLVM IR from kazunetakahashi/atcoder :: 2017/0325_yahoo-procon2017-final/B.ll (Z3cntiii)

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

@N = external dso_local global i32, align 4
@M = external dso_local global i32, align 4
@A = external dso_local global [100010 x i64], align 16
@B = external dso_local global [100010 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z4takeiii(i32 noundef, i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z3cntiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %5, align 4, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !5
  %8 = load i32, ptr %6, align 4, !tbaa !5
  %9 = load i32, ptr @N, align 4, !tbaa !5
  %10 = icmp sge i32 %8, %9
  br i1 %10, label %15, label %11

11:                                               ; preds = %3
  %12 = load i32, ptr %7, align 4, !tbaa !5
  %13 = load i32, ptr @M, align 4, !tbaa !5
  %14 = icmp sge i32 %12, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %11, %3
  store i32 0, ptr %4, align 4
  br label %59

16:                                               ; preds = %11
  %17 = load i32, ptr %6, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [100010 x i64], ptr @A, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = trunc i64 %20 to i32
  %22 = load i32, ptr %7, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [100010 x i64], ptr @B, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !9
  %26 = trunc i64 %25 to i32
  %27 = load i32, ptr %5, align 4, !tbaa !5
  %28 = call noundef zeroext i1 @_Z4takeiii(i32 noundef %21, i32 noundef %26, i32 noundef %27)
  br i1 %28, label %29, label %37

29:                                               ; preds = %16
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = load i32, ptr %6, align 4, !tbaa !5
  %32 = add nsw i32 %31, 1
  %33 = load i32, ptr %7, align 4, !tbaa !5
  %34 = add nsw i32 %33, 1
  %35 = call noundef i32 @_Z3cntiii(i32 noundef %30, i32 noundef %32, i32 noundef %34)
  %36 = add nsw i32 1, %35
  store i32 %36, ptr %4, align 4
  br label %59

37:                                               ; preds = %16
  %38 = load i32, ptr %6, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [100010 x i64], ptr @A, i64 0, i64 %39
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = load i32, ptr %7, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [100010 x i64], ptr @B, i64 0, i64 %43
  %45 = load i64, ptr %44, align 8, !tbaa !9
  %46 = icmp slt i64 %41, %45
  br i1 %46, label %47, label %53

47:                                               ; preds = %37
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = load i32, ptr %6, align 4, !tbaa !5
  %50 = add nsw i32 %49, 1
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = call noundef i32 @_Z3cntiii(i32 noundef %48, i32 noundef %50, i32 noundef %51)
  store i32 %52, ptr %4, align 4
  br label %59

53:                                               ; preds = %37
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = load i32, ptr %6, align 4, !tbaa !5
  %56 = load i32, ptr %7, align 4, !tbaa !5
  %57 = add nsw i32 %56, 1
  %58 = call noundef i32 @_Z3cntiii(i32 noundef %54, i32 noundef %55, i32 noundef %57)
  store i32 %58, ptr %4, align 4
  br label %59

59:                                               ; preds = %53, %47, %29, %15
  %60 = load i32, ptr %4, align 4
  ret i32 %60
}

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 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 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


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

@N = external dso_local local_unnamed_addr global i32, align 4
@M = external dso_local local_unnamed_addr global i32, align 4
@A = external dso_local local_unnamed_addr global [100010 x i64], align 16
@B = external dso_local local_unnamed_addr global [100010 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z4takeiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_Z3cntiii(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = load i32, ptr @N, align 4, !tbaa !5
  %.not283340 = icmp sgt i32 %4, %1
  %5 = load i32, ptr @M, align 4
  %.not19293441 = icmp sgt i32 %5, %2
  %or.cond303542 = select i1 %.not283340, i1 %.not19293441, i1 false
  br i1 %or.cond303542, label %.lr.ph.lr.ph, label %tailrecurse.outer22._crit_edge

.lr.ph.lr.ph:                                     ; preds = %3, %tailrecurse.outer
  %.tr21.ph45 = phi i32 [ %19, %tailrecurse.outer ], [ %2, %3 ]
  %.tr20.ph44 = phi i32 [ %18, %tailrecurse.outer ], [ %1, %3 ]
  %accumulator.tr.ph43 = phi i32 [ %20, %tailrecurse.outer ], [ 0, %3 ]
  %6 = sext i32 %.tr20.ph44 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.lr.ph, %tailrecurse.outer22
  %indvars.iv56 = phi i64 [ %6, %.lr.ph.lr.ph ], [ %indvars.iv.next57, %tailrecurse.outer22 ]
  %.tr21.ph2437 = phi i32 [ %.tr21.ph45, %.lr.ph.lr.ph ], [ %27, %tailrecurse.outer22 ]
  %7 = getelementptr inbounds [100010 x i64], ptr @A, i64 0, i64 %indvars.iv56
  %8 = sext i32 %.tr21.ph2437 to i64
  %.pre = load i64, ptr %7, align 8, !tbaa !9
  br label %9

9:                                                ; preds = %.lr.ph, %tailrecurse
  %10 = phi i64 [ %.pre, %.lr.ph ], [ %24, %tailrecurse ]
  %indvars.iv = phi i64 [ %8, %.lr.ph ], [ %indvars.iv.next, %tailrecurse ]
  %11 = trunc i64 %10 to i32
  %12 = getelementptr inbounds [100010 x i64], ptr @B, i64 0, i64 %indvars.iv
  %13 = load i64, ptr %12, align 8, !tbaa !9
  %14 = trunc i64 %13 to i32
  %15 = tail call noundef zeroext i1 @_Z4takeiii(i32 noundef %11, i32 noundef %14, i32 noundef %0)
  br i1 %15, label %tailrecurse.outer, label %23

tailrecurse.outer:                                ; preds = %9
  %16 = trunc nsw i64 %indvars.iv56 to i32
  %17 = trunc nsw i64 %indvars.iv to i32
  %18 = add nsw i32 %16, 1
  %19 = add nsw i32 %17, 1
  %20 = add nuw nsw i32 %accumulator.tr.ph43, 1
  %21 = load i32, ptr @N, align 4, !tbaa !5
  %.not2833 = icmp sgt i32 %21, %18
  %22 = load i32, ptr @M, align 4
  %.not192934 = icmp sgt i32 %22, %19
  %or.cond3035 = select i1 %.not2833, i1 %.not192934, i1 false
  br i1 %or.cond3035, label %.lr.ph.lr.ph, label %tailrecurse.outer22._crit_edge

23:                                               ; preds = %9
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = load i64, ptr %12, align 8, !tbaa !9
  %26 = icmp slt i64 %24, %25
  br i1 %26, label %tailrecurse.outer22, label %tailrecurse

tailrecurse.outer22:                              ; preds = %23
  %27 = trunc nsw i64 %indvars.iv to i32
  %indvars.iv.next57 = add nsw i64 %indvars.iv56, 1
  %28 = load i32, ptr @N, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %.not28 = icmp slt i64 %indvars.iv.next57, %29
  %30 = load i32, ptr @M, align 4
  %.not1929 = icmp sgt i32 %30, %27
  %or.cond30 = select i1 %.not28, i1 %.not1929, i1 false
  br i1 %or.cond30, label %.lr.ph, label %tailrecurse.outer22._crit_edge

tailrecurse:                                      ; preds = %23
  %indvars.iv.next = add nsw i64 %indvars.iv, 1
  %31 = load i32, ptr @N, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %.not = icmp slt i64 %indvars.iv56, %32
  %33 = load i32, ptr @M, align 4
  %34 = sext i32 %33 to i64
  %.not19 = icmp slt i64 %indvars.iv.next, %34
  %or.cond = select i1 %.not, i1 %.not19, i1 false
  br i1 %or.cond, label %9, label %tailrecurse.outer22._crit_edge

tailrecurse.outer22._crit_edge:                   ; preds = %tailrecurse.outer, %tailrecurse.outer22, %tailrecurse, %3
  %accumulator.tr.ph.lcssa = phi i32 [ 0, %3 ], [ %accumulator.tr.ph43, %tailrecurse ], [ %accumulator.tr.ph43, %tailrecurse.outer22 ], [ %20, %tailrecurse.outer ]
  ret i32 %accumulator.tr.ph.lcssa
}

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

!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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}


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