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

%struct.TCOD_bsp_t = type { %struct.TCOD_tree_t, i32, i32, i32, i32, i32, i8, i8 }
%struct.TCOD_tree_t = type { ptr, ptr, ptr }

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

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

; Function Attrs: nounwind uwtable
define dso_local void @TCOD_bsp_resize(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i32 %2, ptr %8, align 4, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !9
  store i32 %4, ptr %10, align 4, !tbaa !9
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.TCOD_bsp_t, ptr %12, i32 0, i32 1
  store i32 %11, ptr %13, align 8, !tbaa !11
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.TCOD_bsp_t, ptr %15, i32 0, i32 2
  store i32 %14, ptr %16, align 4, !tbaa !15
  %17 = load i32, ptr %9, align 4, !tbaa !9
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.TCOD_bsp_t, ptr %18, i32 0, i32 3
  store i32 %17, ptr %19, align 8, !tbaa !16
  %20 = load i32, ptr %10, align 4, !tbaa !9
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.TCOD_bsp_t, ptr %21, i32 0, i32 4
  store i32 %20, ptr %22, align 4, !tbaa !17
  %23 = load ptr, ptr %6, 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 %82

26:                                               ; preds = %5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.TCOD_bsp_t, ptr %27, i32 0, i32 7
  %29 = load i8, ptr %28, align 1, !tbaa !18, !range !19, !noundef !20
  %30 = trunc i8 %29 to i1
  br i1 %30, label %31, label %56

31:                                               ; preds = %26
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = call ptr @TCOD_bsp_left(ptr noundef %32)
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = load i32, ptr %8, align 4, !tbaa !9
  %36 = load i32, ptr %9, align 4, !tbaa !9
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TCOD_bsp_t, ptr %37, i32 0, i32 5
  %39 = load i32, ptr %38, align 8, !tbaa !21
  %40 = load i32, ptr %8, align 4, !tbaa !9
  %41 = sub nsw i32 %39, %40
  call void @TCOD_bsp_resize(ptr noundef %33, i32 noundef %34, i32 noundef %35, i32 noundef %36, i32 noundef %41)
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call ptr @TCOD_bsp_right(ptr noundef %42)
  %44 = load i32, ptr %7, align 4, !tbaa !9
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.TCOD_bsp_t, ptr %45, i32 0, i32 5
  %47 = load i32, ptr %46, align 8, !tbaa !21
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = load i32, ptr %8, align 4, !tbaa !9
  %50 = load i32, ptr %10, align 4, !tbaa !9
  %51 = add nsw i32 %49, %50
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.TCOD_bsp_t, ptr %52, i32 0, i32 5
  %54 = load i32, ptr %53, align 8, !tbaa !21
  %55 = sub nsw i32 %51, %54
  call void @TCOD_bsp_resize(ptr noundef %43, i32 noundef %44, i32 noundef %47, i32 noundef %48, i32 noundef %55)
  br label %81

56:                                               ; preds = %26
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = call ptr @TCOD_bsp_left(ptr noundef %57)
  %59 = load i32, ptr %7, align 4, !tbaa !9
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.TCOD_bsp_t, ptr %61, i32 0, i32 5
  %63 = load i32, ptr %62, align 8, !tbaa !21
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = sub nsw i32 %63, %64
  %66 = load i32, ptr %10, align 4, !tbaa !9
  call void @TCOD_bsp_resize(ptr noundef %58, i32 noundef %59, i32 noundef %60, i32 noundef %65, i32 noundef %66)
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = call ptr @TCOD_bsp_right(ptr noundef %67)
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.TCOD_bsp_t, ptr %69, i32 0, i32 5
  %71 = load i32, ptr %70, align 8, !tbaa !21
  %72 = load i32, ptr %8, align 4, !tbaa !9
  %73 = load i32, ptr %7, align 4, !tbaa !9
  %74 = load i32, ptr %9, align 4, !tbaa !9
  %75 = add nsw i32 %73, %74
  %76 = load ptr, ptr %6, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.TCOD_bsp_t, ptr %76, i32 0, i32 5
  %78 = load i32, ptr %77, align 8, !tbaa !21
  %79 = sub nsw i32 %75, %78
  %80 = load i32, ptr %10, align 4, !tbaa !9
  call void @TCOD_bsp_resize(ptr noundef %68, i32 noundef %71, i32 noundef %72, i32 noundef %79, i32 noundef %80)
  br label %81

81:                                               ; preds = %56, %31
  br label %82

82:                                               ; preds = %81, %5
  ret void
}

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

!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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 24}
!12 = !{!"", !13, i64 0, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !7, i64 44, !14, i64 45}
!13 = !{!"TCOD_tree_t", !6, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!12, !10, i64 28}
!16 = !{!12, !10, i64 32}
!17 = !{!12, !10, i64 36}
!18 = !{!12, !14, i64 45}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!12, !10, i64 40}


; 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 void @TCOD_bsp_resize(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %1, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %2, ptr %7, align 4, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %3, ptr %8, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 %4, ptr %9, align 4, !tbaa !15
  %10 = tail call ptr @TCOD_bsp_left(ptr noundef %0)
  %.not4347 = icmp eq ptr %10, null
  br i1 %.not4347, label %tailrecurse.outer._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %tailrecurse.outer
  %.tr38.ph52 = phi i32 [ %.tr3846, %tailrecurse.outer ], [ %4, %5 ]
  %.tr37.ph51 = phi i32 [ %32, %tailrecurse.outer ], [ %3, %5 ]
  %.tr36.ph50 = phi i32 [ %.tr3645, %tailrecurse.outer ], [ %2, %5 ]
  %.tr35.ph49 = phi i32 [ %30, %tailrecurse.outer ], [ %1, %5 ]
  %.tr.ph48 = phi ptr [ %29, %tailrecurse.outer ], [ %0, %5 ]
  br label %11

11:                                               ; preds = %.lr.ph, %tailrecurse
  %.tr3846 = phi i32 [ %.tr38.ph52, %.lr.ph ], [ %22, %tailrecurse ]
  %.tr3645 = phi i32 [ %.tr36.ph50, %.lr.ph ], [ %20, %tailrecurse ]
  %.tr44 = phi ptr [ %.tr.ph48, %.lr.ph ], [ %19, %tailrecurse ]
  %12 = getelementptr inbounds i8, ptr %.tr44, i64 45
  %13 = load i8, ptr %12, align 1, !tbaa !16, !range !17, !noundef !18
  %14 = trunc nuw i8 %13 to i1
  %15 = tail call ptr @TCOD_bsp_left(ptr noundef nonnull %.tr44)
  %16 = getelementptr inbounds i8, ptr %.tr44, i64 40
  %17 = load i32, ptr %16, align 8, !tbaa !19
  br i1 %14, label %tailrecurse, label %tailrecurse.outer

tailrecurse:                                      ; preds = %11
  %18 = sub nsw i32 %17, %.tr3645
  tail call void @TCOD_bsp_resize(ptr noundef %15, i32 noundef %.tr35.ph49, i32 noundef %.tr3645, i32 noundef %.tr37.ph51, i32 noundef %18)
  %19 = tail call ptr @TCOD_bsp_right(ptr noundef nonnull %.tr44)
  %20 = load i32, ptr %16, align 8, !tbaa !19
  %21 = add nsw i32 %.tr3846, %.tr3645
  %22 = sub i32 %21, %20
  %23 = getelementptr inbounds i8, ptr %19, i64 24
  store i32 %.tr35.ph49, ptr %23, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %19, i64 28
  store i32 %20, ptr %24, align 4, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %19, i64 32
  store i32 %.tr37.ph51, ptr %25, align 8, !tbaa !14
  %26 = getelementptr inbounds i8, ptr %19, i64 36
  store i32 %22, ptr %26, align 4, !tbaa !15
  %27 = tail call ptr @TCOD_bsp_left(ptr noundef %19)
  %.not = icmp eq ptr %27, null
  br i1 %.not, label %tailrecurse.outer._crit_edge, label %11

tailrecurse.outer:                                ; preds = %11
  %28 = sub nsw i32 %17, %.tr35.ph49
  tail call void @TCOD_bsp_resize(ptr noundef %15, i32 noundef %.tr35.ph49, i32 noundef %.tr3645, i32 noundef %28, i32 noundef %.tr3846)
  %29 = tail call ptr @TCOD_bsp_right(ptr noundef nonnull %.tr44)
  %30 = load i32, ptr %16, align 8, !tbaa !19
  %31 = add nsw i32 %.tr37.ph51, %.tr35.ph49
  %32 = sub i32 %31, %30
  %33 = getelementptr inbounds i8, ptr %29, i64 24
  store i32 %30, ptr %33, align 8, !tbaa !5
  %34 = getelementptr inbounds i8, ptr %29, i64 28
  store i32 %.tr3645, ptr %34, align 4, !tbaa !13
  %35 = getelementptr inbounds i8, ptr %29, i64 32
  store i32 %32, ptr %35, align 8, !tbaa !14
  %36 = getelementptr inbounds i8, ptr %29, i64 36
  store i32 %.tr3846, ptr %36, align 4, !tbaa !15
  %37 = tail call ptr @TCOD_bsp_left(ptr noundef %29)
  %.not43 = icmp eq ptr %37, null
  br i1 %.not43, label %tailrecurse.outer._crit_edge, label %.lr.ph

tailrecurse.outer._crit_edge:                     ; preds = %tailrecurse.outer, %tailrecurse, %5
  ret void
}

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

!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, !11, i64 24}
!6 = !{!"", !7, i64 0, !11, i64 24, !11, i64 28, !11, i64 32, !11, i64 36, !11, i64 40, !9, i64 44, !12, i64 45}
!7 = !{!"TCOD_tree_t", !8, i64 0, !8, i64 8, !8, i64 16}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!"_Bool", !9, i64 0}
!13 = !{!6, !11, i64 28}
!14 = !{!6, !11, i64 32}
!15 = !{!6, !11, i64 36}
!16 = !{!6, !12, i64 45}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!6, !11, i64 40}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass