; LLVM IR from kazunetakahashi/atcoder :: 201411_201509/0412_ABC021/D.ll (Z1Cii)

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

@fact = external dso_local global [200010 x i64], align 16
@factinv = external dso_local global [200010 x i64], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i64 @_Z1Cii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i64, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp sge i32 %6, 0
  br i1 %7, label %8, label %35

8:                                                ; preds = %2
  %9 = load i32, ptr %5, align 4, !tbaa !5
  %10 = icmp sge i32 %9, 0
  br i1 %10, label %11, label %35

11:                                               ; preds = %8
  %12 = load i32, ptr %4, align 4, !tbaa !5
  %13 = load i32, ptr %5, align 4, !tbaa !5
  %14 = sub nsw i32 %12, %13
  %15 = icmp sge i32 %14, 0
  br i1 %15, label %16, label %35

16:                                               ; preds = %11
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [200010 x i64], ptr @fact, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [200010 x i64], ptr @factinv, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = mul nsw i64 %20, %24
  %26 = srem i64 %25, 1000000007
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = load i32, ptr %5, align 4, !tbaa !5
  %29 = sub nsw i32 %27, %28
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [200010 x i64], ptr @factinv, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = mul nsw i64 %26, %32
  %34 = srem i64 %33, 1000000007
  store i64 %34, ptr %3, align 8
  br label %36

35:                                               ; preds = %11, %8, %2
  store i64 0, ptr %3, align 8
  br label %36

36:                                               ; preds = %35, %16
  %37 = load i64, ptr %3, align 8
  ret i64 %37
}

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}


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

@fact = external dso_local local_unnamed_addr global [200010 x i64], align 16
@factinv = external dso_local local_unnamed_addr global [200010 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef range(i64 -1000000006, 1000000007) i64 @_Z1Cii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = or i32 %1, %0
  %or.cond = icmp sgt i32 %3, -1
  br i1 %or.cond, label %4, label %21

4:                                                ; preds = %2
  %5 = sub nsw i32 %0, %1
  %6 = icmp sgt i32 %5, -1
  br i1 %6, label %7, label %21

7:                                                ; preds = %4
  %8 = zext nneg i32 %0 to i64
  %9 = getelementptr inbounds [200010 x i64], ptr @fact, i64 0, i64 %8
  %10 = load i64, ptr %9, align 8, !tbaa !5
  %11 = zext nneg i32 %1 to i64
  %12 = getelementptr inbounds [200010 x i64], ptr @factinv, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = mul nsw i64 %13, %10
  %15 = srem i64 %14, 1000000007
  %16 = zext nneg i32 %5 to i64
  %17 = getelementptr inbounds [200010 x i64], ptr @factinv, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = mul nsw i64 %15, %18
  %20 = srem i64 %19, 1000000007
  br label %21

21:                                               ; preds = %2, %4, %7
  %.0 = phi i64 [ %20, %7 ], [ 0, %4 ], [ 0, %2 ]
  ret i64 %.0
}

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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass