; LLVM IR from tangjz/acm-icpc :: lydsy/3068.ll (Z5reseti)

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

@f = external dso_local global [500001 x i32], align 16
@st = external dso_local global [19 x [500001 x i32]], align 16

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z5reseti(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  %4 = load i32, ptr %2, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [500001 x i32], ptr @st, i64 0, i64 %9
  store i32 %7, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %37, %1
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 19
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %11
  %16 = load i32, ptr %3, align 4, !tbaa !5
  %17 = sub nsw i32 %16, 1
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 %18
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = sub nsw i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 %22
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [500001 x i32], ptr %23, i64 0, i64 %25
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [500001 x i32], ptr %19, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !5
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 %32
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [500001 x i32], ptr %33, i64 0, i64 %35
  store i32 %30, ptr %36, align 4, !tbaa !5
  br label %37

37:                                               ; preds = %15
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %3, align 4, !tbaa !5
  br label %11, !llvm.loop !9

40:                                               ; preds = %14
  ret void
}

; 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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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"}


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

@f = external dso_local local_unnamed_addr global [500001 x i32], align 16
@st = external dso_local local_unnamed_addr global [19 x [500001 x i32]], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local void @_Z5reseti(i32 noundef %0) local_unnamed_addr #0 {
  %2 = sext i32 %0 to i64
  %3 = getelementptr inbounds [500001 x i32], ptr @f, i64 0, i64 %2
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds [500001 x i32], ptr @st, i64 0, i64 %2
  store i32 %4, ptr %5, align 4, !tbaa !5
  %6 = sext i32 %4 to i64
  %7 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 1, i64 %2
  store i32 %8, ptr %9, align 4, !tbaa !5
  %10 = sext i32 %8 to i64
  %11 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 1, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !5
  %13 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 2, i64 %2
  store i32 %12, ptr %13, align 4, !tbaa !5
  %14 = sext i32 %12 to i64
  %15 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 2, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 3, i64 %2
  store i32 %16, ptr %17, align 4, !tbaa !5
  %18 = sext i32 %16 to i64
  %19 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 3, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 4, i64 %2
  store i32 %20, ptr %21, align 4, !tbaa !5
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 4, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %25 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 5, i64 %2
  store i32 %24, ptr %25, align 4, !tbaa !5
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 5, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !5
  %29 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 6, i64 %2
  store i32 %28, ptr %29, align 4, !tbaa !5
  %30 = sext i32 %28 to i64
  %31 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 6, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 7, i64 %2
  store i32 %32, ptr %33, align 4, !tbaa !5
  %34 = sext i32 %32 to i64
  %35 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 7, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 8, i64 %2
  store i32 %36, ptr %37, align 4, !tbaa !5
  %38 = sext i32 %36 to i64
  %39 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 8, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 9, i64 %2
  store i32 %40, ptr %41, align 4, !tbaa !5
  %42 = sext i32 %40 to i64
  %43 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 9, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 10, i64 %2
  store i32 %44, ptr %45, align 4, !tbaa !5
  %46 = sext i32 %44 to i64
  %47 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 10, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 11, i64 %2
  store i32 %48, ptr %49, align 4, !tbaa !5
  %50 = sext i32 %48 to i64
  %51 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 11, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 12, i64 %2
  store i32 %52, ptr %53, align 4, !tbaa !5
  %54 = sext i32 %52 to i64
  %55 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 12, i64 %54
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 13, i64 %2
  store i32 %56, ptr %57, align 4, !tbaa !5
  %58 = sext i32 %56 to i64
  %59 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 13, i64 %58
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 14, i64 %2
  store i32 %60, ptr %61, align 4, !tbaa !5
  %62 = sext i32 %60 to i64
  %63 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 14, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 15, i64 %2
  store i32 %64, ptr %65, align 4, !tbaa !5
  %66 = sext i32 %64 to i64
  %67 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 15, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 16, i64 %2
  store i32 %68, ptr %69, align 4, !tbaa !5
  %70 = sext i32 %68 to i64
  %71 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 16, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 17, i64 %2
  store i32 %72, ptr %73, align 4, !tbaa !5
  %74 = sext i32 %72 to i64
  %75 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 17, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = getelementptr inbounds [19 x [500001 x i32]], ptr @st, i64 0, i64 18, i64 %2
  store i32 %76, ptr %77, align 4, !tbaa !5
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) 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" }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass