; LLVM IR from BehaviorTree/BehaviorTree.CPP :: src (action_node)

; 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.mco_coro = type { ptr, i32, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr, i64, i64, ptr, ptr, ptr, i64 }

@.str.13 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [33 x i8], align 1

declare i32 @puts(ptr noundef) #0

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

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

10:                                               ; preds = %3
  %11 = call i32 @puts(ptr noundef @.str.13)
  store i32 3, ptr %4, align 4
  br label %42

12:                                               ; preds = %3
  %13 = load i64, ptr %7, align 8, !tbaa !9
  %14 = icmp ugt i64 %13, 0
  br i1 %14, label %15, label %40

15:                                               ; preds = %12
  %16 = load i64, ptr %7, align 8, !tbaa !9
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mco_coro, ptr %17, i32 0, i32 10
  %19 = load i64, ptr %18, align 8, !tbaa !11
  %20 = icmp ugt i64 %16, %19
  br i1 %20, label %21, label %23

21:                                               ; preds = %15
  %22 = call i32 @puts(ptr noundef @.str.17)
  store i32 8, ptr %4, align 4
  br label %42

23:                                               ; preds = %15
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %28, label %26

26:                                               ; preds = %23
  %27 = call i32 @puts(ptr noundef @.str.18)
  store i32 2, ptr %4, align 4
  br label %42

28:                                               ; preds = %23
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.mco_coro, ptr %30, i32 0, i32 9
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.mco_coro, ptr %33, i32 0, i32 10
  %35 = load i64, ptr %34, align 8, !tbaa !11
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = sub i64 %35, %36
  %38 = getelementptr inbounds i8, ptr %32, i64 %37
  %39 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %29, ptr align 1 %38, i64 %39, i1 false)
  br label %40

40:                                               ; preds = %28, %12
  br label %41

41:                                               ; preds = %40
  store i32 0, ptr %4, align 4
  br label %42

42:                                               ; preds = %41, %26, %21, %10
  %43 = load i32, ptr %4, align 4
  ret i32 %43
}

attributes #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 nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 80}
!12 = !{!"_ZTS8mco_coro", !6, i64 0, !13, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !10, i64 64, !6, i64 72, !10, i64 80, !10, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !10, i64 120}
!13 = !{!"_ZTS9mco_state", !7, i64 0}
!14 = !{!12, !6, i64 72}


; 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.13 = external hidden unnamed_addr constant [36 x i8], align 1
@.str.17 = external hidden unnamed_addr constant [54 x i8], align 1
@.str.18 = external hidden unnamed_addr constant [33 x i8], align 1

; Function Attrs: nofree nounwind
declare noundef i32 @puts(ptr nocapture noundef readonly) local_unnamed_addr #0

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

; Function Attrs: mustprogress nofree nounwind uwtable
define dso_local range(i32 0, 9) i32 @mco_peek(ptr noundef readonly %0, ptr noundef writeonly %1, i64 noundef %2) local_unnamed_addr #2 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %4, label %6

4:                                                ; preds = %3
  %5 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.13)
  br label %21

6:                                                ; preds = %3
  %.not14 = icmp eq i64 %2, 0
  br i1 %.not14, label %21, label %7

7:                                                ; preds = %6
  %8 = getelementptr inbounds i8, ptr %0, i64 80
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = icmp ult i64 %9, %2
  br i1 %10, label %11, label %13

11:                                               ; preds = %7
  %12 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.17)
  br label %21

13:                                               ; preds = %7
  %.not15 = icmp eq ptr %1, null
  br i1 %.not15, label %14, label %16

14:                                               ; preds = %13
  %15 = tail call i32 @puts(ptr noundef nonnull dereferenceable(1) @.str.18)
  br label %21

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %0, i64 72
  %18 = load ptr, ptr %17, align 8, !tbaa !12
  %19 = sub i64 %9, %2
  %20 = getelementptr inbounds i8, ptr %18, i64 %19
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 1 %1, ptr align 1 %20, i64 %2, i1 false)
  br label %21

21:                                               ; preds = %16, %6, %14, %11, %4
  %.0 = phi i32 [ 8, %11 ], [ 2, %14 ], [ 3, %4 ], [ 0, %6 ], [ 0, %16 ]
  ret i32 %.0
}

attributes #0 = { nofree 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree 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, !11, i64 80}
!6 = !{!"_ZTS8mco_coro", !7, i64 0, !10, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !7, i64 48, !7, i64 56, !11, i64 64, !7, i64 72, !11, i64 80, !11, i64 88, !7, i64 96, !7, i64 104, !7, i64 112, !11, i64 120}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS9mco_state", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !7, i64 72}


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