; LLVM IR from tangjz/acm-icpc :: 51nod/1295.ll (Z6updateRiii)

; 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, [2 x i32] }

@seg_tot = external dso_local global i32, align 4
@seg = external dso_local global [1500030 x %struct.Trie], align 16

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6updateRiii(ptr noundef nonnull align 4 dereferenceable(4) %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %10, ptr %7, align 4, !tbaa !9
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1500030 x %struct.Trie], ptr @seg, i64 0, i64 %12
  %14 = load i32, ptr @seg_tot, align 4, !tbaa !9
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr @seg_tot, align 4, !tbaa !9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 %15, ptr %16, align 4, !tbaa !9
  %17 = sext i32 %15 to i64
  %18 = getelementptr inbounds [1500030 x %struct.Trie], ptr @seg, i64 0, i64 %17
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %18, ptr align 4 %13, i64 12, i1 false), !tbaa.struct !11
  %19 = load ptr, ptr %4, align 8, !tbaa !5
  %20 = load i32, ptr %19, align 4, !tbaa !9
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [1500030 x %struct.Trie], ptr @seg, i64 0, i64 %21
  %23 = getelementptr inbounds %struct.Trie, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 4, !tbaa !13
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %23, align 4, !tbaa !13
  %26 = load i32, ptr %5, align 4, !tbaa !9
  %27 = icmp eq i32 %26, -1
  br i1 %27, label %28, label %29

28:                                               ; preds = %3
  store i32 1, ptr %8, align 4
  br label %44

29:                                               ; preds = %3
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1500030 x %struct.Trie], ptr @seg, i64 0, i64 %32
  %34 = getelementptr inbounds %struct.Trie, ptr %33, i32 0, i32 1
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = load i32, ptr %5, align 4, !tbaa !9
  %37 = ashr i32 %35, %36
  %38 = and i32 %37, 1
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2 x i32], ptr %34, i64 0, i64 %39
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = sub nsw i32 %41, 1
  %43 = load i32, ptr %6, align 4, !tbaa !9
  call void @_Z6updateRiii(ptr noundef nonnull align 4 dereferenceable(4) %40, i32 noundef %42, i32 noundef %43)
  store i32 0, ptr %8, align 4
  br label %44

44:                                               ; preds = %29, %28
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %45 = load i32, ptr %8, align 4
  switch i32 %45, label %47 [
    i32 0, label %46
    i32 1, label %46
  ]

46:                                               ; preds = %44, %44
  ret void

47:                                               ; preds = %44
  unreachable
}

; 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #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 = { nocallback nofree 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 = !{!"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 8, !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, [2 x i32] }

@seg_tot = external dso_local local_unnamed_addr global i32, align 4
@seg = external dso_local local_unnamed_addr global [1500030 x %struct.Trie], align 16

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

tailrecurse:                                      ; preds = %17, %3
  %.tr = phi ptr [ %0, %3 ], [ %23, %17 ]
  %.tr9 = phi i32 [ %1, %3 ], [ %24, %17 ]
  %4 = load i32, ptr %.tr, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [1500030 x %struct.Trie], ptr @seg, i64 0, i64 %5
  %7 = load i32, ptr @seg_tot, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr @seg_tot, align 4, !tbaa !5
  store i32 %8, ptr %.tr, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [1500030 x %struct.Trie], ptr @seg, i64 0, i64 %9
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %10, ptr noundef nonnull align 4 dereferenceable(12) %6, i64 12, i1 false), !tbaa.struct !9
  %11 = load i32, ptr %.tr, align 4, !tbaa !5
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds [1500030 x %struct.Trie], ptr @seg, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !11
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %13, align 4, !tbaa !11
  %16 = icmp eq i32 %.tr9, -1
  br i1 %16, label %25, label %17

17:                                               ; preds = %tailrecurse
  %18 = load i32, ptr %.tr, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = lshr i32 %2, %.tr9
  %21 = and i32 %20, 1
  %22 = zext nneg i32 %21 to i64
  %23 = getelementptr inbounds [1500030 x %struct.Trie], ptr @seg, i64 0, i64 %19, i32 1, i64 %22
  %24 = add nsw i32 %.tr9, -1
  br label %tailrecurse

25:                                               ; 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 8, !10}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"_ZTS4Trie", !6, i64 0, !7, i64 4}


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