; LLVM IR from tangjz/acm-icpc :: buaa/oj3rd (1238)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(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
  store i32 0, ptr %1, align 4
  br label %4

4:                                                ; preds = %89, %12, %0
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @a, ptr noundef @b)
  %6 = icmp eq i32 %5, 3
  br i1 %6, label %7, label %92

7:                                                ; preds = %4
  %8 = load i32, ptr @b, align 4, !tbaa !5
  %9 = load i32, ptr @a, align 4, !tbaa !5
  %10 = srem i32 %8, %9
  %11 = icmp ne i32 %10, 0
  br i1 %11, label %12, label %14

12:                                               ; preds = %7
  %13 = call i32 @puts(ptr noundef @.str.1)
  br label %4, !llvm.loop !9

14:                                               ; preds = %7
  %15 = load i32, ptr @a, align 4, !tbaa !5
  %16 = load i32, ptr @b, align 4, !tbaa !5
  %17 = sdiv i32 %16, %15
  store i32 %17, ptr @b, align 4, !tbaa !5
  store i32 1, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 2, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  br label %18

18:                                               ; preds = %67, %14
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = load i32, ptr @b, align 4, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sdiv i32 %20, %21
  %23 = icmp sle i32 %19, %22
  br i1 %23, label %25, label %24

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

25:                                               ; preds = %18
  %26 = load i32, ptr @b, align 4, !tbaa !5
  %27 = load i32, ptr %2, align 4, !tbaa !5
  %28 = srem i32 %26, %27
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %30, label %66

30:                                               ; preds = %25
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %37, %30
  %32 = load i32, ptr @b, align 4, !tbaa !5
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = srem i32 %32, %33
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %43

36:                                               ; preds = %31
  br label %37

37:                                               ; preds = %36
  %38 = load i32, ptr %2, align 4, !tbaa !5
  %39 = load i32, ptr @b, align 4, !tbaa !5
  %40 = sdiv i32 %39, %38
  store i32 %40, ptr @b, align 4, !tbaa !5
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = add nsw i32 %41, 1
  store i32 %42, ptr %3, align 4, !tbaa !5
  br label %31, !llvm.loop !11

43:                                               ; preds = %31
  %44 = load i32, ptr @ans, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  %48 = load i32, ptr @n, align 4, !tbaa !5
  %49 = call noundef i32 @_Z7mod_powii(i32 noundef %47, i32 noundef %48)
  %50 = sext i32 %49 to i64
  %51 = load i32, ptr %3, align 4, !tbaa !5
  %52 = load i32, ptr @n, align 4, !tbaa !5
  %53 = call noundef i32 @_Z7mod_powii(i32 noundef %51, i32 noundef %52)
  %54 = sext i32 %53 to i64
  %55 = mul nsw i64 2, %54
  %56 = sub nsw i64 %50, %55
  %57 = load i32, ptr %3, align 4, !tbaa !5
  %58 = sub nsw i32 %57, 1
  %59 = load i32, ptr @n, align 4, !tbaa !5
  %60 = call noundef i32 @_Z7mod_powii(i32 noundef %58, i32 noundef %59)
  %61 = sext i32 %60 to i64
  %62 = add nsw i64 %56, %61
  %63 = mul nsw i64 %45, %62
  %64 = srem i64 %63, 1000000007
  %65 = trunc i64 %64 to i32
  store i32 %65, ptr @ans, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %43, %25
  br label %67

67:                                               ; preds = %66
  %68 = load i32, ptr %2, align 4, !tbaa !5
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %2, align 4, !tbaa !5
  br label %18, !llvm.loop !12

70:                                               ; preds = %24
  %71 = load i32, ptr @b, align 4, !tbaa !5
  %72 = icmp sgt i32 %71, 1
  br i1 %72, label %73, label %83

73:                                               ; preds = %70
  %74 = load i32, ptr @ans, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = load i32, ptr @n, align 4, !tbaa !5
  %77 = call noundef i32 @_Z7mod_powii(i32 noundef 2, i32 noundef %76)
  %78 = sub nsw i32 %77, 2
  %79 = sext i32 %78 to i64
  %80 = mul nsw i64 %75, %79
  %81 = srem i64 %80, 1000000007
  %82 = trunc i64 %81 to i32
  store i32 %82, ptr @ans, align 4, !tbaa !5
  br label %83

83:                                               ; preds = %73, %70
  %84 = load i32, ptr @ans, align 4, !tbaa !5
  %85 = icmp slt i32 %84, 0
  br i1 %85, label %86, label %89

86:                                               ; preds = %83
  %87 = load i32, ptr @ans, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1000000007
  store i32 %88, ptr @ans, align 4, !tbaa !5
  br label %89

89:                                               ; preds = %86, %83
  %90 = load i32, ptr @ans, align 4, !tbaa !5
  %91 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %90)
  br label %4, !llvm.loop !9

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

@n = external dso_local global i32, align 4
@a = external dso_local global i32, align 4
@b = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z7mod_powii(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 @a, ptr noundef nonnull @b)
  %2 = icmp eq i32 %1, 3
  br i1 %2, label %.lr.ph24, label %._crit_edge25

.lr.ph24:                                         ; preds = %0, %.backedge
  %3 = load i32, ptr @b, align 4, !tbaa !5
  %4 = load i32, ptr @a, align 4, !tbaa !5
  %5 = srem i32 %3, %4
  %6 = sdiv i32 %3, %4
  %.not = icmp eq i32 %5, 0
  br i1 %.not, label %11, label %7

7:                                                ; preds = %.lr.ph24
  %8 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.backedge

.backedge:                                        ; preds = %7, %57
  %9 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @a, ptr noundef nonnull @b)
  %10 = icmp eq i32 %9, 3
  br i1 %10, label %.lr.ph24, label %._crit_edge25, !llvm.loop !9

11:                                               ; preds = %.lr.ph24
  store i32 %6, ptr @b, align 4, !tbaa !5
  store i32 1, ptr @ans, align 4, !tbaa !5
  %.not1216 = icmp slt i32 %6, 4
  br i1 %.not1216, label %._crit_edge21, label %.lr.ph20

._crit_edge21:                                    ; preds = %40, %11
  %12 = phi i32 [ 1, %11 ], [ %41, %40 ]
  %.lcssa = phi i32 [ %6, %11 ], [ %.pr, %40 ]
  %13 = icmp sgt i32 %.lcssa, 1
  br i1 %13, label %44, label %thread-pre-split

.lr.ph20:                                         ; preds = %11, %40
  %.pr29 = phi i32 [ %.pr, %40 ], [ %6, %11 ]
  %14 = phi i32 [ %41, %40 ], [ 1, %11 ]
  %.01017 = phi i32 [ %42, %40 ], [ 2, %11 ]
  %15 = srem i32 %.pr29, %.01017
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %.lr.ph, label %40

.lr.ph:                                           ; preds = %.lr.ph20, %.lr.ph
  %.014 = phi i32 [ %19, %.lr.ph ], [ 0, %.lr.ph20 ]
  %17 = phi i32 [ %18, %.lr.ph ], [ %.pr29, %.lr.ph20 ]
  %18 = sdiv i32 %17, %.01017
  %19 = add nuw nsw i32 %.014, 1
  %20 = srem i32 %18, %.01017
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %.lr.ph, label %22, !llvm.loop !11

22:                                               ; preds = %.lr.ph
  store i32 %18, ptr @b, align 4, !tbaa !5
  %23 = sext i32 %14 to i64
  %24 = add nuw nsw i32 %.014, 2
  %25 = load i32, ptr @n, align 4, !tbaa !5
  %26 = tail call noundef i32 @_Z7mod_powii(i32 noundef %24, i32 noundef %25)
  %27 = sext i32 %26 to i64
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = tail call noundef i32 @_Z7mod_powii(i32 noundef %19, i32 noundef %28)
  %30 = sext i32 %29 to i64
  %31 = shl nsw i64 %30, 1
  %32 = sub nsw i64 %27, %31
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = tail call noundef i32 @_Z7mod_powii(i32 noundef %.014, i32 noundef %33)
  %35 = sext i32 %34 to i64
  %36 = add nsw i64 %32, %35
  %37 = mul nsw i64 %36, %23
  %38 = srem i64 %37, 1000000007
  %39 = trunc nsw i64 %38 to i32
  store i32 %39, ptr @ans, align 4, !tbaa !5
  %.pr.pre = load i32, ptr @b, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %.lr.ph20, %22
  %.pr = phi i32 [ %.pr29, %.lr.ph20 ], [ %.pr.pre, %22 ]
  %41 = phi i32 [ %14, %.lr.ph20 ], [ %39, %22 ]
  %42 = add nuw nsw i32 %.01017, 1
  %43 = sdiv i32 %.pr, %42
  %.not12.not = icmp slt i32 %.01017, %43
  br i1 %.not12.not, label %.lr.ph20, label %._crit_edge21, !llvm.loop !12

44:                                               ; preds = %._crit_edge21
  %45 = sext i32 %12 to i64
  %46 = load i32, ptr @n, align 4, !tbaa !5
  %47 = tail call noundef i32 @_Z7mod_powii(i32 noundef 2, i32 noundef %46)
  %48 = add nsw i32 %47, -2
  %49 = sext i32 %48 to i64
  %50 = mul nsw i64 %49, %45
  %51 = srem i64 %50, 1000000007
  %52 = trunc nsw i64 %51 to i32
  store i32 %52, ptr @ans, align 4, !tbaa !5
  br label %thread-pre-split

thread-pre-split:                                 ; preds = %._crit_edge21, %44
  %53 = phi i32 [ %52, %44 ], [ %12, %._crit_edge21 ]
  %54 = icmp slt i32 %53, 0
  br i1 %54, label %55, label %57

55:                                               ; preds = %thread-pre-split
  %56 = add nsw i32 %53, 1000000007
  store i32 %56, ptr @ans, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %55, %thread-pre-split
  %58 = phi i32 [ %56, %55 ], [ %53, %thread-pre-split ]
  %59 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %58)
  br label %.backedge

._crit_edge25:                                    ; preds = %.backedge, %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 @puts(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"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}


; Effective O3 passes: DivRemPairsPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass