; LLVM IR from libtcod/libtcod :: src/libtcod/bsp.ll (ZN7TCODBsp9splitOnceEbi)

; 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.TCODBsp = type <{ ptr, %class.TCODTree, i32, i32, i32, i32, i32, i8, i8, [2 x i8] }>
%class.TCODTree = type { ptr, ptr, ptr }

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7TCODBsp9splitOnceEbi(ptr noundef nonnull align 8 dereferenceable(54) %0, i1 noundef zeroext %1, i32 noundef %2) #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = alloca ptr, align 8
  %5 = alloca i8, align 1
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  %9 = zext i1 %1 to i8
  store i8 %9, ptr %5, align 1, !tbaa !9
  store i32 %2, ptr %6, align 4, !tbaa !11
  %10 = load ptr, ptr %4, align 8
  %11 = load i8, ptr %5, align 1, !tbaa !9, !range !13, !noundef !14
  %12 = trunc i8 %11 to i1
  %13 = getelementptr inbounds %class.TCODBsp, ptr %10, i32 0, i32 7
  %14 = zext i1 %12 to i8
  store i8 %14, ptr %13, align 4, !tbaa !15
  %15 = load i32, ptr %6, align 4, !tbaa !11
  %16 = getelementptr inbounds %class.TCODBsp, ptr %10, i32 0, i32 6
  store i32 %15, ptr %16, align 8, !tbaa !18
  %17 = getelementptr inbounds i8, ptr %10, i64 8
  %18 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 56) #4
  invoke void @_ZN7TCODBspC1EPS_b(ptr noundef nonnull align 8 dereferenceable(54) %18, ptr noundef %10, i1 noundef zeroext true)
          to label %19 unwind label %33

19:                                               ; preds = %3
  %20 = icmp eq ptr %18, null
  br i1 %20, label %23, label %21

21:                                               ; preds = %19
  %22 = getelementptr inbounds i8, ptr %18, i64 8
  br label %23

23:                                               ; preds = %21, %19
  %24 = phi ptr [ %22, %21 ], [ null, %19 ]
  call void @_ZN8TCODTree6addSonEPS_(ptr noundef nonnull align 8 dereferenceable(24) %17, ptr noundef %24)
  %25 = getelementptr inbounds i8, ptr %10, i64 8
  %26 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 56) #4
  invoke void @_ZN7TCODBspC1EPS_b(ptr noundef nonnull align 8 dereferenceable(54) %26, ptr noundef %10, i1 noundef zeroext false)
          to label %27 unwind label %37

27:                                               ; preds = %23
  %28 = icmp eq ptr %26, null
  br i1 %28, label %31, label %29

29:                                               ; preds = %27
  %30 = getelementptr inbounds i8, ptr %26, i64 8
  br label %31

31:                                               ; preds = %29, %27
  %32 = phi ptr [ %30, %29 ], [ null, %27 ]
  call void @_ZN8TCODTree6addSonEPS_(ptr noundef nonnull align 8 dereferenceable(24) %25, ptr noundef %32)
  ret void

33:                                               ; preds = %3
  %34 = landingpad { ptr, i32 }
          cleanup
  %35 = extractvalue { ptr, i32 } %34, 0
  store ptr %35, ptr %7, align 8
  %36 = extractvalue { ptr, i32 } %34, 1
  store i32 %36, ptr %8, align 4
  call void @_ZdlPvm(ptr noundef %18, i64 noundef 56) #5
  br label %41

37:                                               ; preds = %23
  %38 = landingpad { ptr, i32 }
          cleanup
  %39 = extractvalue { ptr, i32 } %38, 0
  store ptr %39, ptr %7, align 8
  %40 = extractvalue { ptr, i32 } %38, 1
  store i32 %40, ptr %8, align 4
  call void @_ZdlPvm(ptr noundef %26, i64 noundef 56) #5
  br label %41

41:                                               ; preds = %37, %33
  %42 = load ptr, ptr %7, align 8
  %43 = load i32, ptr %8, align 4
  %44 = insertvalue { ptr, i32 } poison, ptr %42, 0
  %45 = insertvalue { ptr, i32 } %44, i32 %43, 1
  resume { ptr, i32 } %45
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8TCODTree6addSonEPS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) #2 align 2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #3

declare void @_ZN7TCODBspC1EPS_b(ptr, ptr, i1)

attributes #0 = { nobuiltin 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 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 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 #3 = { nobuiltin allocsize(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 #4 = { builtin allocsize(0) }
attributes #5 = { builtin 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 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !10, i64 52}
!16 = !{!"_ZTS7TCODBsp", !17, i64 8, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !12, i64 48, !10, i64 52, !7, i64 53}
!17 = !{!"_ZTS8TCODTree", !6, i64 0, !6, i64 8, !6, i64 16}
!18 = !{!16, !12, i64 48}


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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7TCODBsp9splitOnceEbi(ptr noundef nonnull align 8 dereferenceable(54) %0, i1 noundef zeroext %1, i32 noundef %2) local_unnamed_addr #1 align 2 personality ptr @__gxx_personality_v0 {
  %4 = zext i1 %1 to i8
  %5 = getelementptr inbounds i8, ptr %0, i64 52
  store i8 %4, ptr %5, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 48
  store i32 %2, ptr %6, align 8, !tbaa !13
  %7 = getelementptr inbounds i8, ptr %0, i64 8
  %8 = tail call noalias noundef nonnull dereferenceable(56) ptr @_Znwm(i64 noundef 56) #4
  invoke void @_ZN7TCODBspC1EPS_b(ptr noundef nonnull align 8 dereferenceable(54) %8, ptr noundef nonnull %0, i1 noundef zeroext true)
          to label %9 unwind label %14

9:                                                ; preds = %3
  %10 = getelementptr inbounds i8, ptr %8, i64 8
  tail call void @_ZN8TCODTree6addSonEPS_(ptr noundef nonnull align 8 dereferenceable(24) %7, ptr noundef nonnull %10)
  %11 = tail call noalias noundef nonnull dereferenceable(56) ptr @_Znwm(i64 noundef 56) #4
  invoke void @_ZN7TCODBspC1EPS_b(ptr noundef nonnull align 8 dereferenceable(54) %11, ptr noundef nonnull %0, i1 noundef zeroext false)
          to label %12 unwind label %16

12:                                               ; preds = %9
  %13 = getelementptr inbounds i8, ptr %11, i64 8
  tail call void @_ZN8TCODTree6addSonEPS_(ptr noundef nonnull align 8 dereferenceable(24) %7, ptr noundef nonnull %13)
  ret void

14:                                               ; preds = %3
  %15 = landingpad { ptr, i32 }
          cleanup
  br label %18

16:                                               ; preds = %9
  %17 = landingpad { ptr, i32 }
          cleanup
  br label %18

18:                                               ; preds = %16, %14
  %.sink = phi ptr [ %11, %16 ], [ %8, %14 ]
  %.pn = phi { ptr, i32 } [ %17, %16 ], [ %15, %14 ]
  tail call void @_ZdlPvm(ptr noundef nonnull %.sink, i64 noundef 56) #5
  resume { ptr, i32 } %.pn
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZN8TCODTree6addSonEPS_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef) local_unnamed_addr #2 align 2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #3

declare void @_ZN7TCODBspC1EPS_b(ptr, ptr, i1) local_unnamed_addr

attributes #0 = { nobuiltin 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 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 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 #3 = { nobuiltin allocsize(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 #4 = { builtin allocsize(0) }
attributes #5 = { builtin 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, !12, i64 52}
!6 = !{!"_ZTS7TCODBsp", !7, i64 8, !11, i64 32, !11, i64 36, !11, i64 40, !11, i64 44, !11, i64 48, !12, i64 52, !9, i64 53}
!7 = !{!"_ZTS8TCODTree", !8, i64 0, !8, i64 8, !8, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"bool", !9, i64 0}
!13 = !{!6, !11, i64 48}


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