; LLVM IR from tangjz/acm-icpc :: lydsy (1430)

; 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
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = 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
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %5 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %6

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

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

11:                                               ; preds = %6
  %12 = load i32, ptr @ans, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = mul nsw i64 %13, %15
  %17 = srem i64 %16, 9999991
  %18 = trunc i64 %17 to i32
  store i32 %18, ptr @ans, align 4, !tbaa !5
  br label %19

19:                                               ; preds = %11
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %2, align 4, !tbaa !5
  br label %6, !llvm.loop !9

22:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  %23 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %23, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  %24 = load i32, ptr @n, align 4, !tbaa !5
  %25 = sub nsw i32 %24, 2
  store i32 %25, ptr %4, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %41, %22
  %27 = load i32, ptr %4, align 4, !tbaa !5
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %51

29:                                               ; preds = %26
  %30 = load i32, ptr %4, align 4, !tbaa !5
  %31 = and i32 %30, 1
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %41

33:                                               ; preds = %29
  %34 = load i32, ptr @ans, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = mul nsw i64 %35, %37
  %39 = srem i64 %38, 9999991
  %40 = trunc i64 %39 to i32
  store i32 %40, ptr @ans, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %33, %29
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = mul nsw i64 %43, %45
  %47 = srem i64 %46, 9999991
  %48 = trunc i64 %47 to i32
  store i32 %48, ptr %3, align 4, !tbaa !5
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = ashr i32 %49, 1
  store i32 %50, ptr %4, align 4, !tbaa !5
  br label %26, !llvm.loop !11

51:                                               ; preds = %26
  %52 = load i32, ptr @ans, align 4, !tbaa !5
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %52)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  ret i32 0
}

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

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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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"

@n = external dso_local global i32, align 4
@ans = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = 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 @n)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %ans.promoted = load i32, ptr @ans, align 4, !tbaa !5
  %3 = icmp sgt i32 %2, 2
  br i1 %3, label %.lr.ph.preheader, label %11

.lr.ph.preheader:                                 ; preds = %0
  %wide.trip.count = zext nneg i32 %2 to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %4 = icmp eq i32 %2, 3
  br i1 %4, label %._crit_edge.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %5 = and i64 %wide.trip.count, 2147483646
  %6 = add nsw i64 %5, -4
  br label %.lr.ph

._crit_edge.unr-lcssa:                            ; preds = %.lr.ph, %.lr.ph.preheader
  %.lcssa26.ph = phi i32 [ poison, %.lr.ph.preheader ], [ %19, %.lr.ph ]
  %indvars.iv.unr = phi i64 [ 2, %.lr.ph.preheader ], [ %indvars.iv.next.1, %.lr.ph ]
  %.unr = phi i32 [ %ans.promoted, %.lr.ph.preheader ], [ %19, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.unr-lcssa
  %7 = sext i32 %.unr to i64
  %8 = mul nsw i64 %indvars.iv.unr, %7
  %9 = srem i64 %8, 9999991
  %10 = trunc nsw i64 %9 to i32
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.unr-lcssa, %.lr.ph.epil
  %.lcssa26 = phi i32 [ %.lcssa26.ph, %._crit_edge.unr-lcssa ], [ %10, %.lr.ph.epil ]
  store i32 %.lcssa26, ptr @ans, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %._crit_edge, %0
  %ans.promoted15 = phi i32 [ %.lcssa26, %._crit_edge ], [ %ans.promoted, %0 ]
  %12 = add nsw i32 %2, -2
  %.not16 = icmp eq i32 %12, 0
  br i1 %.not16, label %._crit_edge21, label %.lr.ph20

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 2, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %13 = phi i32 [ %ans.promoted, %.lr.ph.preheader.new ], [ %19, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %14 = sext i32 %13 to i64
  %15 = mul nsw i64 %indvars.iv, %14
  %16 = srem i64 %15, 9999991
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %17 = mul nsw i64 %indvars.iv.next, %16
  %18 = srem i64 %17, 9999991
  %19 = trunc nsw i64 %18 to i32
  %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, %6
  br i1 %niter.ncmp.1, label %._crit_edge.unr-lcssa, label %.lr.ph, !llvm.loop !9

.lr.ph20:                                         ; preds = %11, %28
  %.018 = phi i32 [ %33, %28 ], [ %12, %11 ]
  %.0917 = phi i32 [ %32, %28 ], [ %2, %11 ]
  %20 = phi i32 [ %29, %28 ], [ %ans.promoted15, %11 ]
  %21 = and i32 %.018, 1
  %.not12 = icmp eq i32 %21, 0
  br i1 %.not12, label %.lr.ph20._crit_edge, label %22

.lr.ph20._crit_edge:                              ; preds = %.lr.ph20
  %.pre = sext i32 %.0917 to i64
  br label %28

22:                                               ; preds = %.lr.ph20
  %23 = sext i32 %20 to i64
  %24 = sext i32 %.0917 to i64
  %25 = mul nsw i64 %23, %24
  %26 = srem i64 %25, 9999991
  %27 = trunc nsw i64 %26 to i32
  store i32 %27, ptr @ans, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %.lr.ph20._crit_edge, %22
  %.pre-phi = phi i64 [ %.pre, %.lr.ph20._crit_edge ], [ %24, %22 ]
  %29 = phi i32 [ %20, %.lr.ph20._crit_edge ], [ %27, %22 ]
  %30 = mul nsw i64 %.pre-phi, %.pre-phi
  %31 = urem i64 %30, 9999991
  %32 = trunc nuw nsw i64 %31 to i32
  %33 = ashr i32 %.018, 1
  %.not = icmp ult i32 %.018, 2
  br i1 %.not, label %._crit_edge21, label %.lr.ph20, !llvm.loop !11

._crit_edge21:                                    ; preds = %28, %11
  %34 = phi i32 [ %ans.promoted15, %11 ], [ %29, %28 ]
  %35 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %34)
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(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" }

!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}


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