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

@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [61 x i8], align 1
@__PRETTY_FUNCTION__.rb3_INLINE_find = external hidden unnamed_addr constant [103 x i8], align 1

; 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_has_child(ptr noundef, i32 noundef) #0

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: inlinehint nounwind uwtable
define dso_local ptr @rb3_INLINE_find(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  store ptr %5, ptr %13, align 8, !tbaa !5
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = icmp ne ptr %16, null
  br i1 %17, label %18, label %19

18:                                               ; preds = %6
  br label %20

19:                                               ; preds = %6
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.5, i32 noundef 461, ptr noundef @__PRETTY_FUNCTION__.rb3_INLINE_find) #3
  unreachable

20:                                               ; preds = %18
  br label %21

21:                                               ; preds = %45, %20
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = call i32 @rb3_has_child(ptr noundef %22, i32 noundef %23)
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %46

26:                                               ; preds = %21
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load i32, ptr %9, align 4, !tbaa !9
  %29 = call ptr @rb3_get_child(ptr noundef %27, i32 noundef %28)
  store ptr %29, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = load ptr, ptr %8, align 8, !tbaa !5
  %32 = load ptr, ptr %11, align 8, !tbaa !5
  %33 = call i32 %30(ptr noundef %31, ptr noundef %32)
  store i32 %33, ptr %14, align 4, !tbaa !9
  %34 = load i32, ptr %14, align 4, !tbaa !9
  %35 = icmp eq i32 %34, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %26
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %37, ptr %7, align 8
  store i32 1, ptr %15, align 4
  br label %43

38:                                               ; preds = %26
  %39 = load i32, ptr %14, align 4, !tbaa !9
  %40 = icmp slt i32 %39, 0
  %41 = zext i1 %40 to i64
  %42 = select i1 %40, i32 1, i32 0
  store i32 %42, ptr %9, align 4, !tbaa !9
  store i32 0, ptr %15, align 4
  br label %43

43:                                               ; preds = %38, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  %44 = load i32, ptr %15, align 4
  switch i32 %44, label %61 [
    i32 0, label %45
    i32 1, label %59
  ]

45:                                               ; preds = %43
  br label %21, !llvm.loop !11

46:                                               ; preds = %21
  %47 = load ptr, ptr %12, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %52

49:                                               ; preds = %46
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %50, ptr %51, align 8, !tbaa !5
  br label %52

52:                                               ; preds = %49, %46
  %53 = load ptr, ptr %13, align 8, !tbaa !5
  %54 = icmp ne ptr %53, null
  br i1 %54, label %55, label %58

55:                                               ; preds = %52
  %56 = load i32, ptr %9, align 4, !tbaa !9
  %57 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 %56, ptr %57, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %55, %52
  store ptr null, ptr %7, align 8
  br label %59

59:                                               ; preds = %58, %43
  %60 = load ptr, ptr %7, align 8
  ret ptr %60

61:                                               ; preds = %43
  unreachable
}

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 = { noreturn nounwind "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 = { noreturn nounwind }
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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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

@.str.4 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [61 x i8], align 1
@__PRETTY_FUNCTION__.rb3_INLINE_find = external hidden unnamed_addr constant [103 x i8], align 1

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

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
define dso_local noundef ptr @rb3_INLINE_find(ptr noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2, ptr noundef %3, ptr noundef writeonly %4, ptr noundef writeonly %5) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %7, label %.preheader

7:                                                ; preds = %6
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.5, i32 noundef 461, ptr noundef nonnull @__PRETTY_FUNCTION__.rb3_INLINE_find) #2
  unreachable

.preheader:                                       ; preds = %6, %9
  %.020 = phi i32 [ %.lobit, %9 ], [ %1, %6 ]
  %.019 = phi ptr [ %10, %9 ], [ %0, %6 ]
  %8 = tail call i32 @rb3_has_child(ptr noundef %.019, i32 noundef %.020)
  %.not26 = icmp eq i32 %8, 0
  br i1 %.not26, label %12, label %9

9:                                                ; preds = %.preheader
  %10 = tail call ptr @rb3_get_child(ptr noundef %.019, i32 noundef %.020)
  %11 = tail call i32 %2(ptr noundef %10, ptr noundef %3) #3
  %.not29 = icmp eq i32 %11, 0
  %.lobit = lshr i32 %11, 31
  br i1 %.not29, label %.loopexit, label %.preheader

12:                                               ; preds = %.preheader
  %.not27 = icmp eq ptr %4, null
  br i1 %.not27, label %14, label %13

13:                                               ; preds = %12
  store ptr %.019, ptr %4, align 8, !tbaa !5
  br label %14

14:                                               ; preds = %13, %12
  %.not28 = icmp eq ptr %5, null
  br i1 %.not28, label %.loopexit, label %15

15:                                               ; preds = %14
  store i32 %.020, ptr %5, align 4, !tbaa !9
  br label %.loopexit

.loopexit:                                        ; preds = %9, %14, %15
  %.2 = phi ptr [ null, %15 ], [ null, %14 ], [ %10, %9 ]
  ret ptr %.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 = { noreturn nounwind "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 = { noreturn nounwind }
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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass