; LLVM IR from VastoLorde95/Competitive-Programming :: SPOJ/Random/HORRIBLE/treap.ll (ZN13ImplicitTreap9propagateEPNS_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.ImplicitTreap::node" = type { i32, i32, i64, ptr, ptr, i64, i64 }

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

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

11:                                               ; preds = %6, %1
  br label %60

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

35:                                               ; preds = %12
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = load i64, ptr %36, align 8, !tbaa !13
  %38 = load ptr, ptr %2, align 8, !tbaa !5
  %39 = getelementptr inbounds %"struct.ImplicitTreap::node", ptr %38, i32 0, i32 3
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  %41 = getelementptr inbounds %"struct.ImplicitTreap::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 = %35, %12
  %45 = load ptr, ptr %2, align 8, !tbaa !5
  %46 = getelementptr inbounds %"struct.ImplicitTreap::node", ptr %45, i32 0, i32 4
  %47 = load ptr, ptr %46, align 8, !tbaa !17
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %58

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

58:                                               ; preds = %49, %44
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  store i64 0, ptr %59, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  br label %60

60:                                               ; preds = %58, %11
  ret void
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN13ImplicitTreap7getSizeEPNS_4nodeE(ptr noundef) #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 = { inlinehint 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 #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, !12, i64 40}
!10 = !{!"_ZTSN13ImplicitTreap4nodeE", !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 = !{!12, !12, i64 0}
!14 = !{!10, !12, i64 8}
!15 = !{!10, !12, i64 32}
!16 = !{!10, !6, i64 16}
!17 = !{!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
define dso_local void @_ZN13ImplicitTreap9propagateEPNS_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
  %.not18 = icmp eq i64 %4, 0
  br i1 %.not18, label %31, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = load i64, ptr %6, align 8, !tbaa !9
  %8 = add nsw i64 %7, %4
  store i64 %8, ptr %6, align 8, !tbaa !9
  %9 = tail call noundef i32 @_ZN13ImplicitTreap7getSizeEPNS_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
  %.not19 = icmp eq ptr %16, null
  br i1 %.not19, 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 !15
  %21 = add nsw i64 %20, %18
  store i64 %21, ptr %19, align 8, !tbaa !15
  br label %22

22:                                               ; preds = %17, %5
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %.not20 = icmp eq ptr %24, null
  br i1 %.not20, 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 !15
  %29 = add nsw i64 %28, %26
  store i64 %29, ptr %27, align 8, !tbaa !15
  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
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN13ImplicitTreap7getSizeEPNS_4nodeE(ptr noundef) local_unnamed_addr #1

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


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