; LLVM IR from uecker/noplate :: src (rb3ptr)

; 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.rb3_head = type { [2 x i64], i64 }

; Function Attrs: inlinehint nounwind uwtable
declare dso_local ptr @rb3_get_parent(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare dso_local ptr @rb3_get_child(ptr noundef, i32 noundef) #0

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

; Function Attrs: nounwind uwtable
declare dso_local void @rb3_update_augment(ptr noundef, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @rb3_child_ptr(ptr noundef, i32 noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @rb3_parent_ptr(ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
define dso_local void @rb3_replace_and_maybe_augment(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %13, i64 24, i1 false), !tbaa.struct !9
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call ptr @rb3_get_child(ptr noundef %14, i32 noundef 0)
  store ptr %15, ptr %7, align 8, !tbaa !5
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call ptr @rb3_get_child(ptr noundef %16, i32 noundef 1)
  store ptr %17, ptr %8, align 8, !tbaa !5
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = call ptr @rb3_get_parent(ptr noundef %18)
  store ptr %19, ptr %9, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = call i32 @rb3_get_parent_dir(ptr noundef %20)
  store i32 %21, ptr %10, align 4, !tbaa !13
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = load i32, ptr %10, align 4, !tbaa !13
  %24 = call i32 @rb3_get_color_bit(ptr noundef %22, i32 noundef %23)
  store i32 %24, ptr %11, align 4, !tbaa !13
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = icmp ne ptr %25, null
  br i1 %26, label %27, label %32

27:                                               ; preds = %3
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call i64 @rb3_parent_ptr(ptr noundef %28, i32 noundef 0)
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.rb3_head, ptr %30, i32 0, i32 1
  store i64 %29, ptr %31, align 8, !tbaa !15
  br label %32

32:                                               ; preds = %27, %3
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %40

35:                                               ; preds = %32
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = call i64 @rb3_parent_ptr(ptr noundef %36, i32 noundef 1)
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.rb3_head, ptr %38, i32 0, i32 1
  store i64 %37, ptr %39, align 8, !tbaa !15
  br label %40

40:                                               ; preds = %35, %32
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = load i32, ptr %11, align 4, !tbaa !13
  %43 = call i64 @rb3_child_ptr(ptr noundef %41, i32 noundef %42)
  %44 = load ptr, ptr %9, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.rb3_head, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %10, align 4, !tbaa !13
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [2 x i64], ptr %45, i64 0, i64 %47
  store i64 %43, ptr %48, align 8, !tbaa !11
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %54

51:                                               ; preds = %40
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  call void @rb3_update_augment(ptr noundef %52, ptr noundef %53)
  br label %54

54:                                               ; preds = %51, %40
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret void
}

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

; 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) #3

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @rb3_get_color_bit(ptr noundef, i32 noundef) #0

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

attributes #0 = { inlinehint 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 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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/C++ TBAA"}
!9 = !{i64 0, i64 16, !10, i64 16, i64 8, !11}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!16, !12, i64 16}
!16 = !{!"rb3_head", !7, i64 0, !12, i64 16}


; 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: inlinehint nounwind uwtable
declare dso_local ptr @rb3_get_parent(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare dso_local ptr @rb3_get_child(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare dso_local i32 @rb3_get_parent_dir(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @rb3_update_augment(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @rb3_child_ptr(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @rb3_parent_ptr(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @rb3_replace_and_maybe_augment(ptr noundef %0, ptr noundef %1, ptr noundef %2) local_unnamed_addr #1 {
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %1, ptr noundef nonnull align 8 dereferenceable(24) %0, i64 24, i1 false), !tbaa.struct !5
  %4 = tail call ptr @rb3_get_child(ptr noundef %0, i32 noundef 0)
  %5 = tail call ptr @rb3_get_child(ptr noundef %0, i32 noundef 1)
  %6 = tail call ptr @rb3_get_parent(ptr noundef %0)
  %7 = tail call i32 @rb3_get_parent_dir(ptr noundef %0)
  %8 = tail call i32 @rb3_get_color_bit(ptr noundef %6, i32 noundef %7)
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %12, label %9

9:                                                ; preds = %3
  %10 = tail call i64 @rb3_parent_ptr(ptr noundef nonnull %1, i32 noundef 0)
  %11 = getelementptr inbounds i8, ptr %4, i64 16
  store i64 %10, ptr %11, align 8, !tbaa !11
  br label %12

12:                                               ; preds = %9, %3
  %.not22 = icmp eq ptr %5, null
  br i1 %.not22, label %16, label %13

13:                                               ; preds = %12
  %14 = tail call i64 @rb3_parent_ptr(ptr noundef nonnull %1, i32 noundef 1)
  %15 = getelementptr inbounds i8, ptr %5, i64 16
  store i64 %14, ptr %15, align 8, !tbaa !11
  br label %16

16:                                               ; preds = %13, %12
  %17 = tail call i64 @rb3_child_ptr(ptr noundef nonnull %1, i32 noundef %8)
  %18 = sext i32 %7 to i64
  %19 = getelementptr inbounds [2 x i64], ptr %6, i64 0, i64 %18
  store i64 %17, ptr %19, align 8, !tbaa !9
  %.not23 = icmp eq ptr %2, null
  br i1 %.not23, label %21, label %20

20:                                               ; preds = %16
  tail call void @rb3_update_augment(ptr noundef nonnull %1, ptr noundef nonnull %2)
  br label %21

21:                                               ; preds = %20, %16
  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) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @rb3_get_color_bit(ptr noundef, i32 noundef) local_unnamed_addr #0

attributes #0 = { inlinehint 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 = { 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 #2 = { 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 = !{i64 0, i64 16, !6, i64 16, i64 8, !9}
!6 = !{!7, !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 16}
!12 = !{!"rb3_head", !7, i64 0, !10, i64 16}


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