; LLVM IR from Tunghohin/Competitive_Coding :: Luogu/p2585.ll (Z5buildv)

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

%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@tr = external dso_local global [500010 x [2 x i32]], align 16
@timestamp = external dso_local global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z5buildv() #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #3
  %2 = load i32, ptr @timestamp, align 4, !tbaa !5
  %3 = add nsw i32 %2, 1
  store i32 %3, ptr @timestamp, align 4, !tbaa !5
  store i32 %3, ptr %1, align 4, !tbaa !5
  %4 = load i32, ptr @timestamp, align 4, !tbaa !5
  %5 = sub nsw i32 %4, 1
  %6 = sext i32 %5 to i64
  %7 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %6)
  %8 = load i8, ptr %7, align 1, !tbaa !9
  %9 = sext i8 %8 to i32
  %10 = icmp eq i32 %9, 50
  br i1 %10, label %11, label %22

11:                                               ; preds = %0
  %12 = call noundef i32 @_Z5buildv()
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [500010 x [2 x i32]], ptr @tr, i64 0, i64 %14
  %16 = getelementptr inbounds [2 x i32], ptr %15, i64 0, i64 0
  store i32 %12, ptr %16, align 8, !tbaa !5
  %17 = call noundef i32 @_Z5buildv()
  %18 = load i32, ptr %1, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [500010 x [2 x i32]], ptr @tr, i64 0, i64 %19
  %21 = getelementptr inbounds [2 x i32], ptr %20, i64 0, i64 1
  store i32 %17, ptr %21, align 4, !tbaa !5
  br label %37

22:                                               ; preds = %0
  %23 = load i32, ptr @timestamp, align 4, !tbaa !5
  %24 = sub nsw i32 %23, 1
  %25 = sext i32 %24 to i64
  %26 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %25)
  %27 = load i8, ptr %26, align 1, !tbaa !9
  %28 = sext i8 %27 to i32
  %29 = icmp eq i32 %28, 49
  br i1 %29, label %30, label %36

30:                                               ; preds = %22
  %31 = call noundef i32 @_Z5buildv()
  %32 = load i32, ptr %1, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [500010 x [2 x i32]], ptr @tr, i64 0, i64 %33
  %35 = getelementptr inbounds [2 x i32], ptr %34, i64 0, i64 0
  store i32 %31, ptr %35, align 8, !tbaa !5
  br label %36

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

37:                                               ; preds = %36, %11
  %38 = load i32, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #3
  ret i32 %38
}

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #2 align 2

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

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 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}


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

%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@tr = external dso_local local_unnamed_addr global [500010 x [2 x i32]], align 16
@timestamp = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef range(i32 -2147483647, -2147483648) i32 @_Z5buildv() local_unnamed_addr #0 {
  %1 = load i32, ptr @timestamp, align 4, !tbaa !5
  %2 = add nsw i32 %1, 1
  store i32 %2, ptr @timestamp, align 4, !tbaa !5
  %3 = sext i32 %1 to i64
  %4 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %3)
  %5 = load i8, ptr %4, align 1, !tbaa !9
  %6 = icmp eq i8 %5, 50
  br i1 %6, label %7, label %13

common.ret4:                                      ; preds = %13, %20, %7
  %common.ret4.op = phi i32 [ %2, %7 ], [ %2, %20 ], [ %2, %13 ]
  ret i32 %common.ret4.op

7:                                                ; preds = %0
  %8 = tail call noundef i32 @_Z5buildv()
  %9 = sext i32 %2 to i64
  %10 = getelementptr inbounds [500010 x [2 x i32]], ptr @tr, i64 0, i64 %9
  store i32 %8, ptr %10, align 8, !tbaa !5
  %11 = tail call noundef i32 @_Z5buildv()
  %12 = getelementptr inbounds i8, ptr %10, i64 4
  store i32 %11, ptr %12, align 4, !tbaa !5
  br label %common.ret4

13:                                               ; preds = %0
  %14 = load i32, ptr @timestamp, align 4, !tbaa !5
  %15 = add nsw i32 %14, -1
  %16 = sext i32 %15 to i64
  %17 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %16)
  %18 = load i8, ptr %17, align 1, !tbaa !9
  %19 = icmp eq i8 %18, 49
  br i1 %19, label %20, label %common.ret4

20:                                               ; preds = %13
  %21 = tail call noundef i32 @_Z5buildv()
  %22 = sext i32 %2 to i64
  %23 = getelementptr inbounds [500010 x [2 x i32]], ptr @tr, i64 0, i64 %22
  store i32 %21, ptr %23, align 8, !tbaa !5
  br label %common.ret4
}

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) local_unnamed_addr #0 align 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" }

!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 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass