; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/RIVALS (rival)

; 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
@dp = external dso_local global [2000001 x i64], align 16
@MOD = external dso_local global i64, align 8
@result = external dso_local global i64, align 8
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 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 @_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 i32, align 4
  store i32 0, ptr %1, align 4
  store i64 1, ptr @dp, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %3

3:                                                ; preds = %21, %0
  %4 = load i32, ptr %2, align 4, !tbaa !9
  %5 = icmp sle i32 %4, 2000000
  br i1 %5, label %7, label %6

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

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

21:                                               ; preds = %7
  %22 = load i32, ptr %2, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %2, align 4, !tbaa !9
  br label %3, !llvm.loop !11

24:                                               ; preds = %6
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %26

26:                                               ; preds = %30, %24
  %27 = load i32, ptr @t, align 4, !tbaa !9
  %28 = add nsw i32 %27, -1
  store i32 %28, ptr @t, align 4, !tbaa !9
  %29 = icmp ne i32 %27, 0
  br i1 %29, label %30, label %57

30:                                               ; preds = %26
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @x, ptr noundef @y)
  %32 = load i32, ptr @x, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [2000001 x i64], ptr @dp, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !5
  %36 = call noundef i64 @_Z3invx(i64 noundef %35)
  %37 = load i32, ptr @y, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [2000001 x i64], ptr @dp, i64 0, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !5
  %41 = call noundef i64 @_Z3invx(i64 noundef %40)
  %42 = mul nsw i64 %36, %41
  %43 = load i64, ptr @MOD, align 8, !tbaa !5
  %44 = srem i64 %42, %43
  store i64 %44, ptr @result, align 8, !tbaa !5
  %45 = load i64, ptr @result, align 8, !tbaa !5
  %46 = load i32, ptr @x, align 4, !tbaa !9
  %47 = load i32, ptr @y, align 4, !tbaa !9
  %48 = add nsw i32 %46, %47
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [2000001 x i64], ptr @dp, i64 0, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !5
  %52 = mul nsw i64 %45, %51
  %53 = load i64, ptr @MOD, align 8, !tbaa !5
  %54 = srem i64 %52, %53
  store i64 %54, ptr @result, align 8, !tbaa !5
  %55 = load i64, ptr @result, align 8, !tbaa !5
  %56 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %55)
  br label %26, !llvm.loop !13

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


; 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
@dp = external dso_local local_unnamed_addr global [2000001 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
@x = external dso_local global i32, align 4
@y = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 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 @_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 %6

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

6:                                                ; preds = %6, %0
  %7 = phi i64 [ 1, %0 ], [ %12, %6 ]
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next.1, %6 ]
  %8 = mul nsw i64 %7, %indvars.iv
  %9 = srem i64 %8, %1
  %10 = getelementptr inbounds [2000001 x i64], ptr @dp, i64 0, i64 %indvars.iv
  store i64 %9, ptr %10, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %11 = mul nsw i64 %9, %indvars.iv.next
  %12 = srem i64 %11, %1
  %13 = getelementptr inbounds [2000001 x i64], ptr @dp, i64 0, i64 %indvars.iv.next
  store i64 %12, ptr %13, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 2000001
  br i1 %exitcond.not.1, label %2, label %6, !llvm.loop !11

.lr.ph:                                           ; preds = %2, %.lr.ph
  %14 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @x, ptr noundef nonnull @y)
  %15 = load i32, ptr @x, align 4, !tbaa !9
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [2000001 x i64], ptr @dp, i64 0, i64 %16
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = tail call noundef i64 @_Z3invx(i64 noundef %18)
  %20 = load i32, ptr @y, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [2000001 x i64], ptr @dp, i64 0, i64 %21
  %23 = load i64, ptr %22, align 8, !tbaa !5
  %24 = tail call noundef i64 @_Z3invx(i64 noundef %23)
  %25 = mul nsw i64 %24, %19
  %26 = load i64, ptr @MOD, align 8, !tbaa !5
  %27 = srem i64 %25, %26
  %28 = load i32, ptr @x, align 4, !tbaa !9
  %29 = load i32, ptr @y, align 4, !tbaa !9
  %30 = add nsw i32 %29, %28
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [2000001 x i64], ptr @dp, i64 0, i64 %31
  %33 = load i64, ptr %32, align 8, !tbaa !5
  %34 = mul nsw i64 %33, %27
  %35 = srem i64 %34, %26
  store i64 %35, ptr @result, align 8, !tbaa !5
  %36 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %35)
  %37 = load i32, ptr @t, align 4, !tbaa !9
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr @t, align 4, !tbaa !9
  %.not = icmp eq i32 %37, 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,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass