; LLVM IR from VastoLorde95/Competitive-Programming :: Library/Implicit Treap.ll (ZN5Treap9propagateEPNS_4nodeE)

; 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.Treap::node" = type { i32, i32, i64, ptr, ptr, i64, i64 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN5Treap7getSizeEPNS_4nodeE(ptr noundef) #0

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

5:                                                ; preds = %1
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %"struct.Treap::node", ptr %6, i32 0, i32 6
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = icmp ne i64 %8, 0
  br i1 %9, label %11, label %10

10:                                               ; preds = %5, %1
  br label %62

11:                                               ; preds = %5
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %"struct.Treap::node", ptr %12, i32 0, i32 6
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %2, align 8, !tbaa !5
  %16 = getelementptr inbounds %"struct.Treap::node", ptr %15, i32 0, i32 2
  %17 = load i64, ptr %16, align 8, !tbaa !13
  %18 = add nsw i64 %17, %14
  store i64 %18, ptr %16, align 8, !tbaa !13
  %19 = load ptr, ptr %2, align 8, !tbaa !5
  %20 = getelementptr inbounds %"struct.Treap::node", ptr %19, i32 0, i32 6
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = call noundef i32 @_ZN5Treap7getSizeEPNS_4nodeE(ptr noundef %22)
  %24 = sext i32 %23 to i64
  %25 = mul nsw i64 %21, %24
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = getelementptr inbounds %"struct.Treap::node", ptr %26, i32 0, i32 5
  %28 = load i64, ptr %27, align 8, !tbaa !14
  %29 = add nsw i64 %28, %25
  store i64 %29, ptr %27, align 8, !tbaa !14
  %30 = load ptr, ptr %2, align 8, !tbaa !5
  %31 = getelementptr inbounds %"struct.Treap::node", ptr %30, i32 0, i32 3
  %32 = load ptr, ptr %31, align 8, !tbaa !15
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %44

34:                                               ; preds = %11
  %35 = load ptr, ptr %2, align 8, !tbaa !5
  %36 = getelementptr inbounds %"struct.Treap::node", ptr %35, i32 0, i32 6
  %37 = load i64, ptr %36, align 8, !tbaa !9
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.Treap::node", ptr %38, i32 0, i32 3
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = getelementptr inbounds %"struct.Treap::node", ptr %40, i32 0, i32 6
  %42 = load i64, ptr %41, align 8, !tbaa !9
  %43 = add nsw i64 %42, %37
  store i64 %43, ptr %41, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %34, %11
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.Treap::node", ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !16
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %59

49:                                               ; preds = %44
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.Treap::node", ptr %50, i32 0, i32 6
  %52 = load i64, ptr %51, align 8, !tbaa !9
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %"struct.Treap::node", ptr %53, i32 0, i32 4
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  %56 = getelementptr inbounds %"struct.Treap::node", ptr %55, i32 0, i32 6
  %57 = load i64, ptr %56, align 8, !tbaa !9
  %58 = add nsw i64 %57, %52
  store i64 %58, ptr %56, align 8, !tbaa !9
  br label %59

59:                                               ; preds = %49, %44
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %"struct.Treap::node", ptr %60, i32 0, i32 6
  store i64 0, ptr %61, align 8, !tbaa !9
  br label %62

62:                                               ; preds = %59, %10
  ret void
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !12, i64 40}
!10 = !{!"_ZTSN5Treap4nodeE", !11, i64 0, !11, i64 4, !12, i64 8, !6, i64 16, !6, i64 24, !12, i64 32, !12, i64 40}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{!10, !12, i64 32}
!15 = !{!10, !6, i64 16}
!16 = !{!10, !6, i64 24}


; 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 noundef i32 @_ZN5Treap7getSizeEPNS_4nodeE(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN5Treap9propagateEPNS_4nodeE(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %31, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 40
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %.not17 = icmp eq i64 %4, 0
  br i1 %.not17, label %31, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !12
  %8 = add nsw i64 %7, %4
  store i64 %8, ptr %6, align 8, !tbaa !12
  %9 = tail call noundef i32 @_ZN5Treap7getSizeEPNS_4nodeE(ptr noundef nonnull %0)
  %10 = sext i32 %9 to i64
  %11 = mul nsw i64 %4, %10
  %12 = getelementptr inbounds i8, ptr %0, i64 32
  %13 = load i64, ptr %12, align 8, !tbaa !13
  %14 = add nsw i64 %11, %13
  store i64 %14, ptr %12, align 8, !tbaa !13
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !14
  %.not18 = icmp eq ptr %16, null
  br i1 %.not18, label %22, label %17

17:                                               ; preds = %5
  %18 = load i64, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %16, i64 40
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = add nsw i64 %20, %18
  store i64 %21, ptr %19, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %17, %5
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  %.not19 = icmp eq ptr %24, null
  br i1 %.not19, label %30, label %25

25:                                               ; preds = %22
  %26 = load i64, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %24, i64 40
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = add nsw i64 %28, %26
  store i64 %29, ptr %27, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %25, %22
  store i64 0, ptr %3, align 8, !tbaa !5
  br label %31

31:                                               ; preds = %1, %2, %30
  ret void
}

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, !10, i64 40}
!6 = !{!"_ZTSN5Treap4nodeE", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !11, i64 24, !10, i64 32, !10, i64 40}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"long long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !10, i64 8}
!13 = !{!6, !10, i64 32}
!14 = !{!6, !11, i64 16}
!15 = !{!6, !11, i64 24}


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