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

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

@_ZTV7TCODBsp = external dso_local unnamed_addr constant { [4 x ptr] }, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7TCODBspC2EPS_b(ptr noundef nonnull align 8 dereferenceable(54) %0, ptr noundef %1, i1 noundef zeroext %2) unnamed_addr #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %7 = zext i1 %2 to i8
  store i8 %7, ptr %6, align 1, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  %9 = getelementptr inbounds i8, ptr %8, i64 8
  call void @_ZN8TCODTreeC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %9) #1
  store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTV7TCODBsp, i32 0, i32 0, i32 2), ptr %8, align 8, !tbaa !11
  %10 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 2
  store i32 0, ptr %10, align 8, !tbaa !13
  %11 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 3
  store i32 0, ptr %11, align 4, !tbaa !17
  %12 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 4
  store i32 0, ptr %12, align 8, !tbaa !18
  %13 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 5
  store i32 0, ptr %13, align 4, !tbaa !19
  %14 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 6
  store i32 0, ptr %14, align 8, !tbaa !20
  %15 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 7
  store i8 0, ptr %15, align 4, !tbaa !21
  %16 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 8
  store i8 0, ptr %16, align 1, !tbaa !22
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.TCODBsp, ptr %17, i32 0, i32 7
  %19 = load i8, ptr %18, align 4, !tbaa !21, !range !23, !noundef !24
  %20 = trunc i8 %19 to i1
  br i1 %20, label %21, label %67

21:                                               ; preds = %3
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %class.TCODBsp, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !13
  %25 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 2
  store i32 %24, ptr %25, align 8, !tbaa !13
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = getelementptr inbounds %class.TCODBsp, ptr %26, i32 0, i32 4
  %28 = load i32, ptr %27, align 8, !tbaa !18
  %29 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 4
  store i32 %28, ptr %29, align 8, !tbaa !18
  %30 = load i8, ptr %6, align 1, !tbaa !9, !range !23, !noundef !24
  %31 = trunc i8 %30 to i1
  br i1 %31, label %32, label %36

32:                                               ; preds = %21
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %class.TCODBsp, ptr %33, i32 0, i32 3
  %35 = load i32, ptr %34, align 4, !tbaa !17
  br label %40

36:                                               ; preds = %21
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %class.TCODBsp, ptr %37, i32 0, i32 6
  %39 = load i32, ptr %38, align 8, !tbaa !20
  br label %40

40:                                               ; preds = %36, %32
  %41 = phi i32 [ %35, %32 ], [ %39, %36 ]
  %42 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 3
  store i32 %41, ptr %42, align 4, !tbaa !17
  %43 = load i8, ptr %6, align 1, !tbaa !9, !range !23, !noundef !24
  %44 = trunc i8 %43 to i1
  br i1 %44, label %45, label %52

45:                                               ; preds = %40
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %class.TCODBsp, ptr %46, i32 0, i32 6
  %48 = load i32, ptr %47, align 8, !tbaa !20
  %49 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 3
  %50 = load i32, ptr %49, align 4, !tbaa !17
  %51 = sub nsw i32 %48, %50
  br label %64

52:                                               ; preds = %40
  %53 = load ptr, ptr %5, align 8, !tbaa !5
  %54 = getelementptr inbounds %class.TCODBsp, ptr %53, i32 0, i32 3
  %55 = load i32, ptr %54, align 4, !tbaa !17
  %56 = load ptr, ptr %5, align 8, !tbaa !5
  %57 = getelementptr inbounds %class.TCODBsp, ptr %56, i32 0, i32 5
  %58 = load i32, ptr %57, align 4, !tbaa !19
  %59 = add nsw i32 %55, %58
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = getelementptr inbounds %class.TCODBsp, ptr %60, i32 0, i32 6
  %62 = load i32, ptr %61, align 8, !tbaa !20
  %63 = sub nsw i32 %59, %62
  br label %64

64:                                               ; preds = %52, %45
  %65 = phi i32 [ %51, %45 ], [ %63, %52 ]
  %66 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 5
  store i32 %65, ptr %66, align 4, !tbaa !19
  br label %113

67:                                               ; preds = %3
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %class.TCODBsp, ptr %68, i32 0, i32 3
  %70 = load i32, ptr %69, align 4, !tbaa !17
  %71 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 3
  store i32 %70, ptr %71, align 4, !tbaa !17
  %72 = load ptr, ptr %5, align 8, !tbaa !5
  %73 = getelementptr inbounds %class.TCODBsp, ptr %72, i32 0, i32 5
  %74 = load i32, ptr %73, align 4, !tbaa !19
  %75 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 5
  store i32 %74, ptr %75, align 4, !tbaa !19
  %76 = load i8, ptr %6, align 1, !tbaa !9, !range !23, !noundef !24
  %77 = trunc i8 %76 to i1
  br i1 %77, label %78, label %82

78:                                               ; preds = %67
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = getelementptr inbounds %class.TCODBsp, ptr %79, i32 0, i32 2
  %81 = load i32, ptr %80, align 8, !tbaa !13
  br label %86

82:                                               ; preds = %67
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  %84 = getelementptr inbounds %class.TCODBsp, ptr %83, i32 0, i32 6
  %85 = load i32, ptr %84, align 8, !tbaa !20
  br label %86

86:                                               ; preds = %82, %78
  %87 = phi i32 [ %81, %78 ], [ %85, %82 ]
  %88 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 2
  store i32 %87, ptr %88, align 8, !tbaa !13
  %89 = load i8, ptr %6, align 1, !tbaa !9, !range !23, !noundef !24
  %90 = trunc i8 %89 to i1
  br i1 %90, label %91, label %98

91:                                               ; preds = %86
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %class.TCODBsp, ptr %92, i32 0, i32 6
  %94 = load i32, ptr %93, align 8, !tbaa !20
  %95 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 2
  %96 = load i32, ptr %95, align 8, !tbaa !13
  %97 = sub nsw i32 %94, %96
  br label %110

98:                                               ; preds = %86
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %class.TCODBsp, ptr %99, i32 0, i32 2
  %101 = load i32, ptr %100, align 8, !tbaa !13
  %102 = load ptr, ptr %5, align 8, !tbaa !5
  %103 = getelementptr inbounds %class.TCODBsp, ptr %102, i32 0, i32 4
  %104 = load i32, ptr %103, align 8, !tbaa !18
  %105 = add nsw i32 %101, %104
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = getelementptr inbounds %class.TCODBsp, ptr %106, i32 0, i32 6
  %108 = load i32, ptr %107, align 8, !tbaa !20
  %109 = sub nsw i32 %105, %108
  br label %110

110:                                              ; preds = %98, %91
  %111 = phi i32 [ %97, %91 ], [ %109, %98 ]
  %112 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 4
  store i32 %111, ptr %112, align 8, !tbaa !18
  br label %113

113:                                              ; preds = %110, %64
  %114 = load ptr, ptr %5, align 8, !tbaa !5
  %115 = getelementptr inbounds %class.TCODBsp, ptr %114, i32 0, i32 8
  %116 = load i8, ptr %115, align 1, !tbaa !22
  %117 = zext i8 %116 to i32
  %118 = add nsw i32 %117, 1
  %119 = trunc i32 %118 to i8
  %120 = getelementptr inbounds %class.TCODBsp, ptr %8, i32 0, i32 8
  store i8 %119, ptr %120, align 1, !tbaa !22
  ret void
}

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

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


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

@_ZTV7TCODBsp = external dso_local unnamed_addr constant { [4 x ptr] }, align 8

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN7TCODBspC2EPS_b(ptr noundef nonnull align 8 dereferenceable(54) %0, ptr nocapture noundef readonly %1, i1 noundef zeroext %2) unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  tail call void @_ZN8TCODTreeC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %4) #2
  store ptr getelementptr inbounds inrange(-16, 16) (i8, ptr @_ZTV7TCODBsp, i64 16), ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  %6 = getelementptr inbounds i8, ptr %0, i64 36
  %7 = getelementptr inbounds i8, ptr %0, i64 40
  %8 = getelementptr inbounds i8, ptr %0, i64 44
  %9 = getelementptr inbounds i8, ptr %1, i64 52
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(22) %5, i8 0, i64 22, i1 false)
  %10 = load i8, ptr %9, align 4, !tbaa !8, !range !15, !noundef !16
  %11 = trunc nuw i8 %10 to i1
  %12 = getelementptr inbounds i8, ptr %1, i64 48
  br i1 %11, label %13, label %32

13:                                               ; preds = %3
  %14 = getelementptr inbounds i8, ptr %1, i64 32
  %15 = load i32, ptr %14, align 8, !tbaa !17
  store i32 %15, ptr %5, align 8, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %1, i64 40
  %17 = load i32, ptr %16, align 8, !tbaa !18
  store i32 %17, ptr %7, align 8, !tbaa !18
  %18 = getelementptr inbounds i8, ptr %1, i64 36
  %.in22 = select i1 %2, ptr %18, ptr %12
  %19 = load i32, ptr %.in22, align 4, !tbaa !19
  store i32 %19, ptr %6, align 4, !tbaa !20
  br i1 %2, label %20, label %23

20:                                               ; preds = %13
  %21 = load i32, ptr %12, align 8, !tbaa !21
  %22 = sub nsw i32 %21, %19
  br label %30

23:                                               ; preds = %13
  %24 = load i32, ptr %18, align 4, !tbaa !20
  %25 = getelementptr inbounds i8, ptr %1, i64 44
  %26 = load i32, ptr %25, align 4, !tbaa !22
  %27 = add nsw i32 %26, %24
  %28 = load i32, ptr %12, align 8, !tbaa !21
  %29 = sub i32 %27, %28
  br label %30

30:                                               ; preds = %23, %20
  %31 = phi i32 [ %22, %20 ], [ %29, %23 ]
  store i32 %31, ptr %8, align 4, !tbaa !22
  br label %51

32:                                               ; preds = %3
  %33 = getelementptr inbounds i8, ptr %1, i64 36
  %34 = load i32, ptr %33, align 4, !tbaa !20
  store i32 %34, ptr %6, align 4, !tbaa !20
  %35 = getelementptr inbounds i8, ptr %1, i64 44
  %36 = load i32, ptr %35, align 4, !tbaa !22
  store i32 %36, ptr %8, align 4, !tbaa !22
  %37 = getelementptr inbounds i8, ptr %1, i64 32
  %.in = select i1 %2, ptr %37, ptr %12
  %38 = load i32, ptr %.in, align 8, !tbaa !19
  store i32 %38, ptr %5, align 8, !tbaa !17
  br i1 %2, label %39, label %42

39:                                               ; preds = %32
  %40 = load i32, ptr %12, align 8, !tbaa !21
  %41 = sub nsw i32 %40, %38
  br label %49

42:                                               ; preds = %32
  %43 = load i32, ptr %37, align 8, !tbaa !17
  %44 = getelementptr inbounds i8, ptr %1, i64 40
  %45 = load i32, ptr %44, align 8, !tbaa !18
  %46 = add nsw i32 %45, %43
  %47 = load i32, ptr %12, align 8, !tbaa !21
  %48 = sub i32 %46, %47
  br label %49

49:                                               ; preds = %42, %39
  %50 = phi i32 [ %41, %39 ], [ %48, %42 ]
  store i32 %50, ptr %7, align 8, !tbaa !18
  br label %51

51:                                               ; preds = %49, %30
  %52 = getelementptr inbounds i8, ptr %0, i64 53
  %53 = getelementptr inbounds i8, ptr %1, i64 53
  %54 = load i8, ptr %53, align 1, !tbaa !23
  %55 = add i8 %54, 1
  store i8 %55, ptr %52, align 1, !tbaa !23
  ret void
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = !{!6, !6, i64 0}
!6 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !14, i64 52}
!9 = !{!"_ZTS7TCODBsp", !10, i64 8, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !13, i64 48, !14, i64 52, !12, i64 53}
!10 = !{!"_ZTS8TCODTree", !11, i64 0, !11, i64 8, !11, i64 16}
!11 = !{!"any pointer", !12, i64 0}
!12 = !{!"omnipotent char", !7, i64 0}
!13 = !{!"int", !12, i64 0}
!14 = !{!"bool", !12, i64 0}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!9, !13, i64 32}
!18 = !{!9, !13, i64 40}
!19 = !{!13, !13, i64 0}
!20 = !{!9, !13, i64 36}
!21 = !{!9, !13, i64 48}
!22 = !{!9, !13, i64 44}
!23 = !{!9, !12, i64 53}


; Effective O3 passes: EarlyCSEPass,IPSCCPPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass