; 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

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @TCOD_bsp_traverse_inverted_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 ptr, align 8
  %11 = alloca ptr, align 8
  %12 = 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
  %13 = call ptr @TCOD_list_new()
  store ptr %13, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %14 = call ptr @TCOD_list_new()
  store ptr %14, ptr %9, align 8, !tbaa !5
  %15 = load ptr, ptr %8, align 8, !tbaa !5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  call void @TCOD_list_push(ptr noundef %15, ptr noundef %16)
  br label %17

17:                                               ; preds = %43, %3
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = call zeroext i1 @TCOD_list_is_empty(ptr noundef %18)
  %20 = xor i1 %19, true
  br i1 %20, label %21, label %44

21:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #3
  %22 = load ptr, ptr %8, align 8, !tbaa !5
  %23 = call ptr @TCOD_list_get(ptr noundef %22, i32 noundef 0)
  store ptr %23, ptr %10, align 8, !tbaa !5
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  call void @TCOD_list_push(ptr noundef %24, ptr noundef %25)
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  call void @TCOD_list_remove(ptr noundef %26, ptr noundef %27)
  %28 = load ptr, ptr %10, align 8, !tbaa !5
  %29 = call ptr @TCOD_bsp_left(ptr noundef %28)
  %30 = icmp ne ptr %29, null
  br i1 %30, label %31, label %35

31:                                               ; preds = %21
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = call ptr @TCOD_bsp_left(ptr noundef %33)
  call void @TCOD_list_push(ptr noundef %32, ptr noundef %34)
  br label %35

35:                                               ; preds = %31, %21
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = call ptr @TCOD_bsp_right(ptr noundef %36)
  %38 = icmp ne ptr %37, null
  br i1 %38, label %39, label %43

39:                                               ; preds = %35
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = load ptr, ptr %10, align 8, !tbaa !5
  %42 = call ptr @TCOD_bsp_right(ptr noundef %41)
  call void @TCOD_list_push(ptr noundef %40, ptr noundef %42)
  br label %43

43:                                               ; preds = %39, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #3
  br label %17, !llvm.loop !9

44:                                               ; preds = %17
  br label %45

45:                                               ; preds = %62, %44
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  %47 = call zeroext i1 @TCOD_list_is_empty(ptr noundef %46)
  %48 = xor i1 %47, true
  br i1 %48, label %49, label %63

49:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %50 = load ptr, ptr %9, align 8, !tbaa !5
  %51 = call ptr @TCOD_list_pop(ptr noundef %50)
  store ptr %51, ptr %11, align 8, !tbaa !5
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = load ptr, ptr %11, align 8, !tbaa !5
  %54 = load ptr, ptr %7, align 8, !tbaa !5
  %55 = call zeroext i1 %52(ptr noundef %53, ptr noundef %54)
  br i1 %55, label %59, label %56

56:                                               ; preds = %49
  %57 = load ptr, ptr %8, align 8, !tbaa !5
  call void @TCOD_list_delete(ptr noundef %57)
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  call void @TCOD_list_delete(ptr noundef %58)
  store i1 false, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %60

59:                                               ; preds = %49
  store i32 0, ptr %12, align 4
  br label %60

60:                                               ; preds = %59, %56
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  %61 = load i32, ptr %12, align 4
  switch i32 %61, label %66 [
    i32 0, label %62
  ]

62:                                               ; preds = %60
  br label %45, !llvm.loop !11

63:                                               ; preds = %45
  %64 = load ptr, ptr %8, align 8, !tbaa !5
  call void @TCOD_list_delete(ptr noundef %64)
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  call void @TCOD_list_delete(ptr noundef %65)
  store i1 true, ptr %4, align 1
  store i32 1, ptr %12, align 4
  br label %66

66:                                               ; preds = %63, %60
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  %67 = load i1, ptr %4, align 1
  ret i1 %67
}

declare ptr @TCOD_list_pop(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"}
!11 = distinct !{!11, !10}


; 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

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

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i1 @TCOD_bsp_traverse_inverted_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
  %5 = tail call ptr @TCOD_list_new() #2
  tail call void @TCOD_list_push(ptr noundef %4, ptr noundef %0) #2
  %6 = tail call zeroext i1 @TCOD_list_is_empty(ptr noundef %4) #2
  br i1 %6, label %.critedge.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %3, %15
  %7 = tail call ptr @TCOD_list_get(ptr noundef %4, i32 noundef 0) #2
  tail call void @TCOD_list_push(ptr noundef %5, ptr noundef %7) #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 = %.lr.ph
  %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, %.lr.ph
  %12 = tail call ptr @TCOD_bsp_right(ptr noundef %7)
  %.not25 = icmp eq ptr %12, null
  br i1 %.not25, 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 @TCOD_list_is_empty(ptr noundef %4) #2
  br i1 %16, label %.critedge.preheader, label %.lr.ph, !llvm.loop !5

.critedge.preheader:                              ; preds = %15, %3
  br label %.critedge

.critedge:                                        ; preds = %.critedge.preheader, %18
  %17 = tail call zeroext i1 @TCOD_list_is_empty(ptr noundef %5) #2
  br i1 %17, label %21, label %18

18:                                               ; preds = %.critedge
  %19 = tail call ptr @TCOD_list_pop(ptr noundef %5) #2
  %20 = tail call zeroext i1 %1(ptr noundef %19, ptr noundef %2) #2
  br i1 %20, label %.critedge, label %21, !llvm.loop !7

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

declare ptr @TCOD_list_pop(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"}
!7 = distinct !{!7, !6}


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