; LLVM IR from BehaviorTree/BehaviorTree.CPP :: src/controls/manual_node.ll (ZNK2BT18ManualSelectorNode12selectStatusEv)

; 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.13 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [28 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZNK2BT18ManualSelectorNode12selectStatusEv(ptr noundef nonnull align 8 dereferenceable(48) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %6 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %7 = call ptr @initscr()
  %8 = call i32 @cbreak()
  %9 = call ptr @newwin(i32 noundef 6, i32 noundef 70, i32 noundef 1, i32 noundef 1)
  store ptr %9, ptr %3, align 8, !tbaa !5
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call i32 (ptr, i32, i32, ptr, ...) @mvwprintw(ptr noundef %10, i32 noundef 0, i32 noundef 0, ptr noundef @.str.13)
  %12 = load ptr, ptr %3, align 8, !tbaa !5
  %13 = call i32 (ptr, i32, i32, ptr, ...) @mvwprintw(ptr noundef %12, i32 noundef 1, i32 noundef 0, ptr noundef @.str.14)
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = call i32 (ptr, i32, i32, ptr, ...) @mvwprintw(ptr noundef %14, i32 noundef 2, i32 noundef 0, ptr noundef @.str.15)
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = call i32 (ptr, i32, i32, ptr, ...) @mvwprintw(ptr noundef %16, i32 noundef 3, i32 noundef 0, ptr noundef @.str.16)
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = call i32 @wrefresh(ptr noundef %18)
  %20 = call i32 @noecho()
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = call i32 @keypad(ptr noundef %21, i1 noundef zeroext true)
  %23 = call i32 @curs_set(i32 noundef 0)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  br label %24

24:                                               ; preds = %48, %1
  br label %25

25:                                               ; preds = %24
  %26 = load i32, ptr %4, align 4, !tbaa !9
  %27 = icmp eq i32 %26, 115
  br i1 %27, label %31, label %28

28:                                               ; preds = %25
  %29 = load i32, ptr %4, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 83
  br i1 %30, label %31, label %32

31:                                               ; preds = %28, %25
  store i32 2, ptr %5, align 4, !tbaa !11
  br label %51

32:                                               ; preds = %28
  %33 = load i32, ptr %4, align 4, !tbaa !9
  %34 = icmp eq i32 %33, 102
  br i1 %34, label %38, label %35

35:                                               ; preds = %32
  %36 = load i32, ptr %4, align 4, !tbaa !9
  %37 = icmp eq i32 %36, 70
  br i1 %37, label %38, label %39

38:                                               ; preds = %35, %32
  store i32 3, ptr %5, align 4, !tbaa !11
  br label %51

39:                                               ; preds = %35
  %40 = load i32, ptr %4, align 4, !tbaa !9
  %41 = icmp eq i32 %40, 114
  br i1 %41, label %45, label %42

42:                                               ; preds = %39
  %43 = load i32, ptr %4, align 4, !tbaa !9
  %44 = icmp eq i32 %43, 82
  br i1 %44, label %45, label %46

45:                                               ; preds = %42, %39
  store i32 1, ptr %5, align 4, !tbaa !11
  br label %51

46:                                               ; preds = %42
  br label %47

47:                                               ; preds = %46
  br label %48

48:                                               ; preds = %47
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = call i32 @wgetch(ptr noundef %49)
  store i32 %50, ptr %4, align 4, !tbaa !9
  br label %24, !llvm.loop !13

51:                                               ; preds = %45, %38, %31
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = call i32 @werase(ptr noundef %52)
  %54 = load ptr, ptr %3, align 8, !tbaa !5
  %55 = call i32 @wrefresh(ptr noundef %54)
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = call i32 @delwin(ptr noundef %56)
  %58 = call i32 @endwin()
  %59 = load i32, ptr %5, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret i32 %59
}

declare ptr @initscr() #2

declare i32 @cbreak() #2

declare ptr @newwin(i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

declare i32 @mvwprintw(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ...) #2

declare i32 @wrefresh(ptr noundef) #2

declare i32 @noecho() #2

declare i32 @keypad(ptr noundef, i1 noundef zeroext) #2

declare i32 @curs_set(i32 noundef) #2

declare i32 @wgetch(ptr noundef) #2

declare i32 @werase(ptr noundef) #2

declare i32 @delwin(ptr noundef) #2

declare i32 @endwin() #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_ZTSN2BT10NodeStatusE", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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.13 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.14 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.15 = external hidden unnamed_addr constant [31 x i8], align 1
@.str.16 = external hidden unnamed_addr constant [28 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i32 1, 4) i32 @_ZNK2BT18ManualSelectorNode12selectStatusEv(ptr nocapture noundef nonnull readnone align 8 dereferenceable(48) %0) local_unnamed_addr #0 align 2 {
  %2 = tail call ptr @initscr()
  %3 = tail call i32 @cbreak()
  %4 = tail call ptr @newwin(i32 noundef 6, i32 noundef 70, i32 noundef 1, i32 noundef 1)
  %5 = tail call i32 (ptr, i32, i32, ptr, ...) @mvwprintw(ptr noundef %4, i32 noundef 0, i32 noundef 0, ptr noundef nonnull @.str.13)
  %6 = tail call i32 (ptr, i32, i32, ptr, ...) @mvwprintw(ptr noundef %4, i32 noundef 1, i32 noundef 0, ptr noundef nonnull @.str.14)
  %7 = tail call i32 (ptr, i32, i32, ptr, ...) @mvwprintw(ptr noundef %4, i32 noundef 2, i32 noundef 0, ptr noundef nonnull @.str.15)
  %8 = tail call i32 (ptr, i32, i32, ptr, ...) @mvwprintw(ptr noundef %4, i32 noundef 3, i32 noundef 0, ptr noundef nonnull @.str.16)
  %9 = tail call i32 @wrefresh(ptr noundef %4)
  %10 = tail call i32 @noecho()
  %11 = tail call i32 @keypad(ptr noundef %4, i1 noundef zeroext true)
  %12 = tail call i32 @curs_set(i32 noundef 0)
  br label %13

13:                                               ; preds = %15, %1
  %.022 = phi i32 [ 0, %1 ], [ %16, %15 ]
  %14 = and i32 %.022, -33
  switch i32 %14, label %15 [
    i32 83, label %.fold.split.loopexit25
    i32 70, label %.fold.split.loopexit
    i32 82, label %.fold.split
  ]

15:                                               ; preds = %13
  %16 = tail call i32 @wgetch(ptr noundef %4)
  br label %13, !llvm.loop !5

.fold.split.loopexit25:                           ; preds = %13
  br label %.fold.split

.fold.split.loopexit:                             ; preds = %13
  br label %.fold.split

.fold.split:                                      ; preds = %13, %.fold.split.loopexit, %.fold.split.loopexit25
  %.0 = phi i32 [ 2, %.fold.split.loopexit25 ], [ 3, %.fold.split.loopexit ], [ 1, %13 ]
  %17 = tail call i32 @werase(ptr noundef %4)
  %18 = tail call i32 @wrefresh(ptr noundef %4)
  %19 = tail call i32 @delwin(ptr noundef %4)
  %20 = tail call i32 @endwin()
  ret i32 %.0
}

declare ptr @initscr() local_unnamed_addr #1

declare i32 @cbreak() local_unnamed_addr #1

declare ptr @newwin(i32 noundef, i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare i32 @mvwprintw(ptr noundef, i32 noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

declare i32 @wrefresh(ptr noundef) local_unnamed_addr #1

declare i32 @noecho() local_unnamed_addr #1

declare i32 @keypad(ptr noundef, i1 noundef zeroext) local_unnamed_addr #1

declare i32 @curs_set(i32 noundef) local_unnamed_addr #1

declare i32 @wgetch(ptr noundef) local_unnamed_addr #1

declare i32 @werase(ptr noundef) local_unnamed_addr #1

declare i32 @delwin(ptr noundef) local_unnamed_addr #1

declare i32 @endwin() local_unnamed_addr #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 = { "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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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