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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z9is_triplei(i32 noundef) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z9is_squarex(i64 noundef) #0

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

2:                                                ; preds = %39, %0
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %5, label %43

5:                                                ; preds = %2
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %7 = icmp eq i32 %6, 1
  br i1 %7, label %8, label %9

8:                                                ; preds = %5
  br label %39

9:                                                ; preds = %5
  %10 = load i32, ptr @n, align 4, !tbaa !5
  %11 = call noundef zeroext i1 @_Z9is_triplei(i32 noundef %10)
  br i1 %11, label %35, label %12

12:                                               ; preds = %9
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = sub nsw i32 %13, 1
  %15 = call noundef zeroext i1 @_Z9is_triplei(i32 noundef %14)
  br i1 %15, label %35, label %16

16:                                               ; preds = %12
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = add nsw i64 %20, 1
  %22 = mul nsw i64 %18, %21
  %23 = ashr i64 %22, 1
  %24 = call noundef zeroext i1 @_Z9is_squarex(i64 noundef %23)
  br i1 %24, label %35, label %25

25:                                               ; preds = %16
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = load i32, ptr @n, align 4, !tbaa !5
  %29 = sext i32 %28 to i64
  %30 = add nsw i64 %29, 1
  %31 = mul nsw i64 %27, %30
  %32 = ashr i64 %31, 1
  %33 = sub nsw i64 %32, 1
  %34 = call noundef zeroext i1 @_Z9is_squarex(i64 noundef %33)
  br i1 %34, label %35, label %36

35:                                               ; preds = %25, %16, %12, %9
  br label %37

36:                                               ; preds = %25
  br label %37

37:                                               ; preds = %36, %35
  %38 = phi ptr [ @.str.2, %35 ], [ @.str.3, %36 ]
  br label %39

39:                                               ; preds = %37, %8
  %40 = phi ptr [ @.str.1, %8 ], [ %38, %37 ]
  %41 = getelementptr inbounds [2 x i8], ptr %40, i64 0, i64 0
  %42 = call i32 @puts(ptr noundef %41)
  br label %2, !llvm.loop !9

43:                                               ; preds = %2
  ret i32 0
}

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

declare i32 @puts(ptr noundef) #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 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 = { "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"}


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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z9is_triplei(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z9is_squarex(i64 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)
  %2 = icmp eq i32 %1, 1
  br i1 %2, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %26
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 1
  br i1 %4, label %26, label %5

5:                                                ; preds = %.lr.ph
  %6 = tail call noundef zeroext i1 @_Z9is_triplei(i32 noundef %3)
  br i1 %6, label %26, label %7

7:                                                ; preds = %5
  %8 = load i32, ptr @n, align 4, !tbaa !5
  %9 = add nsw i32 %8, -1
  %10 = tail call noundef zeroext i1 @_Z9is_triplei(i32 noundef %9)
  br i1 %10, label %26, label %11

11:                                               ; preds = %7
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = add nsw i64 %13, 1
  %15 = mul nsw i64 %14, %13
  %16 = ashr i64 %15, 1
  %17 = tail call noundef zeroext i1 @_Z9is_squarex(i64 noundef %16)
  br i1 %17, label %26, label %18

18:                                               ; preds = %11
  %19 = load i32, ptr @n, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = add nsw i64 %20, 1
  %22 = mul nsw i64 %21, %20
  %23 = ashr i64 %22, 1
  %24 = add nsw i64 %23, -1
  %25 = tail call noundef zeroext i1 @_Z9is_squarex(i64 noundef %24)
  %spec.select = select i1 %25, ptr @.str.2, ptr @.str.3
  br label %26

26:                                               ; preds = %18, %11, %7, %5, %.lr.ph
  %27 = phi ptr [ @.str.1, %.lr.ph ], [ @.str.2, %11 ], [ @.str.2, %7 ], [ @.str.2, %5 ], [ %spec.select, %18 ]
  %28 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %27)
  %29 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %30 = icmp eq i32 %29, 1
  br i1 %30, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %26, %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

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


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