; LLVM IR from tangjz/acm-icpc :: self_training/2015-01-29 (A)

; 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
@k = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3powiii(i32 noundef, i32 noundef, i32 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
  br label %2

2:                                                ; preds = %13, %0
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @k)
  %4 = icmp eq i32 %3, 2
  br i1 %4, label %5, label %11

5:                                                ; preds = %2
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp ne i32 %6, 0
  br i1 %7, label %8, label %11

8:                                                ; preds = %5
  %9 = load i32, ptr @k, align 4, !tbaa !5
  %10 = icmp ne i32 %9, 0
  br label %11

11:                                               ; preds = %8, %5, %2
  %12 = phi i1 [ false, %5 ], [ false, %2 ], [ %10, %8 ]
  br i1 %12, label %13, label %45

13:                                               ; preds = %11
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = mul nsw i32 3, %14
  %16 = add nsw i32 %15, 1
  %17 = load i32, ptr @k, align 4, !tbaa !5
  %18 = mul nsw i32 250, %17
  %19 = call noundef i32 @_Z3powiii(i32 noundef 2, i32 noundef %16, i32 noundef %18)
  %20 = load i32, ptr @k, align 4, !tbaa !5
  %21 = mul nsw i32 250, %20
  %22 = add nsw i32 %19, %21
  %23 = sext i32 %22 to i64
  %24 = sub nsw i64 %23, 1
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  %27 = load i32, ptr @k, align 4, !tbaa !5
  %28 = mul nsw i32 250, %27
  %29 = call noundef i32 @_Z3powiii(i32 noundef 251, i32 noundef %26, i32 noundef %28)
  %30 = load i32, ptr @k, align 4, !tbaa !5
  %31 = mul nsw i32 250, %30
  %32 = add nsw i32 %29, %31
  %33 = sext i32 %32 to i64
  %34 = sub nsw i64 %33, 1
  %35 = mul nsw i64 %24, %34
  %36 = load i32, ptr @k, align 4, !tbaa !5
  %37 = mul nsw i32 250, %36
  %38 = sext i32 %37 to i64
  %39 = srem i64 %35, %38
  %40 = sdiv i64 %39, 250
  %41 = trunc i64 %40 to i32
  %42 = load i32, ptr @k, align 4, !tbaa !5
  %43 = call noundef i32 @_Z3powiii(i32 noundef 2008, i32 noundef %41, i32 noundef %42)
  %44 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %43)
  br label %2, !llvm.loop !9

45:                                               ; preds = %11
  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 = distinct !{!9, !10}
!10 = !{!"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
@k = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3powiii(i32 noundef, i32 noundef, i32 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, ptr noundef nonnull @k)
  %2 = icmp eq i32 %1, 2
  %3 = load i32, ptr @n, align 4
  %4 = icmp ne i32 %3, 0
  %or.cond5 = select i1 %2, i1 %4, i1 false
  %5 = load i32, ptr @k, align 4
  %6 = icmp ne i32 %5, 0
  %or.cond36 = select i1 %or.cond5, i1 %6, i1 false
  br i1 %or.cond36, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %7 = phi i32 [ %36, %.lr.ph ], [ %5, %0 ]
  %8 = phi i32 [ %34, %.lr.ph ], [ %3, %0 ]
  %9 = mul nsw i32 %8, 3
  %10 = add nsw i32 %9, 1
  %11 = mul nsw i32 %7, 250
  %12 = tail call noundef i32 @_Z3powiii(i32 noundef 2, i32 noundef %10, i32 noundef %11)
  %13 = load i32, ptr @k, align 4, !tbaa !5
  %14 = mul nsw i32 %13, 250
  %15 = add nsw i32 %14, %12
  %16 = sext i32 %15 to i64
  %17 = add nsw i64 %16, -1
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = tail call noundef i32 @_Z3powiii(i32 noundef 251, i32 noundef %19, i32 noundef %14)
  %21 = load i32, ptr @k, align 4, !tbaa !5
  %22 = mul nsw i32 %21, 250
  %23 = add nsw i32 %22, %20
  %24 = sext i32 %23 to i64
  %25 = add nsw i64 %24, -1
  %26 = mul nsw i64 %25, %17
  %27 = sext i32 %22 to i64
  %28 = srem i64 %26, %27
  %.lhs.trunc = trunc nsw i64 %28 to i32
  %29 = sdiv i32 %.lhs.trunc, 250
  %30 = tail call noundef i32 @_Z3powiii(i32 noundef 2008, i32 noundef %29, i32 noundef %21)
  %31 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %30)
  %32 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @k)
  %33 = icmp eq i32 %32, 2
  %34 = load i32, ptr @n, align 4
  %35 = icmp ne i32 %34, 0
  %or.cond = select i1 %33, i1 %35, i1 false
  %36 = load i32, ptr @k, align 4
  %37 = icmp ne i32 %36, 0
  %or.cond3 = select i1 %or.cond, i1 %37, i1 false
  br i1 %or.cond3, label %.lr.ph, label %.critedge, !llvm.loop !9

.critedge:                                        ; 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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