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

; 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
@p = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@s = external dso_local global [10000001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

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

3:                                                ; preds = %37, %16, %9, %0
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @s, ptr noundef @p)
  %5 = icmp eq i32 %4, 2
  br i1 %5, label %6, label %40

6:                                                ; preds = %3
  %7 = call i64 @strlen(ptr noundef @s) #5
  %8 = icmp ugt i64 %7, 7
  br i1 %8, label %9, label %11

9:                                                ; preds = %6
  %10 = call i32 @puts(ptr noundef @.str.1)
  br label %3, !llvm.loop !5

11:                                               ; preds = %6
  %12 = call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef @s, ptr noundef @.str.2, ptr noundef @n) #6
  %13 = load i32, ptr @n, align 4, !tbaa !7
  %14 = load i32, ptr @p, align 4, !tbaa !7
  %15 = icmp sge i32 %13, %14
  br i1 %15, label %16, label %18

16:                                               ; preds = %11
  %17 = call i32 @puts(ptr noundef @.str.1)
  br label %3, !llvm.loop !5

18:                                               ; preds = %11
  store i32 1, ptr @ans, align 4, !tbaa !7
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 2, ptr %2, align 4, !tbaa !7
  br label %19

19:                                               ; preds = %34, %18
  %20 = load i32, ptr %2, align 4, !tbaa !7
  %21 = load i32, ptr @n, align 4, !tbaa !7
  %22 = icmp sle i32 %20, %21
  br i1 %22, label %24, label %23

23:                                               ; preds = %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %37

24:                                               ; preds = %19
  %25 = load i32, ptr @ans, align 4, !tbaa !7
  %26 = sext i32 %25 to i64
  %27 = load i32, ptr %2, align 4, !tbaa !7
  %28 = sext i32 %27 to i64
  %29 = mul nsw i64 %26, %28
  %30 = load i32, ptr @p, align 4, !tbaa !7
  %31 = sext i32 %30 to i64
  %32 = srem i64 %29, %31
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr @ans, align 4, !tbaa !7
  br label %34

34:                                               ; preds = %24
  %35 = load i32, ptr %2, align 4, !tbaa !7
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %2, align 4, !tbaa !7
  br label %19, !llvm.loop !11

37:                                               ; preds = %23
  %38 = load i32, ptr @ans, align 4, !tbaa !7
  %39 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i32 noundef %38)
  br label %3, !llvm.loop !5

40:                                               ; preds = %3
  ret i32 0
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

declare i32 @puts(ptr noundef) #1

; Function Attrs: nounwind
declare i32 @__isoc99_sscanf(ptr noundef, ptr noundef, ...) #3

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

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

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

attributes #0 = { 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 #1 = { "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 = { nounwind willreturn memory(read) "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 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind willreturn memory(read) }
attributes #6 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}


; 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
@p = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@s = external dso_local global [10000001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @s, ptr noundef nonnull @p)
  %2 = icmp eq i32 %1, 2
  br i1 %2, label %.lr.ph7, label %._crit_edge8

.lr.ph7:                                          ; preds = %0, %.backedge
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @s) #3
  %4 = icmp ugt i64 %3, 7
  br i1 %4, label %5, label %9

5:                                                ; preds = %.lr.ph7
  %6 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.backedge

.backedge:                                        ; preds = %5, %13, %25
  %7 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @s, ptr noundef nonnull @p)
  %8 = icmp eq i32 %7, 2
  br i1 %8, label %.lr.ph7, label %._crit_edge8, !llvm.loop !5

9:                                                ; preds = %.lr.ph7
  %10 = tail call i32 (ptr, ptr, ...) @__isoc99_sscanf(ptr noundef nonnull @s, ptr noundef nonnull @.str.2, ptr noundef nonnull @n) #4
  %11 = load i32, ptr @n, align 4, !tbaa !7
  %12 = load i32, ptr @p, align 4, !tbaa !7
  %.not = icmp slt i32 %11, %12
  br i1 %.not, label %15, label %13

13:                                               ; preds = %9
  %14 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.1)
  br label %.backedge

15:                                               ; preds = %9
  store i32 1, ptr @ans, align 4, !tbaa !7
  %.not34 = icmp slt i32 %11, 2
  br i1 %.not34, label %25, label %.lr.ph

.lr.ph:                                           ; preds = %15
  %16 = sext i32 %12 to i64
  %17 = add nuw nsw i32 %11, 1
  %wide.trip.count = zext nneg i32 %17 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %18 = icmp eq i32 %17, 3
  br i1 %18, label %._crit_edge.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %19 = and i64 %wide.trip.count, 2147483646
  %20 = add nsw i64 %19, -4
  br label %28

._crit_edge.unr-lcssa:                            ; preds = %28, %.lr.ph
  %.lcssa.ph = phi i64 [ poison, %.lr.ph ], [ %35, %28 ]
  %indvars.iv.unr = phi i64 [ 2, %.lr.ph ], [ %indvars.iv.next.1, %28 ]
  %.unr = phi i64 [ 1, %.lr.ph ], [ %35, %28 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %._crit_edge.epilog-lcssa

._crit_edge.epilog-lcssa:                         ; preds = %._crit_edge.unr-lcssa
  %sext.epil = shl i64 %.unr, 32
  %21 = ashr exact i64 %sext.epil, 32
  %22 = mul nsw i64 %21, %indvars.iv.unr
  %23 = srem i64 %22, %16
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %._crit_edge.epilog-lcssa
  %.lcssa = phi i64 [ %.lcssa.ph, %._crit_edge.unr-lcssa ], [ %23, %._crit_edge.epilog-lcssa ]
  %24 = trunc nsw i64 %.lcssa to i32
  store i32 %24, ptr @ans, align 4, !tbaa !7
  br label %25

25:                                               ; preds = %._crit_edge, %15
  %26 = phi i32 [ %24, %._crit_edge ], [ 1, %15 ]
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i32 noundef %26)
  br label %.backedge

28:                                               ; preds = %28, %.lr.ph.new
  %indvars.iv = phi i64 [ 2, %.lr.ph.new ], [ %indvars.iv.next.1, %28 ]
  %29 = phi i64 [ 1, %.lr.ph.new ], [ %35, %28 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.1, %28 ]
  %sext = shl i64 %29, 32
  %30 = ashr exact i64 %sext, 32
  %31 = mul nsw i64 %30, %indvars.iv
  %32 = srem i64 %31, %16
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %sext.1 = shl i64 %32, 32
  %33 = ashr exact i64 %sext.1, 32
  %34 = mul nsw i64 %33, %indvars.iv.next
  %35 = srem i64 %34, %16
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter, %20
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %28, !llvm.loop !11

._crit_edge8:                                     ; preds = %.backedge, %0
  ret i32 0
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #1

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

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

attributes #0 = { mustprogress nofree 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 #1 = { 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 #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nounwind willreturn memory(read) }
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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"int", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = distinct !{!11, !6}


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