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

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

@tot = external dso_local global i32, align 4
@n = external dso_local global i64, align 8
@p = external dso_local global [80001 x i64], align 16
@vis = external dso_local global [1000001 x i8], align 16
@.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 uwtable
declare dso_local noundef i64 @_Z3dfsiix(i32 noundef, i32 noundef, i64 noundef) #0

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

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

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

9:                                                ; preds = %44, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 1000000
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  br label %47

13:                                               ; preds = %9
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %15
  %17 = load i8, ptr %16, align 1, !tbaa !9, !range !11, !noundef !12
  %18 = trunc i8 %17 to i1
  br i1 %18, label %43, label %19

19:                                               ; preds = %13
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = load i32, ptr @tot, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr @tot, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [80001 x i64], ptr @p, i64 0, i64 %24
  store i64 %21, ptr %25, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %26 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %26, ptr %4, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %39, %19
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = load i32, ptr %2, align 4, !tbaa !5
  %30 = sdiv i32 1000000, %29
  %31 = icmp sle i32 %28, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %27
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %42

33:                                               ; preds = %27
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = mul nsw i32 %34, %35
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %37
  store i8 1, ptr %38, align 1, !tbaa !9
  br label %39

39:                                               ; preds = %33
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %4, align 4, !tbaa !5
  br label %27, !llvm.loop !15

42:                                               ; preds = %32
  br label %43

43:                                               ; preds = %42, %13
  br label %44

44:                                               ; preds = %43
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !17

47:                                               ; preds = %12
  %48 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 1, ptr %5, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 100000000000, ptr %6, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  br label %49

49:                                               ; preds = %68, %47
  %50 = load i64, ptr %5, align 8, !tbaa !13
  %51 = load i64, ptr %6, align 8, !tbaa !13
  %52 = icmp slt i64 %50, %51
  br i1 %52, label %53, label %69

53:                                               ; preds = %49
  %54 = load i64, ptr %5, align 8, !tbaa !13
  %55 = load i64, ptr %6, align 8, !tbaa !13
  %56 = add nsw i64 %54, %55
  %57 = ashr i64 %56, 1
  store i64 %57, ptr %7, align 8, !tbaa !13
  %58 = load i64, ptr %7, align 8, !tbaa !13
  %59 = call noundef i64 @_Z3dfsiix(i32 noundef 1, i32 noundef 1, i64 noundef %58)
  store i64 %59, ptr %8, align 8, !tbaa !13
  %60 = load i64, ptr %8, align 8, !tbaa !13
  %61 = load i64, ptr @n, align 8, !tbaa !13
  %62 = icmp slt i64 %60, %61
  br i1 %62, label %63, label %66

63:                                               ; preds = %53
  %64 = load i64, ptr %7, align 8, !tbaa !13
  %65 = add nsw i64 %64, 1
  store i64 %65, ptr %5, align 8, !tbaa !13
  br label %68

66:                                               ; preds = %53
  %67 = load i64, ptr %7, align 8, !tbaa !13
  store i64 %67, ptr %6, align 8, !tbaa !13
  br label %68

68:                                               ; preds = %66, %63
  br label %49, !llvm.loop !18

69:                                               ; preds = %49
  %70 = load i64, ptr %5, align 8, !tbaa !13
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %70)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  %72 = load i32, ptr %1, align 4
  ret i32 %72
}

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

declare i32 @printf(ptr noundef, ...) #3

attributes #0 = { mustprogress 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 #4 = { 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


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

@tot = external dso_local local_unnamed_addr global i32, align 4
@n = external dso_local global i64, align 8
@p = external dso_local local_unnamed_addr global [80001 x i64], align 16
@vis = external dso_local local_unnamed_addr global [1000001 x i8], align 16
@.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 uwtable
declare dso_local noundef i64 @_Z3dfsiix(i32 noundef, i32 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  br label %3

1:                                                ; preds = %.loopexit
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  br label %18

3:                                                ; preds = %0, %.loopexit
  %indvars.iv = phi i64 [ 2, %0 ], [ %indvars.iv.next, %.loopexit ]
  %4 = phi i32 [ %tot.promoted, %0 ], [ %17, %.loopexit ]
  %5 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %indvars.iv
  %6 = load i8, ptr %5, align 1, !tbaa !9, !range !11, !noundef !12
  %7 = trunc nuw i8 %6 to i1
  br i1 %7, label %.loopexit, label %8

8:                                                ; preds = %3
  %9 = add nsw i32 %4, 1
  store i32 %9, ptr @tot, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [80001 x i64], ptr @p, i64 0, i64 %10
  store i64 %indvars.iv, ptr %11, align 8, !tbaa !13
  %12 = trunc nuw nsw i64 %indvars.iv to i32
  %13 = udiv i32 1000000, %12
  %14 = zext nneg i32 %13 to i64
  %.not24 = icmp ugt i64 %indvars.iv, %14
  br i1 %.not24, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.lr.ph
  %indvars.iv30 = phi i64 [ %indvars.iv.next31, %.lr.ph ], [ %indvars.iv, %8 ]
  %15 = mul nuw nsw i64 %indvars.iv30, %indvars.iv
  %16 = getelementptr inbounds [1000001 x i8], ptr @vis, i64 0, i64 %15
  store i8 1, ptr %16, align 1, !tbaa !9
  %indvars.iv.next31 = add nuw nsw i64 %indvars.iv30, 1
  %.not.not = icmp ult i64 %indvars.iv30, %14
  br i1 %.not.not, label %.lr.ph, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %.lr.ph, %8, %3
  %17 = phi i32 [ %4, %3 ], [ %9, %8 ], [ %9, %.lr.ph ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 1000000
  br i1 %exitcond.not, label %1, label %3, !llvm.loop !17

18:                                               ; preds = %1, %18
  %.02029 = phi i64 [ 100000000000, %1 ], [ %.1, %18 ]
  %.02128 = phi i64 [ 1, %1 ], [ %.122, %18 ]
  %19 = add nsw i64 %.02029, %.02128
  %20 = ashr i64 %19, 1
  %21 = tail call noundef i64 @_Z3dfsiix(i32 noundef 1, i32 noundef 1, i64 noundef %20)
  %22 = load i64, ptr @n, align 8, !tbaa !13
  %23 = icmp slt i64 %21, %22
  %24 = add nsw i64 %20, 1
  %.122 = select i1 %23, i64 %24, i64 %.02128
  %.1 = select i1 %23, i64 %.02029, i64 %20
  %25 = icmp slt i64 %.122, %.1
  br i1 %25, label %18, label %26, !llvm.loop !18

26:                                               ; preds = %18
  %27 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.122)
  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 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #2

attributes #0 = { mustprogress 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 = { 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 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = !{!14, !14, i64 0}
!14 = !{!"long long", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


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