; LLVM IR from kazunetakahashi/atcoder :: 2018/0421_ARC096/E.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"

@MOD = external dso_local global i64, align 8
@fact = external dso_local global [1000010 x i64], align 16
@factinv = external dso_local global [1000010 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 %37

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

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 %37

16:                                               ; preds = %11
  %17 = load i32, ptr %4, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [1000010 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 [1000010 x i64], ptr @factinv, i64 0, i64 %22
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = mul nsw i64 %20, %24
  %26 = load i64, ptr @MOD, align 8, !tbaa !9
  %27 = srem i64 %25, %26
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = load i32, ptr %5, align 4, !tbaa !5
  %30 = sub nsw i32 %28, %29
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [1000010 x i64], ptr @factinv, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !9
  %34 = mul nsw i64 %27, %33
  %35 = load i64, ptr @MOD, align 8, !tbaa !9
  %36 = srem i64 %34, %35
  store i64 %36, ptr %3, align 8
  br label %38

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

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

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"

@MOD = external dso_local local_unnamed_addr global i64, align 8
@fact = external dso_local local_unnamed_addr global [1000010 x i64], align 16
@factinv = external dso_local local_unnamed_addr global [1000010 x i64], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local noundef 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 %22

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

7:                                                ; preds = %4
  %8 = zext nneg i32 %0 to i64
  %9 = getelementptr inbounds [1000010 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 [1000010 x i64], ptr @factinv, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = mul nsw i64 %13, %10
  %15 = load i64, ptr @MOD, align 8, !tbaa !5
  %16 = srem i64 %14, %15
  %17 = zext nneg i32 %5 to i64
  %18 = getelementptr inbounds [1000010 x i64], ptr @factinv, i64 0, i64 %17
  %19 = load i64, ptr %18, align 8, !tbaa !5
  %20 = mul nsw i64 %19, %16
  %21 = srem i64 %20, %15
  br label %22

22:                                               ; preds = %2, %4, %7
  %.0 = phi i64 [ %21, %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