; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/KOPC12B (kop)

; 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 i32, align 4
@n = external dso_local global i32, align 4
@dp = external dso_local global [2000002 x i64], align 16
@MOD = external dso_local global i64, align 8
@result = external dso_local global i64, align 8
@a = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 @dp, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store i64 1, ptr %2, align 8, !tbaa !5
  br label %3

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

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

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

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

21:                                               ; preds = %6
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  %23 = call noundef i64 @_Z3invx(i64 noundef 2)
  store i64 %23, ptr @a, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %28, %21
  %25 = load i32, ptr @t, align 4, !tbaa !11
  %26 = add nsw i32 %25, -1
  store i32 %26, ptr @t, align 4, !tbaa !11
  %27 = icmp ne i32 %25, 0
  br i1 %27, label %28, label %64

28:                                               ; preds = %24
  %29 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %30 = load i32, ptr @n, align 4, !tbaa !11
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2000002 x i64], ptr @dp, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = call noundef i64 @_Z3invx(i64 noundef %33)
  %35 = load i32, ptr @n, align 4, !tbaa !11
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [2000002 x i64], ptr @dp, i64 0, i64 %36
  %38 = load i64, ptr %37, align 8, !tbaa !5
  %39 = call noundef i64 @_Z3invx(i64 noundef %38)
  %40 = mul nsw i64 %34, %39
  %41 = load i64, ptr @MOD, align 8, !tbaa !5
  %42 = srem i64 %40, %41
  %43 = load i64, ptr @a, align 8, !tbaa !5
  %44 = mul nsw i64 %42, %43
  %45 = load i64, ptr @MOD, align 8, !tbaa !5
  %46 = srem i64 %44, %45
  store i64 %46, ptr @result, align 8, !tbaa !5
  %47 = load i64, ptr @result, align 8, !tbaa !5
  %48 = load i32, ptr @n, align 4, !tbaa !11
  %49 = load i32, ptr @n, align 4, !tbaa !11
  %50 = add nsw i32 %48, %49
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [2000002 x i64], ptr @dp, i64 0, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !5
  %54 = mul nsw i64 %47, %53
  %55 = load i64, ptr @MOD, align 8, !tbaa !5
  %56 = srem i64 %54, %55
  store i64 %56, ptr @result, align 8, !tbaa !5
  %57 = load i64, ptr @result, align 8, !tbaa !5
  %58 = load i32, ptr @n, align 4, !tbaa !11
  %59 = sext i32 %58 to i64
  %60 = mul nsw i64 %57, %59
  %61 = load i64, ptr @MOD, align 8, !tbaa !5
  %62 = srem i64 %60, %61
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %62)
  br label %24, !llvm.loop !13

64:                                               ; preds = %24
  ret i32 0
}

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !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 i32, align 4
@n = external dso_local global i32, align 4
@dp = external dso_local local_unnamed_addr global [2000002 x i64], align 16
@MOD = external dso_local local_unnamed_addr global i64, align 8
@result = external dso_local local_unnamed_addr global i64, align 8
@a = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3invx(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 @dp, align 16, !tbaa !5
  %1 = load i64, ptr @MOD, align 8, !tbaa !5
  br label %7

2:                                                ; preds = %7
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %4 = tail call noundef i64 @_Z3invx(i64 noundef 2)
  store i64 %4, ptr @a, align 8, !tbaa !5
  %5 = load i32, ptr @t, align 4, !tbaa !9
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @t, align 4, !tbaa !9
  %.not6 = icmp eq i32 %5, 0
  br i1 %.not6, label %._crit_edge, label %.lr.ph

7:                                                ; preds = %7, %0
  %8 = phi i64 [ 1, %0 ], [ %18, %7 ]
  %.05 = phi i64 [ 1, %0 ], [ %20, %7 ]
  %9 = mul nsw i64 %8, %.05
  %10 = srem i64 %9, %1
  %11 = getelementptr inbounds [2000002 x i64], ptr @dp, i64 0, i64 %.05
  store i64 %10, ptr %11, align 8, !tbaa !5
  %12 = add nuw nsw i64 %.05, 1
  %13 = mul nsw i64 %10, %12
  %14 = srem i64 %13, %1
  %15 = getelementptr inbounds [2000002 x i64], ptr @dp, i64 0, i64 %12
  store i64 %14, ptr %15, align 8, !tbaa !5
  %16 = add nuw nsw i64 %.05, 2
  %17 = mul nsw i64 %14, %16
  %18 = srem i64 %17, %1
  %19 = getelementptr inbounds [2000002 x i64], ptr @dp, i64 0, i64 %16
  store i64 %18, ptr %19, align 8, !tbaa !5
  %20 = add nuw nsw i64 %.05, 3
  %exitcond.not.2 = icmp eq i64 %20, 2000002
  br i1 %exitcond.not.2, label %2, label %7, !llvm.loop !11

.lr.ph:                                           ; preds = %2, %.lr.ph
  %21 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %22 = load i32, ptr @n, align 4, !tbaa !9
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [2000002 x i64], ptr @dp, i64 0, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = tail call noundef i64 @_Z3invx(i64 noundef %25)
  %27 = load i32, ptr @n, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [2000002 x i64], ptr @dp, i64 0, i64 %28
  %30 = load i64, ptr %29, align 8, !tbaa !5
  %31 = tail call noundef i64 @_Z3invx(i64 noundef %30)
  %32 = mul nsw i64 %31, %26
  %33 = load i64, ptr @MOD, align 8, !tbaa !5
  %34 = srem i64 %32, %33
  %35 = load i64, ptr @a, align 8, !tbaa !5
  %36 = mul nsw i64 %35, %34
  %37 = srem i64 %36, %33
  %38 = load i32, ptr @n, align 4, !tbaa !9
  %39 = shl nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [2000002 x i64], ptr @dp, i64 0, i64 %40
  %42 = load i64, ptr %41, align 16, !tbaa !5
  %43 = mul nsw i64 %42, %37
  %44 = srem i64 %43, %33
  store i64 %44, ptr @result, align 8, !tbaa !5
  %45 = sext i32 %38 to i64
  %46 = mul nsw i64 %44, %45
  %47 = srem i64 %46, %33
  %48 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %47)
  %49 = load i32, ptr @t, align 4, !tbaa !9
  %50 = add nsw i32 %49, -1
  store i32 %50, ptr @t, align 4, !tbaa !9
  %.not = icmp eq i32 %49, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %2
  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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


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