; LLVM IR from tangjz/acm-icpc :: hdu/6096.ll (Z5buildRiPc)

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

%struct.Trie = type { i32, [26 x i32] }

@tot = external dso_local global i32, align 4
@e = external dso_local global [600001 x %struct.Trie], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z5buildRiPc(ptr noundef nonnull align 4 dereferenceable(4) %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %5 = load ptr, ptr %3, align 8, !tbaa !5
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [600001 x %struct.Trie], ptr @e, i64 0, i64 %7
  %9 = load i32, ptr @tot, align 4, !tbaa !9
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [600001 x %struct.Trie], ptr @e, i64 0, i64 %10
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %11, ptr align 4 %8, i64 108, i1 false), !tbaa.struct !11
  %12 = load i32, ptr @tot, align 4, !tbaa !9
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr @tot, align 4, !tbaa !9
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  store i32 %12, ptr %14, align 4, !tbaa !9
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = load i32, ptr %15, align 4, !tbaa !9
  %17 = sext i32 %16 to i64
  %18 = getelementptr inbounds [600001 x %struct.Trie], ptr @e, i64 0, i64 %17
  %19 = getelementptr inbounds %struct.Trie, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 4, !tbaa !13
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %19, align 4, !tbaa !13
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !12
  %24 = icmp ne i8 %23, 0
  br i1 %24, label %25, label %39

25:                                               ; preds = %2
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = sext i32 %27 to i64
  %29 = getelementptr inbounds [600001 x %struct.Trie], ptr @e, i64 0, i64 %28
  %30 = getelementptr inbounds %struct.Trie, ptr %29, i32 0, i32 1
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = load i8, ptr %31, align 1, !tbaa !12
  %33 = sext i8 %32 to i32
  %34 = sub nsw i32 %33, 97
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [26 x i32], ptr %30, i64 0, i64 %35
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 -1
  call void @_Z5buildRiPc(ptr noundef nonnull align 4 dereferenceable(4) %36, ptr noundef %38)
  br label %39

39:                                               ; preds = %25, %2
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 nounwind willreturn memory(argmem: readwrite) }

!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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !9, i64 4, i64 104, !12}
!12 = !{!7, !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"_ZTS4Trie", !10, i64 0, !7, i64 4}


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

%struct.Trie = type { i32, [26 x i32] }

@tot = external dso_local local_unnamed_addr global i32, align 4
@e = external dso_local local_unnamed_addr global [600001 x %struct.Trie], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @_Z5buildRiPc(ptr nocapture noundef nonnull align 4 dereferenceable(4) %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  br label %tailrecurse

tailrecurse:                                      ; preds = %13, %2
  %.tr = phi ptr [ %0, %2 ], [ %18, %13 ]
  %.tr7 = phi ptr [ %1, %2 ], [ %19, %13 ]
  %3 = load i32, ptr %.tr, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [600001 x %struct.Trie], ptr @e, i64 0, i64 %4
  %6 = load i32, ptr @tot, align 4, !tbaa !5
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds [600001 x %struct.Trie], ptr @e, i64 0, i64 %7
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(108) %8, ptr noundef nonnull align 4 dereferenceable(108) %5, i64 108, i1 false), !tbaa.struct !9
  %9 = add nsw i32 %6, 1
  store i32 %9, ptr @tot, align 4, !tbaa !5
  store i32 %6, ptr %.tr, align 4, !tbaa !5
  %10 = load i32, ptr %8, align 4, !tbaa !11
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr %8, align 4, !tbaa !11
  %12 = load i8, ptr %.tr7, align 1, !tbaa !10
  %.not = icmp eq i8 %12, 0
  br i1 %.not, label %20, label %13

13:                                               ; preds = %tailrecurse
  %14 = load i32, ptr %.tr, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = sext i8 %12 to i64
  %17 = add nsw i64 %16, -97
  %18 = getelementptr inbounds [600001 x %struct.Trie], ptr @e, i64 0, i64 %15, i32 1, i64 %17
  %19 = getelementptr inbounds i8, ptr %.tr7, i64 -1
  br label %tailrecurse

20:                                               ; preds = %tailrecurse
  ret void
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

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

!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 = !{i64 0, i64 4, !5, i64 4, i64 104, !10}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4Trie", !6, i64 0, !7, i64 4}


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