; LLVM IR from BehaviorTree/BehaviorTree.CPP :: sample_nodes/crossdoor_nodes.ll (ZN9CrossDoor8pickLockEv)

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

%class.CrossDoor = type { i8, i8, i32 }

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z7SleepMSi(i32 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN9CrossDoor8pickLockEv(ptr noundef nonnull align 4 dereferenceable(8) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8
  call void @_Z7SleepMSi(i32 noundef 500)
  %4 = getelementptr inbounds %class.CrossDoor, ptr %3, i32 0, i32 2
  %5 = load i32, ptr %4, align 4, !tbaa !9
  %6 = add nsw i32 %5, 1
  store i32 %6, ptr %4, align 4, !tbaa !9
  %7 = icmp sgt i32 %5, 3
  br i1 %7, label %8, label %11

8:                                                ; preds = %1
  %9 = getelementptr inbounds %class.CrossDoor, ptr %3, i32 0, i32 1
  store i8 0, ptr %9, align 1, !tbaa !13
  %10 = getelementptr inbounds %class.CrossDoor, ptr %3, i32 0, i32 0
  store i8 1, ptr %10, align 4, !tbaa !14
  br label %11

11:                                               ; preds = %8, %1
  %12 = getelementptr inbounds %class.CrossDoor, ptr %3, i32 0, i32 0
  %13 = load i8, ptr %12, align 4, !tbaa !14, !range !15, !noundef !16
  %14 = trunc i8 %13 to i1
  %15 = zext i1 %14 to i64
  %16 = select i1 %14, i32 2, i32 3
  ret i32 %16
}

attributes #0 = { inlinehint 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 = { 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, !12, i64 4}
!10 = !{!"_ZTS9CrossDoor", !11, i64 0, !11, i64 1, !12, i64 4}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !11, i64 1}
!14 = !{!10, !11, i64 0}
!15 = !{i8 0, i8 2}
!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 mustprogress uwtable
declare dso_local void @_Z7SleepMSi(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 2, 4) i32 @_ZN9CrossDoor8pickLockEv(ptr nocapture noundef nonnull align 4 dereferenceable(8) %0) local_unnamed_addr #1 align 2 {
  tail call void @_Z7SleepMSi(i32 noundef 500)
  %2 = getelementptr inbounds i8, ptr %0, i64 4
  %3 = load i32, ptr %2, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  store i32 %4, ptr %2, align 4, !tbaa !5
  %5 = icmp sgt i32 %3, 3
  br i1 %5, label %8, label %._crit_edge

._crit_edge:                                      ; preds = %1
  %.pre = load i8, ptr %0, align 4, !tbaa !11, !range !12
  %6 = trunc nuw i8 %.pre to i1
  %7 = select i1 %6, i32 2, i32 3
  br label %10

8:                                                ; preds = %1
  %9 = getelementptr inbounds i8, ptr %0, i64 1
  store i8 0, ptr %9, align 1, !tbaa !13
  store i8 1, ptr %0, align 4, !tbaa !11
  br label %10

10:                                               ; preds = %._crit_edge, %8
  %11 = phi i32 [ %7, %._crit_edge ], [ 2, %8 ]
  ret i32 %11
}

attributes #0 = { inlinehint 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 = { 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, !10, i64 4}
!6 = !{!"_ZTS9CrossDoor", !7, i64 0, !7, i64 1, !10, i64 4}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{!6, !7, i64 1}


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