; LLVM IR from tangjz/acm-icpc :: self_training/2015-04-25 (H)

; 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 i64, align 8
@m = 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 [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3incRxx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3powxy(i64 noundef, 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
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %4

4:                                                ; preds = %56, %0
  %5 = load i32, ptr @t, align 4, !tbaa !5
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr @t, align 4, !tbaa !5
  %7 = icmp ne i32 %5, 0
  br i1 %7, label %8, label %57

8:                                                ; preds = %4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m)
  %10 = load i64, ptr @n, align 8, !tbaa !9
  %11 = icmp eq i64 %10, 1
  br i1 %11, label %12, label %14

12:                                               ; preds = %8
  %13 = call i32 @puts(ptr noundef @.str.2)
  br label %56

14:                                               ; preds = %8
  %15 = load i64, ptr @n, align 8, !tbaa !9
  %16 = icmp eq i64 %15, 2
  br i1 %16, label %17, label %21

17:                                               ; preds = %14
  %18 = load i64, ptr @m, align 8, !tbaa !9
  %19 = sub nsw i64 %18, 1
  %20 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %19)
  br label %55

21:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %22 = load i64, ptr @m, align 8, !tbaa !9
  %23 = sub nsw i64 %22, 1
  %24 = load i64, ptr @n, align 8, !tbaa !9
  %25 = call noundef i64 @_Z3powxy(i64 noundef %23, i64 noundef %24)
  store i64 %25, ptr %2, align 8, !tbaa !9
  %26 = load i64, ptr %2, align 8, !tbaa !9
  %27 = icmp ne i64 %26, 0
  br i1 %27, label %28, label %35

28:                                               ; preds = %21
  %29 = load i64, ptr @n, align 8, !tbaa !9
  %30 = and i64 %29, 1
  %31 = icmp ne i64 %30, 0
  br i1 %31, label %32, label %35

32:                                               ; preds = %28
  %33 = load i64, ptr %2, align 8, !tbaa !9
  %34 = sub nsw i64 1000000007, %33
  store i64 %34, ptr %2, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %32, %28, %21
  %36 = load i64, ptr @m, align 8, !tbaa !9
  %37 = sub nsw i64 %36, 1
  call void @_Z3incRxx(ptr noundef nonnull align 8 dereferenceable(8) %2, i64 noundef %37)
  %38 = load i64, ptr %2, align 8, !tbaa !9
  %39 = load i64, ptr @m, align 8, !tbaa !9
  %40 = call noundef i64 @_Z3powxy(i64 noundef %39, i64 noundef 1000000005)
  %41 = mul nsw i64 %38, %40
  %42 = srem i64 %41, 1000000007
  store i64 %42, ptr %2, align 8, !tbaa !9
  %43 = load i64, ptr %2, align 8, !tbaa !9
  %44 = icmp ne i64 %43, 0
  br i1 %44, label %45, label %52

45:                                               ; preds = %35
  %46 = load i64, ptr @n, align 8, !tbaa !9
  %47 = and i64 %46, 1
  %48 = icmp ne i64 %47, 0
  br i1 %48, label %49, label %52

49:                                               ; preds = %45
  %50 = load i64, ptr %2, align 8, !tbaa !9
  %51 = sub nsw i64 1000000007, %50
  store i64 %51, ptr %2, align 8, !tbaa !9
  br label %52

52:                                               ; preds = %49, %45, %35
  %53 = load i64, ptr %2, align 8, !tbaa !9
  %54 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %53)
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  br label %55

55:                                               ; preds = %52, %17
  br label %56

56:                                               ; preds = %55, %12
  br label %4, !llvm.loop !11

57:                                               ; preds = %4
  ret i32 0
}

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

declare i32 @puts(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 = !{!"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"

@t = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@m = 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 [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z3incRxx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z3powxy(i64 noundef, i64 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 nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i64, align 8
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %3 = load i32, ptr @t, align 4, !tbaa !5
  %4 = add nsw i32 %3, -1
  store i32 %4, ptr @t, align 4, !tbaa !5
  %.not7 = icmp eq i32 %3, 0
  br i1 %.not7, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %0, %38
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %6 = load i64, ptr @n, align 8, !tbaa !9
  switch i64 %6, label %13 [
    i64 1, label %7
    i64 2, label %9
  ]

7:                                                ; preds = %.lr.ph
  %8 = call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %38

9:                                                ; preds = %.lr.ph
  %10 = load i64, ptr @m, align 8, !tbaa !9
  %11 = add nsw i64 %10, -1
  %12 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %11)
  br label %38

13:                                               ; preds = %.lr.ph
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  %14 = load i64, ptr @m, align 8, !tbaa !9
  %15 = add nsw i64 %14, -1
  %16 = call noundef i64 @_Z3powxy(i64 noundef %15, i64 noundef %6)
  store i64 %16, ptr %1, align 8, !tbaa !9
  %.not3 = icmp eq i64 %16, 0
  br i1 %.not3, label %22, label %17

17:                                               ; preds = %13
  %18 = load i64, ptr @n, align 8, !tbaa !9
  %19 = and i64 %18, 1
  %.not4 = icmp eq i64 %19, 0
  br i1 %.not4, label %22, label %20

20:                                               ; preds = %17
  %21 = sub nsw i64 1000000007, %16
  store i64 %21, ptr %1, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %20, %17, %13
  %23 = load i64, ptr @m, align 8, !tbaa !9
  %24 = add nsw i64 %23, -1
  call void @_Z3incRxx(ptr noundef nonnull align 8 dereferenceable(8) %1, i64 noundef %24)
  %25 = load i64, ptr %1, align 8, !tbaa !9
  %26 = load i64, ptr @m, align 8, !tbaa !9
  %27 = call noundef i64 @_Z3powxy(i64 noundef %26, i64 noundef 1000000005)
  %28 = mul nsw i64 %27, %25
  %29 = srem i64 %28, 1000000007
  store i64 %29, ptr %1, align 8, !tbaa !9
  %.not5 = icmp eq i64 %29, 0
  br i1 %.not5, label %35, label %30

30:                                               ; preds = %22
  %31 = load i64, ptr @n, align 8, !tbaa !9
  %32 = and i64 %31, 1
  %.not6 = icmp eq i64 %32, 0
  br i1 %.not6, label %35, label %33

33:                                               ; preds = %30
  %34 = sub nsw i64 1000000007, %29
  store i64 %34, ptr %1, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %33, %30, %22
  %36 = phi i64 [ %34, %33 ], [ %29, %30 ], [ 0, %22 ]
  %37 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %36)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  br label %38

38:                                               ; preds = %9, %35, %7
  %39 = load i32, ptr @t, align 4, !tbaa !5
  %40 = add nsw i32 %39, -1
  store i32 %40, ptr @t, align 4, !tbaa !5
  %.not = icmp eq i32 %39, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11

._crit_edge:                                      ; preds = %38, %0
  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 @puts(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 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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