; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2013-14/Feb 2014/14 Feb G3.ll (Z7processii)

; 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.std::pair" = type { ptr, ptr }
%"struct.std::pair.0" = type { i32, i32 }
%struct.tnode = type { %"struct.std::pair.0", i32, i32, [2 x ptr] }

@root = external dso_local global ptr, align 8

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, ptr } @_Z5splitP5tnodei(ptr noundef, i32 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 uwtable
declare dso_local noundef ptr @_Z5mergeP5tnodeS0_(ptr noundef, ptr noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z3insP5tnodeSt4pairIiiE(ptr noundef, i64) #0

; 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: mustprogress uwtable
declare dso_local i64 @_Z6getlstP5tnode(ptr noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7processii(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %"struct.std::pair", align 8
  %6 = alloca %"struct.std::pair.0", align 4
  %7 = alloca %"struct.std::pair.0", align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #3
  %8 = load ptr, ptr @root, align 8, !tbaa !9
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = call { ptr, ptr } @_Z5splitP5tnodei(ptr noundef %8, i32 noundef %9)
  %11 = getelementptr inbounds { ptr, ptr }, ptr %5, i32 0, i32 0
  %12 = extractvalue { ptr, ptr } %10, 0
  store ptr %12, ptr %11, align 8
  %13 = getelementptr inbounds { ptr, ptr }, ptr %5, i32 0, i32 1
  %14 = extractvalue { ptr, ptr } %10, 1
  store ptr %14, ptr %13, align 8
  %15 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 1
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %24

18:                                               ; preds = %2
  %19 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 1
  %20 = load ptr, ptr %19, align 8, !tbaa !11
  %21 = getelementptr inbounds %struct.tnode, ptr %20, i32 0, i32 2
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %21, align 4, !tbaa !13
  br label %24

24:                                               ; preds = %18, %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %25 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !16
  %27 = call i64 @_Z6getlstP5tnode(ptr noundef %26)
  store i64 %27, ptr %6, align 4
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = add nsw i32 %28, %29
  %31 = getelementptr inbounds %"struct.std::pair.0", ptr %6, i32 0, i32 0
  %32 = load i32, ptr %31, align 4, !tbaa !17
  %33 = sub nsw i32 %30, %32
  %34 = getelementptr inbounds %"struct.std::pair.0", ptr %6, i32 0, i32 1
  %35 = load i32, ptr %34, align 4, !tbaa !18
  %36 = add nsw i32 %35, %33
  store i32 %36, ptr %34, align 4, !tbaa !18
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = getelementptr inbounds %"struct.std::pair.0", ptr %6, i32 0, i32 0
  store i32 %37, ptr %38, align 4, !tbaa !17
  %39 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 0
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  %41 = getelementptr inbounds %"struct.std::pair", ptr %5, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = call noundef ptr @_Z5mergeP5tnodeS0_(ptr noundef %40, ptr noundef %42)
  store ptr %43, ptr @root, align 8, !tbaa !9
  %44 = load ptr, ptr @root, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %7, ptr align 4 %6, i64 8, i1 false)
  %45 = load i64, ptr %7, align 4
  %46 = call noundef ptr @_Z3insP5tnodeSt4pairIiiE(ptr noundef %44, i64 %45)
  store ptr %46, ptr @root, align 8, !tbaa !9
  %47 = getelementptr inbounds %"struct.std::pair.0", ptr %6, i32 0, i32 1
  %48 = load i32, ptr %47, align 4, !tbaa !18
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #3
  ret i32 %48
}

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTSSt4pairIP5tnodeS1_E", !10, i64 0, !10, i64 8}
!13 = !{!14, !6, i64 12}
!14 = !{!"_ZTS5tnode", !15, i64 0, !6, i64 8, !6, i64 12, !7, i64 16}
!15 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!16 = !{!12, !10, i64 0}
!17 = !{!15, !6, i64 0}
!18 = !{!15, !6, 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"

@root = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress uwtable
declare dso_local { ptr, ptr } @_Z5splitP5tnodei(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z5mergeP5tnodeS0_(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z3insP5tnodeSt4pairIiiE(ptr noundef, i64) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_Z6getlstP5tnode(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z7processii(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @root, align 8, !tbaa !5
  %4 = tail call { ptr, ptr } @_Z5splitP5tnodei(ptr noundef %3, i32 noundef %0)
  %5 = extractvalue { ptr, ptr } %4, 1
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %10, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %5, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = add nsw i32 %8, 1
  store i32 %9, ptr %7, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %6, %2
  %11 = extractvalue { ptr, ptr } %4, 0
  %12 = tail call i64 @_Z6getlstP5tnode(ptr noundef %11)
  %.sroa.01.0.extract.trunc = trunc i64 %12 to i32
  %.sroa.6.0.extract.shift = lshr i64 %12, 32
  %.sroa.6.0.extract.trunc = trunc nuw i64 %.sroa.6.0.extract.shift to i32
  %13 = add nsw i32 %1, %0
  %14 = sub i32 %13, %.sroa.01.0.extract.trunc
  %15 = add nsw i32 %14, %.sroa.6.0.extract.trunc
  %16 = tail call noundef ptr @_Z5mergeP5tnodeS0_(ptr noundef %11, ptr noundef %5)
  store ptr %16, ptr @root, align 8, !tbaa !5
  %.sroa.6.0.insert.ext = zext i32 %15 to i64
  %.sroa.6.0.insert.shift = shl nuw i64 %.sroa.6.0.insert.ext, 32
  %.sroa.01.0.insert.ext = zext i32 %0 to i64
  %.sroa.01.0.insert.insert = or disjoint i64 %.sroa.6.0.insert.shift, %.sroa.01.0.insert.ext
  %17 = tail call noundef ptr @_Z3insP5tnodeSt4pairIiiE(ptr noundef %16, i64 %.sroa.01.0.insert.insert)
  store ptr %17, ptr @root, align 8, !tbaa !5
  ret i32 %15
}

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

!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, !12, i64 12}
!10 = !{!"_ZTS5tnode", !11, i64 0, !12, i64 8, !12, i64 12, !7, i64 16}
!11 = !{!"_ZTSSt4pairIiiE", !12, i64 0, !12, i64 4}
!12 = !{!"int", !7, i64 0}


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