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

; 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
@ans = 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 [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %4 = load i64, ptr @n, align 8, !tbaa !5
  %5 = shl i64 %4, 1
  %6 = add nsw i64 %5, 1
  store i64 %6, ptr @n, align 8, !tbaa !5
  %7 = load i64, ptr @n, align 8, !tbaa !5
  %8 = add nsw i64 %7, 1
  store i64 %8, ptr @ans, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  store i64 3, ptr %2, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %38, %0
  %10 = load i64, ptr %2, align 8, !tbaa !5
  %11 = load i64, ptr @n, align 8, !tbaa !5
  %12 = load i64, ptr %2, align 8, !tbaa !5
  %13 = sdiv i64 %11, %12
  %14 = icmp sle i64 %10, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %9
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  br label %41

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

21:                                               ; preds = %16
  %22 = load i64, ptr %2, align 8, !tbaa !5
  %23 = load i64, ptr @ans, align 8, !tbaa !5
  %24 = add nsw i64 %23, %22
  store i64 %24, ptr @ans, align 8, !tbaa !5
  %25 = load i64, ptr %2, align 8, !tbaa !5
  %26 = load i64, ptr @n, align 8, !tbaa !5
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = sdiv i64 %26, %27
  %29 = icmp ne i64 %25, %28
  br i1 %29, label %30, label %36

30:                                               ; preds = %21
  %31 = load i64, ptr @n, align 8, !tbaa !5
  %32 = load i64, ptr %2, align 8, !tbaa !5
  %33 = sdiv i64 %31, %32
  %34 = load i64, ptr @ans, align 8, !tbaa !5
  %35 = add nsw i64 %34, %33
  store i64 %35, ptr @ans, align 8, !tbaa !5
  br label %36

36:                                               ; preds = %30, %21
  br label %37

37:                                               ; preds = %36, %16
  br label %38

38:                                               ; preds = %37
  %39 = load i64, ptr %2, align 8, !tbaa !5
  %40 = add nsw i64 %39, 1
  store i64 %40, ptr %2, align 8, !tbaa !5
  br label %9, !llvm.loop !9

41:                                               ; preds = %15
  %42 = load i64, ptr @ans, align 8, !tbaa !5
  %43 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %42)
  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 = !{!"long long", !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 i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [6 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 i64, ptr @n, align 8, !tbaa !5
  %3 = shl i64 %2, 1
  %4 = or disjoint i64 %3, 1
  store i64 %4, ptr @n, align 8, !tbaa !5
  %5 = add nsw i64 %3, 2
  store i64 %5, ptr @ans, align 8, !tbaa !5
  %.not10 = icmp slt i64 %4, 9
  br i1 %.not10, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %0
  %6 = udiv i64 %4, 3
  br label %.lr.ph

._crit_edge:                                      ; preds = %17, %0
  %7 = phi i64 [ %5, %0 ], [ %18, %17 ]
  %8 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %7)
  ret i32 0

.lr.ph:                                           ; preds = %.lr.ph.preheader, %17
  %9 = phi i64 [ %20, %17 ], [ %6, %.lr.ph.preheader ]
  %.011 = phi i64 [ %19, %17 ], [ 3, %.lr.ph.preheader ]
  %10 = phi i64 [ %18, %17 ], [ %5, %.lr.ph.preheader ]
  %11 = urem i64 %4, %.011
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %17

13:                                               ; preds = %.lr.ph
  %14 = add nsw i64 %10, %.011
  store i64 %14, ptr @ans, align 8, !tbaa !5
  %.not9 = icmp eq i64 %.011, %9
  br i1 %.not9, label %17, label %15

15:                                               ; preds = %13
  %16 = add nsw i64 %14, %9
  store i64 %16, ptr @ans, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %.lr.ph, %15, %13
  %18 = phi i64 [ %10, %.lr.ph ], [ %16, %15 ], [ %14, %13 ]
  %19 = add nuw nsw i64 %.011, 1
  %20 = udiv i64 %4, %19
  %.not.not = icmp ult i64 %.011, %20
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9
}

; 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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