; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/MMOD29 (mod)

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

@n = external dso_local global i32, align 4
@mod = external dso_local global i32, align 4
@res = 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 @_Z3expxx(i64 noundef, i64 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  br label %3

3:                                                ; preds = %6, %0
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = icmp ne i32 %4, 0
  br i1 %5, label %6, label %44

6:                                                ; preds = %3
  %7 = load i32, ptr @n, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  %9 = sext i32 %8 to i64
  %10 = call noundef i64 @_Z3expxx(i64 noundef 167, i64 noundef %9)
  %11 = add nsw i64 %10, 28
  %12 = load i32, ptr @mod, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = srem i64 %11, %13
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  %17 = sext i32 %16 to i64
  %18 = call noundef i64 @_Z3expxx(i64 noundef 3, i64 noundef %17)
  %19 = add nsw i64 %18, 28
  %20 = load i32, ptr @mod, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = srem i64 %19, %21
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = mul nsw i32 2, %23
  %25 = add nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = call noundef i64 @_Z3expxx(i64 noundef 2, i64 noundef %26)
  %28 = add nsw i64 %27, 28
  %29 = mul nsw i64 %22, %28
  %30 = load i32, ptr @mod, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = srem i64 %29, %31
  %33 = mul nsw i64 %14, %32
  %34 = load i32, ptr @mod, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = srem i64 %33, %35
  %37 = mul nsw i64 %36, 9
  %38 = load i32, ptr @mod, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = srem i64 %37, %39
  store i64 %40, ptr @res, align 8, !tbaa !9
  %41 = load i64, ptr @res, align 8, !tbaa !9
  %42 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %41)
  %43 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  br label %3, !llvm.loop !11

44:                                               ; preds = %3
  ret i32 0
}

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

declare i32 @printf(ptr noundef, ...) #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 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 = { "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}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@n = external dso_local global i32, align 4
@mod = external dso_local local_unnamed_addr global i32, align 4
@res = 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 @_Z3expxx(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not1 = icmp eq i32 %2, 0
  br i1 %.not1, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %.lr.ph
  %3 = phi i32 [ %35, %.lr.ph ], [ %2, %0 ]
  %4 = add nsw i32 %3, 1
  %5 = sext i32 %4 to i64
  %6 = tail call noundef i64 @_Z3expxx(i64 noundef 167, i64 noundef %5)
  %7 = add nsw i64 %6, 28
  %8 = load i32, ptr @mod, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = srem i64 %7, %9
  %11 = load i32, ptr @n, align 4, !tbaa !5
  %12 = add nsw i32 %11, 1
  %13 = sext i32 %12 to i64
  %14 = tail call noundef i64 @_Z3expxx(i64 noundef 3, i64 noundef %13)
  %15 = add nsw i64 %14, 28
  %16 = load i32, ptr @mod, align 4, !tbaa !5
  %17 = sext i32 %16 to i64
  %18 = srem i64 %15, %17
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = shl nsw i32 %19, 1
  %21 = or disjoint i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = tail call noundef i64 @_Z3expxx(i64 noundef 2, i64 noundef %22)
  %24 = add nsw i64 %23, 28
  %25 = mul nsw i64 %24, %18
  %26 = load i32, ptr @mod, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = srem i64 %25, %27
  %29 = mul nsw i64 %28, %10
  %30 = srem i64 %29, %27
  %31 = mul nsw i64 %30, 9
  %32 = srem i64 %31, %27
  store i64 %32, ptr @res, align 8, !tbaa !9
  %33 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %32)
  %34 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %.not = icmp eq i32 %35, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

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


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass