; LLVM IR from kazunetakahashi/atcoder :: 2018/0311_ARC091/E.ll (Z2okv)

; 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 i64, align 8
@A = external dso_local global i64, align 8
@B = external dso_local global i64, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_Z2okv() #0 {
  %1 = load i64, ptr @A, align 8, !tbaa !5
  %2 = icmp sle i64 1, %1
  br i1 %2, label %3, label %27

3:                                                ; preds = %0
  %4 = load i64, ptr @A, align 8, !tbaa !5
  %5 = load i64, ptr @N, align 8, !tbaa !5
  %6 = icmp sle i64 %4, %5
  br i1 %6, label %7, label %27

7:                                                ; preds = %3
  %8 = load i64, ptr @B, align 8, !tbaa !5
  %9 = icmp sle i64 1, %8
  br i1 %9, label %10, label %27

10:                                               ; preds = %7
  %11 = load i64, ptr @B, align 8, !tbaa !5
  %12 = load i64, ptr @N, align 8, !tbaa !5
  %13 = icmp sle i64 %11, %12
  br i1 %13, label %14, label %27

14:                                               ; preds = %10
  %15 = load i64, ptr @A, align 8, !tbaa !5
  %16 = load i64, ptr @B, align 8, !tbaa !5
  %17 = add nsw i64 %15, %16
  %18 = load i64, ptr @N, align 8, !tbaa !5
  %19 = add nsw i64 %18, 1
  %20 = icmp sle i64 %17, %19
  br i1 %20, label %21, label %27

21:                                               ; preds = %14
  %22 = load i64, ptr @A, align 8, !tbaa !5
  %23 = load i64, ptr @B, align 8, !tbaa !5
  %24 = mul nsw i64 %22, %23
  %25 = load i64, ptr @N, align 8, !tbaa !5
  %26 = icmp sge i64 %24, %25
  br label %27

27:                                               ; preds = %21, %14, %10, %7, %3, %0
  %28 = phi i1 [ false, %14 ], [ false, %10 ], [ false, %7 ], [ false, %3 ], [ false, %0 ], [ %26, %21 ]
  ret i1 %28
}

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


; 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 i64, align 8
@A = external dso_local local_unnamed_addr global i64, align 8
@B = external dso_local local_unnamed_addr global i64, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z2okv() local_unnamed_addr #0 {
  %1 = load i64, ptr @A, align 8, !tbaa !5
  %2 = icmp sgt i64 %1, 0
  br i1 %2, label %3, label %15

3:                                                ; preds = %0
  %4 = load i64, ptr @N, align 8, !tbaa !5
  %5 = icmp sgt i64 %1, %4
  %6 = load i64, ptr @B, align 8
  %7 = icmp slt i64 %6, 1
  %.not = icmp sgt i64 %6, %4
  %8 = or i1 %7, %.not
  %or.cond5 = select i1 %5, i1 true, i1 %8
  br i1 %or.cond5, label %15, label %9

9:                                                ; preds = %3
  %10 = add nuw nsw i64 %6, %1
  %11 = add nuw nsw i64 %4, 1
  %.not4 = icmp ugt i64 %10, %11
  br i1 %.not4, label %15, label %12

12:                                               ; preds = %9
  %13 = mul nuw nsw i64 %6, %1
  %14 = icmp uge i64 %13, %4
  br label %15

15:                                               ; preds = %12, %9, %3, %0
  %16 = phi i1 [ false, %9 ], [ false, %3 ], [ false, %0 ], [ %14, %12 ]
  ret i1 %16
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SimplifyCFGPass