; LLVM IR from libtcod/libtcod :: src/libtcod (bsp_c)

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

; 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: nounwind uwtable
declare dso_local ptr @TCOD_bsp_left(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @TCOD_bsp_right(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @TCOD_bsp_traverse_level_order(ptr noundef %0, ptr noundef %1, ptr noundef %2) #1 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  %11 = call ptr @TCOD_list_new()
  store ptr %11, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %8, align 8, !tbaa !5
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  call void @TCOD_list_push(ptr noundef %12, ptr noundef %13)
  br label %14

14:                                               ; preds = %48, %3
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = call zeroext i1 @TCOD_list_is_empty(ptr noundef %15)
  %17 = xor i1 %16, true
  br i1 %17, label %18, label %49

18:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  %20 = call ptr @TCOD_list_get(ptr noundef %19, i32 noundef 0)
  store ptr %20, ptr %9, align 8, !tbaa !5
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  call void @TCOD_list_remove(ptr noundef %21, ptr noundef %22)
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = call ptr @TCOD_bsp_left(ptr noundef %23)
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %30

26:                                               ; preds = %18
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load ptr, ptr %9, align 8, !tbaa !5
  %29 = call ptr @TCOD_bsp_left(ptr noundef %28)
  call void @TCOD_list_push(ptr noundef %27, ptr noundef %29)
  br label %30

30:                                               ; preds = %26, %18
  %31 = load ptr, ptr %9, align 8, !tbaa !5
  %32 = call ptr @TCOD_bsp_right(ptr noundef %31)
  %33 = icmp ne ptr %32, null
  br i1 %33, label %34, label %38

34:                                               ; preds = %30
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load ptr, ptr %9, align 8, !tbaa !5
  %37 = call ptr @TCOD_bsp_right(ptr noundef %36)
  call void @TCOD_list_push(ptr noundef %35, ptr noundef %37)
  br label %38

38:                                               ; preds = %34, %30
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = call zeroext i1 %39(ptr noundef %40, ptr noundef %41)
  br i1 %42, label %45, label %43

43:                                               ; preds = %38
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  call void @TCOD_list_delete(ptr noundef %44)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %46

45:                                               ; preds = %38
  store i32 0, ptr %10, align 4
  br label %46

46:                                               ; preds = %45, %43
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  %47 = load i32, ptr %10, align 4
  switch i32 %47, label %51 [
    i32 0, label %48
  ]

48:                                               ; preds = %46
  br label %14, !llvm.loop !9

49:                                               ; preds = %14
  %50 = load ptr, ptr %8, align 8, !tbaa !5
  call void @TCOD_list_delete(ptr noundef %50)
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %51

51:                                               ; preds = %49, %46
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %52 = load i1, ptr %4, align 1
  ret i1 %52
}

declare ptr @TCOD_list_new() #2

declare void @TCOD_list_push(ptr noundef, ptr noundef) #2

declare zeroext i1 @TCOD_list_is_empty(ptr noundef) #2

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

declare void @TCOD_list_remove(ptr noundef, ptr noundef) #2

declare void @TCOD_list_delete(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"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"

; Function Attrs: nounwind uwtable
declare dso_local ptr @TCOD_bsp_left(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @TCOD_bsp_right(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @TCOD_bsp_traverse_level_order(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2) local_unnamed_addr #0 {
  %4 = tail call ptr @TCOD_list_new() #2
  tail call void @TCOD_list_push(ptr noundef %4, ptr noundef %0) #2
  br label %.critedge

.critedge:                                        ; preds = %15, %3
  %5 = tail call zeroext i1 @TCOD_list_is_empty(ptr noundef %4) #2
  br i1 %5, label %17, label %6

6:                                                ; preds = %.critedge
  %7 = tail call ptr @TCOD_list_get(ptr noundef %4, i32 noundef 0) #2
  tail call void @TCOD_list_remove(ptr noundef %4, ptr noundef %7) #2
  %8 = tail call ptr @TCOD_bsp_left(ptr noundef %7)
  %.not = icmp eq ptr %8, null
  br i1 %.not, label %11, label %9

9:                                                ; preds = %6
  %10 = tail call ptr @TCOD_bsp_left(ptr noundef %7)
  tail call void @TCOD_list_push(ptr noundef %4, ptr noundef %10) #2
  br label %11

11:                                               ; preds = %9, %6
  %12 = tail call ptr @TCOD_bsp_right(ptr noundef %7)
  %.not19 = icmp eq ptr %12, null
  br i1 %.not19, label %15, label %13

13:                                               ; preds = %11
  %14 = tail call ptr @TCOD_bsp_right(ptr noundef %7)
  tail call void @TCOD_list_push(ptr noundef %4, ptr noundef %14) #2
  br label %15

15:                                               ; preds = %13, %11
  %16 = tail call zeroext i1 %1(ptr noundef %7, ptr noundef %2) #2
  br i1 %16, label %.critedge, label %17, !llvm.loop !5

17:                                               ; preds = %.critedge, %15
  tail call void @TCOD_list_delete(ptr noundef %4) #2
  ret i1 %5
}

declare ptr @TCOD_list_new() local_unnamed_addr #1

declare void @TCOD_list_push(ptr noundef, ptr noundef) local_unnamed_addr #1

declare zeroext i1 @TCOD_list_is_empty(ptr noundef) local_unnamed_addr #1

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

declare void @TCOD_list_remove(ptr noundef, ptr noundef) local_unnamed_addr #1

declare void @TCOD_list_delete(ptr noundef) local_unnamed_addr #1

attributes #0 = { 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 = { "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 = { 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


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