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

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

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

2:                                                ; preds = %23, %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 %29

5:                                                ; preds = %2
  %6 = load i64, ptr @n, align 8, !tbaa !5
  %7 = add nsw i64 %6, 2
  store i64 %7, ptr @n, align 8, !tbaa !5
  br label %8

8:                                                ; preds = %12, %5
  %9 = load i64, ptr @n, align 8, !tbaa !5
  %10 = srem i64 %9, 3
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %12, label %15

12:                                               ; preds = %8
  %13 = load i64, ptr @n, align 8, !tbaa !5
  %14 = sdiv i64 %13, 3
  store i64 %14, ptr @n, align 8, !tbaa !5
  br label %8, !llvm.loop !9

15:                                               ; preds = %8
  br label %16

16:                                               ; preds = %20, %15
  %17 = load i64, ptr @n, align 8, !tbaa !5
  %18 = srem i64 %17, 5
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %23

20:                                               ; preds = %16
  %21 = load i64, ptr @n, align 8, !tbaa !5
  %22 = sdiv i64 %21, 5
  store i64 %22, ptr @n, align 8, !tbaa !5
  br label %16, !llvm.loop !11

23:                                               ; preds = %16
  %24 = load i64, ptr @n, align 8, !tbaa !5
  %25 = icmp eq i64 %24, 1
  %26 = zext i1 %25 to i64
  %27 = select i1 %25, ptr @.str.1, ptr @.str.2
  %28 = call i32 @puts(ptr noundef %27)
  br label %2, !llvm.loop !12

29:                                               ; preds = %2
  ret i32 0
}

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

declare i32 @puts(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" }

!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 = !{!"long long", !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 i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [3 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 = icmp eq i32 %1, 1
  br i1 %2, label %.lr.ph6, label %._crit_edge7

.lr.ph6:                                          ; preds = %0, %16
  %3 = load i64, ptr @n, align 8, !tbaa !5
  %4 = add nsw i64 %3, 2
  %5 = srem i64 %4, 3
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %.lr.ph6
  %storemerge.lcssa = phi i64 [ %4, %.lr.ph6 ], [ %9, %.lr.ph ]
  store i64 %storemerge.lcssa, ptr @n, align 8, !tbaa !5
  %7 = srem i64 %storemerge.lcssa, 5
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %.lr.ph2, label %16

.lr.ph:                                           ; preds = %.lr.ph6, %.lr.ph
  %storemerge1 = phi i64 [ %9, %.lr.ph ], [ %4, %.lr.ph6 ]
  %9 = sdiv i64 %storemerge1, 3
  %10 = srem i64 %9, 3
  %11 = icmp eq i64 %10, 0
  br i1 %11, label %.lr.ph, label %.preheader, !llvm.loop !9

.lr.ph2:                                          ; preds = %.preheader, %.lr.ph2
  %12 = phi i64 [ %13, %.lr.ph2 ], [ %storemerge.lcssa, %.preheader ]
  %13 = sdiv i64 %12, 5
  %14 = srem i64 %13, 5
  %15 = icmp eq i64 %14, 0
  br i1 %15, label %.lr.ph2, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph2
  store i64 %13, ptr @n, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %._crit_edge, %.preheader
  %.lcssa = phi i64 [ %13, %._crit_edge ], [ %storemerge.lcssa, %.preheader ]
  %17 = icmp eq i64 %.lcssa, 1
  %18 = select i1 %17, ptr @.str.1, ptr @.str.2
  %19 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) %18)
  %20 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %21 = icmp eq i32 %20, 1
  br i1 %21, label %.lr.ph6, label %._crit_edge7, !llvm.loop !12

._crit_edge7:                                     ; preds = %16, %0
  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 @puts(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 = !{!"long long", !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: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass