; LLVM IR from tangjz/acm-icpc :: 51nod (1262)

; 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
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  store i32 %5, ptr @n, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %6, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %7

7:                                                ; preds = %39, %0
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = mul nsw i64 %9, %11
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = icmp sle i64 %12, %14
  br i1 %15, label %17, label %16

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

17:                                               ; preds = %7
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = srem i32 %18, %19
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %22, label %38

22:                                               ; preds = %17
  %23 = load i32, ptr @ans, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sdiv i32 %23, %24
  %26 = load i32, ptr @ans, align 4, !tbaa !5
  %27 = sub nsw i32 %26, %25
  store i32 %27, ptr @ans, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %33, %22
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = srem i32 %29, %30
  %32 = icmp eq i32 %31, 0
  br i1 %32, label %33, label %37

33:                                               ; preds = %28
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = sdiv i32 %35, %34
  store i32 %36, ptr @n, align 4, !tbaa !5
  br label %28, !llvm.loop !9

37:                                               ; preds = %28
  br label %38

38:                                               ; preds = %37, %17
  br label %39

39:                                               ; preds = %38
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %2, align 4, !tbaa !5
  br label %7, !llvm.loop !11

42:                                               ; preds = %16
  %43 = load i32, ptr @n, align 4, !tbaa !5
  %44 = icmp sgt i32 %43, 1
  br i1 %44, label %45, label %51

45:                                               ; preds = %42
  %46 = load i32, ptr @ans, align 4, !tbaa !5
  %47 = load i32, ptr @n, align 4, !tbaa !5
  %48 = sdiv i32 %46, %47
  %49 = load i32, ptr @ans, align 4, !tbaa !5
  %50 = sub nsw i32 %49, %48
  store i32 %50, ptr @ans, align 4, !tbaa !5
  br label %51

51:                                               ; preds = %45, %42
  %52 = load i32, ptr @ans, align 4, !tbaa !5
  %53 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %52)
  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
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr @n, align 4, !tbaa !5
  store i32 %3, ptr @ans, align 4, !tbaa !5
  %.not13 = icmp slt i32 %2, 3
  br i1 %.not13, label %._crit_edge, label %.lr.ph16

._crit_edge:                                      ; preds = %.loopexit, %0
  %4 = phi i32 [ %3, %0 ], [ %17, %.loopexit ]
  %.lcssa = phi i32 [ %3, %0 ], [ %.lcssa810, %.loopexit ]
  %5 = icmp sgt i32 %.lcssa, 1
  br i1 %5, label %21, label %24

.lr.ph16:                                         ; preds = %0, %.loopexit
  %6 = phi i32 [ %17, %.loopexit ], [ %3, %0 ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %.loopexit ], [ 2, %0 ]
  %7 = phi i32 [ %18, %.loopexit ], [ %3, %0 ]
  %.lcssa81214 = phi i32 [ %.lcssa810, %.loopexit ], [ %3, %0 ]
  %8 = trunc nuw nsw i64 %indvars.iv to i32
  %9 = srem i32 %.lcssa81214, %8
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %.lr.ph.preheader, label %.loopexit

.lr.ph.preheader:                                 ; preds = %.lr.ph16
  %11 = sdiv i32 %7, %8
  %12 = sub nsw i32 %7, %11
  store i32 %12, ptr @ans, align 4, !tbaa !5
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %13 = phi i32 [ %14, %.lr.ph ], [ %.lcssa81214, %.lr.ph.preheader ]
  %14 = sdiv i32 %13, %8
  %15 = srem i32 %14, %8
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %.lr.ph, label %..loopexit_crit_edge, !llvm.loop !9

..loopexit_crit_edge:                             ; preds = %.lr.ph
  store i32 %14, ptr @n, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %..loopexit_crit_edge, %.lr.ph16
  %17 = phi i32 [ %6, %.lr.ph16 ], [ %12, %..loopexit_crit_edge ]
  %.lcssa810 = phi i32 [ %.lcssa81214, %.lr.ph16 ], [ %14, %..loopexit_crit_edge ]
  %18 = phi i32 [ %7, %.lr.ph16 ], [ %12, %..loopexit_crit_edge ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %19 = mul nuw nsw i64 %indvars.iv.next, %indvars.iv.next
  %20 = sext i32 %.lcssa810 to i64
  %.not = icmp sgt i64 %19, %20
  br i1 %.not, label %._crit_edge, label %.lr.ph16, !llvm.loop !11

21:                                               ; preds = %._crit_edge
  %22 = sdiv i32 %4, %.lcssa
  %23 = sub nsw i32 %4, %22
  store i32 %23, ptr @ans, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %21, %._crit_edge
  %25 = phi i32 [ %23, %21 ], [ %4, %._crit_edge ]
  %26 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %25)
  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,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass