; LLVM IR from VastoLorde95/Competitive-Programming :: CodeChef/LONG/APRIL15/CSEQ (cseq)

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

@t = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@l = external dso_local global i64, align 8
@r = external dso_local global i64, align 8
@mod = external dso_local global i64, align 8
@res = external dso_local global i64, align 8
@fact = external dso_local global [1000005 x i64], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z1Cxxx(i64 noundef, i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  store i64 1, ptr @fact, align 16, !tbaa !5
  store i64 1, ptr getelementptr inbounds ([1000005 x i64], ptr @fact, i64 0, i64 1), align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store i64 2, ptr %2, align 8, !tbaa !5
  br label %3

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

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

8:                                                ; preds = %3
  %9 = load i64, ptr %2, align 8, !tbaa !5
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = sub nsw i64 %10, 1
  %12 = getelementptr inbounds [1000005 x i64], ptr @fact, i64 0, i64 %11
  %13 = load i64, ptr %12, align 8, !tbaa !5
  %14 = mul nsw i64 %9, %13
  %15 = load i64, ptr @mod, align 8, !tbaa !5
  %16 = srem i64 %14, %15
  %17 = load i64, ptr %2, align 8, !tbaa !5
  %18 = getelementptr inbounds [1000005 x i64], ptr @fact, i64 0, i64 %17
  store i64 %16, ptr %18, align 8, !tbaa !5
  br label %19

19:                                               ; preds = %8
  %20 = load i64, ptr %2, align 8, !tbaa !5
  %21 = add nsw i64 %20, 1
  store i64 %21, ptr %2, align 8, !tbaa !5
  br label %3, !llvm.loop !9

22:                                               ; preds = %7
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %24

24:                                               ; preds = %28, %22
  %25 = load i64, ptr @t, align 8, !tbaa !5
  %26 = add nsw i64 %25, -1
  store i64 %26, ptr @t, align 8, !tbaa !5
  %27 = icmp ne i64 %25, 0
  br i1 %27, label %28, label %49

28:                                               ; preds = %24
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @l, ptr noundef @r)
  %30 = load i64, ptr @r, align 8, !tbaa !5
  %31 = load i64, ptr @l, align 8, !tbaa !5
  %32 = sub nsw i64 %30, %31
  %33 = add nsw i64 %32, 1
  %34 = load i64, ptr @n, align 8, !tbaa !5
  %35 = add nsw i64 %33, %34
  %36 = load i64, ptr @r, align 8, !tbaa !5
  %37 = load i64, ptr @l, align 8, !tbaa !5
  %38 = sub nsw i64 %36, %37
  %39 = add nsw i64 %38, 1
  %40 = load i64, ptr @mod, align 8, !tbaa !5
  %41 = call noundef i64 @_Z1Cxxx(i64 noundef %35, i64 noundef %39, i64 noundef %40)
  %42 = sub nsw i64 %41, 1
  %43 = load i64, ptr @mod, align 8, !tbaa !5
  %44 = add nsw i64 %42, %43
  %45 = load i64, ptr @mod, align 8, !tbaa !5
  %46 = srem i64 %44, %45
  store i64 %46, ptr @res, align 8, !tbaa !5
  %47 = load i64, ptr @res, align 8, !tbaa !5
  %48 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %47)
  br label %24, !llvm.loop !11

49:                                               ; preds = %24
  %50 = load i32, ptr %1, align 4
  ret i32 %50
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #3

declare i32 @printf(ptr noundef, ...) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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

@t = external dso_local global i64, align 8
@n = external dso_local global i64, align 8
@l = external dso_local global i64, align 8
@r = external dso_local global i64, align 8
@mod = external dso_local local_unnamed_addr global i64, align 8
@res = external dso_local local_unnamed_addr global i64, align 8
@fact = external dso_local local_unnamed_addr global [1000005 x i64], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z1Cxxx(i64 noundef, i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  store i64 1, ptr @fact, align 16, !tbaa !5
  store i64 1, ptr getelementptr inbounds (i8, ptr @fact, i64 8), align 8, !tbaa !5
  %1 = load i64, ptr @mod, align 8, !tbaa !5
  %.not8 = icmp slt i64 %1, 2
  br i1 %.not8, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %2 = add nsw i64 %1, -1
  %xtraiter = and i64 %2, 1
  %3 = icmp eq i64 %1, 2
  br i1 %3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %2, -2
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.unr = phi i64 [ 1, %.lr.ph.preheader ], [ %16, %.lr.ph ]
  %.09.unr = phi i64 [ 2, %.lr.ph.preheader ], [ %18, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %4 = mul nsw i64 %.unr, %.09.unr
  %5 = srem i64 %4, %1
  %6 = getelementptr inbounds [1000005 x i64], ptr @fact, i64 0, i64 %.09.unr
  store i64 %5, ptr %6, align 8, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %0
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %8 = load i64, ptr @t, align 8, !tbaa !5
  %9 = add nsw i64 %8, -1
  store i64 %9, ptr @t, align 8, !tbaa !5
  %.not710 = icmp eq i64 %8, 0
  br i1 %.not710, label %._crit_edge13, label %.lr.ph12

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %10 = phi i64 [ 1, %.lr.ph.preheader.new ], [ %16, %.lr.ph ]
  %.09 = phi i64 [ 2, %.lr.ph.preheader.new ], [ %18, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %11 = mul nsw i64 %10, %.09
  %12 = srem i64 %11, %1
  %13 = getelementptr inbounds [1000005 x i64], ptr @fact, i64 0, i64 %.09
  store i64 %12, ptr %13, align 16, !tbaa !5
  %14 = or disjoint i64 %.09, 1
  %15 = mul nsw i64 %12, %14
  %16 = srem i64 %15, %1
  %17 = getelementptr inbounds [1000005 x i64], ptr @fact, i64 0, i64 %14
  store i64 %16, ptr %17, align 8, !tbaa !5
  %18 = add nuw i64 %.09, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !9

.lr.ph12:                                         ; preds = %._crit_edge, %.lr.ph12
  %19 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @l, ptr noundef nonnull @r)
  %20 = load i64, ptr @r, align 8, !tbaa !5
  %21 = load i64, ptr @l, align 8, !tbaa !5
  %22 = sub nsw i64 %20, %21
  %23 = add nsw i64 %22, 1
  %24 = load i64, ptr @n, align 8, !tbaa !5
  %25 = add nsw i64 %23, %24
  %26 = load i64, ptr @mod, align 8, !tbaa !5
  %27 = tail call noundef i64 @_Z1Cxxx(i64 noundef %25, i64 noundef %23, i64 noundef %26)
  %28 = add nsw i64 %27, -1
  %29 = load i64, ptr @mod, align 8, !tbaa !5
  %30 = add nsw i64 %28, %29
  %31 = srem i64 %30, %29
  store i64 %31, ptr @res, align 8, !tbaa !5
  %32 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %31)
  %33 = load i64, ptr @t, align 8, !tbaa !5
  %34 = add nsw i64 %33, -1
  store i64 %34, ptr @t, align 8, !tbaa !5
  %.not7 = icmp eq i64 %33, 0
  br i1 %.not7, label %._crit_edge13, label %.lr.ph12, !llvm.loop !11

._crit_edge13:                                    ; preds = %.lr.ph12, %._crit_edge
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

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 norecurse 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 #2 = { nofree nounwind "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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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