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

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

@__const.main.primes = external hidden unnamed_addr constant [3 x i32], align 4
@__const.main.powers = external hidden unnamed_addr constant [3 x i32], align 4
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z6bigmodiii(i32 noundef, i32 noundef, i32 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
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca [3 x i32], align 4
  %7 = alloca [3 x i32], align 4
  %8 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 12, ptr %6) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 4 @__const.main.primes, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 12, ptr %7) #5
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 @__const.main.powers, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 29, ptr %8, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %61, %0
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %11 = icmp eq i32 %10, 1
  br i1 %11, label %12, label %64

12:                                               ; preds = %9
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  br label %64

16:                                               ; preds = %12
  store i32 1, ptr %3, align 4, !tbaa !5
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %58, %16
  %18 = load i32, ptr %4, align 4, !tbaa !5
  %19 = icmp slt i32 %18, 3
  br i1 %19, label %20, label %61

20:                                               ; preds = %17
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [3 x i32], ptr %6, i64 0, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = load i32, ptr %4, align 4, !tbaa !5
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [3 x i32], ptr %7, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = mul nsw i32 %28, %29
  %31 = add nsw i32 %30, 1
  %32 = load i32, ptr %8, align 4, !tbaa !5
  %33 = call noundef i32 @_Z6bigmodiii(i32 noundef %24, i32 noundef %31, i32 noundef %32)
  %34 = sub nsw i32 %33, 1
  %35 = load i32, ptr %8, align 4, !tbaa !5
  %36 = add nsw i32 %34, %35
  %37 = load i32, ptr %8, align 4, !tbaa !5
  %38 = srem i32 %36, %37
  store i32 %38, ptr %5, align 4, !tbaa !5
  %39 = load i32, ptr %3, align 4, !tbaa !5
  %40 = load i32, ptr %5, align 4, !tbaa !5
  %41 = mul nsw i32 %39, %40
  %42 = load i32, ptr %8, align 4, !tbaa !5
  %43 = srem i32 %41, %42
  store i32 %43, ptr %3, align 4, !tbaa !5
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [3 x i32], ptr %6, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = sub nsw i32 %47, 1
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = sub nsw i32 %49, 2
  %51 = load i32, ptr %8, align 4, !tbaa !5
  %52 = call noundef i32 @_Z6bigmodiii(i32 noundef %48, i32 noundef %50, i32 noundef %51)
  store i32 %52, ptr %5, align 4, !tbaa !5
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = load i32, ptr %5, align 4, !tbaa !5
  %55 = mul nsw i32 %53, %54
  %56 = load i32, ptr %8, align 4, !tbaa !5
  %57 = srem i32 %55, %56
  store i32 %57, ptr %3, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %20
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %4, align 4, !tbaa !5
  br label %17, !llvm.loop !9

61:                                               ; preds = %17
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %62)
  br label %9, !llvm.loop !11

64:                                               ; preds = %15, %9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 12, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  ret i32 0
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

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

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

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { "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 #5 = { 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 = !{!"int", !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"

@__const.main.primes = external hidden unnamed_addr constant [3 x i32], align 4
@__const.main.powers = external hidden unnamed_addr constant [3 x i32], align 4
@.str = external hidden unnamed_addr constant [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z6bigmodiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress 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() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = icmp ne i32 %2, 1
  %4 = load i32, ptr %1, align 4
  %5 = icmp eq i32 %4, 0
  %or.cond21 = select i1 %3, i1 true, i1 %5
  br i1 %or.cond21, label %._crit_edge, label %.preheader.preheader

.preheader.preheader:                             ; preds = %0
  %.pre = load i32, ptr @__const.main.primes, align 4, !tbaa !5
  %.pre23 = load i32, ptr @__const.main.powers, align 4, !tbaa !5
  %.pre24 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.primes, i64 4), align 4, !tbaa !5
  %.pre25 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.powers, i64 4), align 4, !tbaa !5
  %.pre26 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.primes, i64 8), align 4, !tbaa !5
  %.pre27 = load i32, ptr getelementptr inbounds (i8, ptr @__const.main.powers, i64 8), align 4, !tbaa !5
  %6 = add nsw i32 %.pre, -1
  %7 = add nsw i32 %.pre24, -1
  %8 = add nsw i32 %.pre26, -1
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %9 = phi i32 [ %4, %.preheader.preheader ], [ %43, %.preheader ]
  %10 = mul nsw i32 %9, %.pre23
  %11 = add nsw i32 %10, 1
  %12 = call noundef i32 @_Z6bigmodiii(i32 noundef %.pre, i32 noundef %11, i32 noundef 29)
  %13 = add nsw i32 %12, 28
  %14 = srem i32 %13, 29
  %15 = call noundef i32 @_Z6bigmodiii(i32 noundef %6, i32 noundef 27, i32 noundef 29)
  %16 = mul nsw i32 %14, %15
  %17 = srem i32 %16, 29
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = mul nsw i32 %18, %.pre25
  %20 = add nsw i32 %19, 1
  %21 = call noundef i32 @_Z6bigmodiii(i32 noundef %.pre24, i32 noundef %20, i32 noundef 29)
  %22 = add nsw i32 %21, 28
  %23 = srem i32 %22, 29
  %24 = mul nsw i32 %23, %17
  %.lhs.trunc = trunc nsw i32 %24 to i16
  %25 = srem i16 %.lhs.trunc, 29
  %.sext = sext i16 %25 to i32
  %26 = call noundef i32 @_Z6bigmodiii(i32 noundef %7, i32 noundef 27, i32 noundef 29)
  %27 = mul nsw i32 %26, %.sext
  %28 = srem i32 %27, 29
  %29 = load i32, ptr %1, align 4, !tbaa !5
  %30 = mul nsw i32 %29, %.pre27
  %31 = add nsw i32 %30, 1
  %32 = call noundef i32 @_Z6bigmodiii(i32 noundef %.pre26, i32 noundef %31, i32 noundef 29)
  %33 = add nsw i32 %32, 28
  %34 = srem i32 %33, 29
  %35 = mul nsw i32 %34, %28
  %.lhs.trunc28 = trunc nsw i32 %35 to i16
  %36 = srem i16 %.lhs.trunc28, 29
  %.sext29 = sext i16 %36 to i32
  %37 = call noundef i32 @_Z6bigmodiii(i32 noundef %8, i32 noundef 27, i32 noundef 29)
  %38 = mul nsw i32 %37, %.sext29
  %39 = srem i32 %38, 29
  %40 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %39)
  %41 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %42 = icmp ne i32 %41, 1
  %43 = load i32, ptr %1, align 4
  %44 = icmp eq i32 %43, 0
  %or.cond = select i1 %42, i1 true, i1 %44
  br i1 %or.cond, label %._crit_edge, label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %.preheader, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

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

attributes #0 = { mustprogress 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 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 = { 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" }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass