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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5tnode9propogateEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z5mergeP5tnodeS0_(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %10, label %8

8:                                                ; preds = %2
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %9, ptr %3, align 8
  br label %47

10:                                               ; preds = %2
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp ne ptr %11, null
  br i1 %12, label %15, label %13

13:                                               ; preds = %10
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %14, ptr %3, align 8
  br label %47

15:                                               ; preds = %10
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  call void @_ZN5tnode9propogateEv(ptr noundef nonnull align 8 dereferenceable(32) %16)
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZN5tnode9propogateEv(ptr noundef nonnull align 8 dereferenceable(32) %17)
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.tnode, ptr %18, i32 0, i32 1
  %20 = load i32, ptr %19, align 8, !tbaa !9
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.tnode, ptr %21, i32 0, i32 1
  %23 = load i32, ptr %22, align 8, !tbaa !9
  %24 = icmp sgt i32 %20, %23
  br i1 %24, label %25, label %36

25:                                               ; preds = %15
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.tnode, ptr %26, i32 0, i32 3
  %28 = getelementptr inbounds [2 x ptr], ptr %27, i64 0, i64 1
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = call noundef ptr @_Z5mergeP5tnodeS0_(ptr noundef %29, ptr noundef %30)
  %32 = load ptr, ptr %4, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.tnode, ptr %32, i32 0, i32 3
  %34 = getelementptr inbounds [2 x ptr], ptr %33, i64 0, i64 1
  store ptr %31, ptr %34, align 8, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %35, ptr %3, align 8
  br label %47

36:                                               ; preds = %15
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load ptr, ptr %5, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.tnode, ptr %38, i32 0, i32 3
  %40 = getelementptr inbounds [2 x ptr], ptr %39, i64 0, i64 0
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = call noundef ptr @_Z5mergeP5tnodeS0_(ptr noundef %37, ptr noundef %41)
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.tnode, ptr %43, i32 0, i32 3
  %45 = getelementptr inbounds [2 x ptr], ptr %44, i64 0, i64 0
  store ptr %42, ptr %45, align 8, !tbaa !5
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %46, ptr %3, align 8
  br label %47

47:                                               ; preds = %36, %25, %13, %8
  %48 = load ptr, ptr %3, align 8
  ret ptr %48
}

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 = { 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 8}
!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}


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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN5tnode9propogateEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z5mergeP5tnodeS0_(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %common.ret20, label %3

3:                                                ; preds = %2
  %.not19 = icmp eq ptr %1, null
  br i1 %.not19, label %common.ret20, label %4

4:                                                ; preds = %3
  tail call void @_ZN5tnode9propogateEv(ptr noundef nonnull align 8 dereferenceable(32) %0)
  tail call void @_ZN5tnode9propogateEv(ptr noundef nonnull align 8 dereferenceable(32) %1)
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %1, i64 8
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = icmp sgt i32 %6, %8
  br i1 %9, label %10, label %14

common.ret20:                                     ; preds = %3, %2, %14, %10
  %common.ret20.op = phi ptr [ %0, %10 ], [ %1, %14 ], [ %1, %2 ], [ %0, %3 ]
  ret ptr %common.ret20.op

10:                                               ; preds = %4
  %11 = getelementptr inbounds i8, ptr %0, i64 24
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = tail call noundef ptr @_Z5mergeP5tnodeS0_(ptr noundef %12, ptr noundef nonnull %1)
  store ptr %13, ptr %11, align 8, !tbaa !11
  br label %common.ret20

14:                                               ; preds = %4
  %15 = getelementptr inbounds i8, ptr %1, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !11
  %17 = tail call noundef ptr @_Z5mergeP5tnodeS0_(ptr noundef nonnull %0, ptr noundef %16)
  store ptr %17, ptr %15, align 8, !tbaa !11
  br label %common.ret20
}

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


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