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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7TCODBsp7getLeftEv(ptr noundef nonnull align 8 dereferenceable(54)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7TCODBsp8getRightEv(ptr noundef nonnull align 8 dereferenceable(54)) #0 align 2

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN7TCODBsp6resizeEiiii(ptr noundef nonnull align 8 dereferenceable(54) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) #1 align 2 {
  %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 ptr, ptr %6, align 8
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 2
  store i32 %12, ptr %13, align 8, !tbaa !11
  %14 = load i32, ptr %8, align 4, !tbaa !9
  %15 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 3
  store i32 %14, ptr %15, align 4, !tbaa !15
  %16 = load i32, ptr %9, align 4, !tbaa !9
  %17 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 4
  store i32 %16, ptr %17, align 8, !tbaa !16
  %18 = load i32, ptr %10, align 4, !tbaa !9
  %19 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 5
  store i32 %18, ptr %19, align 4, !tbaa !17
  %20 = call noundef ptr @_ZNK7TCODBsp7getLeftEv(ptr noundef nonnull align 8 dereferenceable(54) %11)
  %21 = icmp ne ptr %20, null
  br i1 %21, label %22, label %83

22:                                               ; preds = %5
  %23 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 7
  %24 = load i8, ptr %23, align 4, !tbaa !18, !range !19, !noundef !20
  %25 = trunc i8 %24 to i1
  br i1 %25, label %26, label %54

26:                                               ; preds = %22
  %27 = call noundef ptr @_ZNK7TCODBsp7getLeftEv(ptr noundef nonnull align 8 dereferenceable(54) %11)
  %28 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 2
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 3
  %31 = load i32, ptr %30, align 4, !tbaa !15
  %32 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 4
  %33 = load i32, ptr %32, align 8, !tbaa !16
  %34 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 6
  %35 = load i32, ptr %34, align 8, !tbaa !21
  %36 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 3
  %37 = load i32, ptr %36, align 4, !tbaa !15
  %38 = sub nsw i32 %35, %37
  call void @_ZN7TCODBsp6resizeEiiii(ptr noundef nonnull align 8 dereferenceable(54) %27, i32 noundef %29, i32 noundef %31, i32 noundef %33, i32 noundef %38)
  %39 = call noundef ptr @_ZNK7TCODBsp8getRightEv(ptr noundef nonnull align 8 dereferenceable(54) %11)
  %40 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 2
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 6
  %43 = load i32, ptr %42, align 8, !tbaa !21
  %44 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 4
  %45 = load i32, ptr %44, align 8, !tbaa !16
  %46 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 3
  %47 = load i32, ptr %46, align 4, !tbaa !15
  %48 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 5
  %49 = load i32, ptr %48, align 4, !tbaa !17
  %50 = add nsw i32 %47, %49
  %51 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 6
  %52 = load i32, ptr %51, align 8, !tbaa !21
  %53 = sub nsw i32 %50, %52
  call void @_ZN7TCODBsp6resizeEiiii(ptr noundef nonnull align 8 dereferenceable(54) %39, i32 noundef %41, i32 noundef %43, i32 noundef %45, i32 noundef %53)
  br label %82

54:                                               ; preds = %22
  %55 = call noundef ptr @_ZNK7TCODBsp7getLeftEv(ptr noundef nonnull align 8 dereferenceable(54) %11)
  %56 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 2
  %57 = load i32, ptr %56, align 8, !tbaa !11
  %58 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 3
  %59 = load i32, ptr %58, align 4, !tbaa !15
  %60 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 6
  %61 = load i32, ptr %60, align 8, !tbaa !21
  %62 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 2
  %63 = load i32, ptr %62, align 8, !tbaa !11
  %64 = sub nsw i32 %61, %63
  %65 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 5
  %66 = load i32, ptr %65, align 4, !tbaa !17
  call void @_ZN7TCODBsp6resizeEiiii(ptr noundef nonnull align 8 dereferenceable(54) %55, i32 noundef %57, i32 noundef %59, i32 noundef %64, i32 noundef %66)
  %67 = call noundef ptr @_ZNK7TCODBsp8getRightEv(ptr noundef nonnull align 8 dereferenceable(54) %11)
  %68 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 6
  %69 = load i32, ptr %68, align 8, !tbaa !21
  %70 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 3
  %71 = load i32, ptr %70, align 4, !tbaa !15
  %72 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 2
  %73 = load i32, ptr %72, align 8, !tbaa !11
  %74 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 4
  %75 = load i32, ptr %74, align 8, !tbaa !16
  %76 = add nsw i32 %73, %75
  %77 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 6
  %78 = load i32, ptr %77, align 8, !tbaa !21
  %79 = sub nsw i32 %76, %78
  %80 = getelementptr inbounds %class.TCODBsp, ptr %11, i32 0, i32 5
  %81 = load i32, ptr %80, align 4, !tbaa !17
  call void @_ZN7TCODBsp6resizeEiiii(ptr noundef nonnull align 8 dereferenceable(54) %67, i32 noundef %69, i32 noundef %71, i32 noundef %79, i32 noundef %81)
  br label %82

82:                                               ; preds = %54, %26
  br label %83

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

attributes #0 = { 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 #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" }

!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, !10, i64 32}
!12 = !{!"_ZTS7TCODBsp", !13, i64 8, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !10, i64 48, !14, i64 52, !7, i64 53}
!13 = !{!"_ZTS8TCODTree", !6, i64 0, !6, i64 8, !6, i64 16}
!14 = !{!"bool", !7, i64 0}
!15 = !{!12, !10, i64 36}
!16 = !{!12, !10, i64 40}
!17 = !{!12, !10, i64 44}
!18 = !{!12, !14, i64 52}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!12, !10, 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"

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7TCODBsp7getLeftEv(ptr noundef nonnull align 8 dereferenceable(54)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK7TCODBsp8getRightEv(ptr noundef nonnull align 8 dereferenceable(54)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7TCODBsp6resizeEiiii(ptr noundef nonnull align 8 dereferenceable(54) %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i32 noundef %4) local_unnamed_addr #0 align 2 {
  %6 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %1, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 %2, ptr %7, align 4, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 %3, ptr %8, align 8, !tbaa !14
  %9 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 %4, ptr %9, align 4, !tbaa !15
  %10 = tail call noundef ptr @_ZNK7TCODBsp7getLeftEv(ptr noundef nonnull align 8 dereferenceable(54) %0)
  %.not9 = icmp eq ptr %10, null
  br i1 %.not9, label %tailrecurse._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %5, %tailrecurse.backedge
  %11 = phi ptr [ %37, %tailrecurse.backedge ], [ %9, %5 ]
  %12 = phi ptr [ %36, %tailrecurse.backedge ], [ %8, %5 ]
  %13 = phi ptr [ %35, %tailrecurse.backedge ], [ %7, %5 ]
  %14 = phi ptr [ %34, %tailrecurse.backedge ], [ %6, %5 ]
  %.tr10 = phi ptr [ %.tr.be, %tailrecurse.backedge ], [ %0, %5 ]
  %15 = getelementptr inbounds i8, ptr %.tr10, i64 52
  %16 = load i8, ptr %15, align 4, !tbaa !16, !range !17, !noundef !18
  %17 = trunc nuw i8 %16 to i1
  %18 = tail call noundef ptr @_ZNK7TCODBsp7getLeftEv(ptr noundef nonnull align 8 dereferenceable(54) %.tr10)
  %19 = load i32, ptr %14, align 8, !tbaa !5
  %20 = load i32, ptr %13, align 4, !tbaa !13
  br i1 %17, label %21, label %39

21:                                               ; preds = %.lr.ph
  %22 = load i32, ptr %12, align 8, !tbaa !14
  %23 = getelementptr inbounds i8, ptr %.tr10, i64 48
  %24 = load i32, ptr %23, align 8, !tbaa !19
  %25 = sub nsw i32 %24, %20
  tail call void @_ZN7TCODBsp6resizeEiiii(ptr noundef nonnull align 8 dereferenceable(54) %18, i32 noundef %19, i32 noundef %20, i32 noundef %22, i32 noundef %25)
  %26 = tail call noundef ptr @_ZNK7TCODBsp8getRightEv(ptr noundef nonnull align 8 dereferenceable(54) %.tr10)
  %27 = load i32, ptr %14, align 8, !tbaa !5
  %28 = load i32, ptr %23, align 8, !tbaa !19
  %29 = load i32, ptr %12, align 8, !tbaa !14
  %30 = load i32, ptr %13, align 4, !tbaa !13
  %31 = load i32, ptr %11, align 4, !tbaa !15
  %32 = sub i32 %30, %28
  %33 = add i32 %32, %31
  br label %tailrecurse.backedge

tailrecurse.backedge:                             ; preds = %21, %39
  %.tr.be = phi ptr [ %26, %21 ], [ %44, %39 ]
  %.tr4.be = phi i32 [ %27, %21 ], [ %45, %39 ]
  %.tr5.be = phi i32 [ %28, %21 ], [ %46, %39 ]
  %.tr6.be = phi i32 [ %29, %21 ], [ %50, %39 ]
  %.tr7.be = phi i32 [ %33, %21 ], [ %51, %39 ]
  %34 = getelementptr inbounds i8, ptr %.tr.be, i64 32
  store i32 %.tr4.be, ptr %34, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %.tr.be, i64 36
  store i32 %.tr5.be, ptr %35, align 4, !tbaa !13
  %36 = getelementptr inbounds i8, ptr %.tr.be, i64 40
  store i32 %.tr6.be, ptr %36, align 8, !tbaa !14
  %37 = getelementptr inbounds i8, ptr %.tr.be, i64 44
  store i32 %.tr7.be, ptr %37, align 4, !tbaa !15
  %38 = tail call noundef ptr @_ZNK7TCODBsp7getLeftEv(ptr noundef nonnull align 8 dereferenceable(54) %.tr.be)
  %.not = icmp eq ptr %38, null
  br i1 %.not, label %tailrecurse._crit_edge, label %.lr.ph

39:                                               ; preds = %.lr.ph
  %40 = getelementptr inbounds i8, ptr %.tr10, i64 48
  %41 = load i32, ptr %40, align 8, !tbaa !19
  %42 = sub nsw i32 %41, %19
  %43 = load i32, ptr %11, align 4, !tbaa !15
  tail call void @_ZN7TCODBsp6resizeEiiii(ptr noundef nonnull align 8 dereferenceable(54) %18, i32 noundef %19, i32 noundef %20, i32 noundef %42, i32 noundef %43)
  %44 = tail call noundef ptr @_ZNK7TCODBsp8getRightEv(ptr noundef nonnull align 8 dereferenceable(54) %.tr10)
  %45 = load i32, ptr %40, align 8, !tbaa !19
  %46 = load i32, ptr %13, align 4, !tbaa !13
  %47 = load i32, ptr %14, align 8, !tbaa !5
  %48 = load i32, ptr %12, align 8, !tbaa !14
  %49 = sub i32 %47, %45
  %50 = add i32 %49, %48
  %51 = load i32, ptr %11, align 4, !tbaa !15
  br label %tailrecurse.backedge

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

attributes #0 = { 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" }

!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 32}
!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 36}
!14 = !{!6, !11, i64 40}
!15 = !{!6, !11, i64 44}
!16 = !{!6, !12, i64 52}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!6, !11, i64 48}


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