; LLVM IR from jdeokkim/ferox :: src (world)

; 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.stbds_string_arena = type { ptr, i64, i8, i8 }
%struct.stbds_string_block = type { ptr, [8 x i8] }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #1

; 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
define dso_local ptr @stbds_stralloc(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #5
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = call i64 @strlen(ptr noundef %12) #6
  %14 = add i64 %13, 1
  store i64 %14, ptr %7, align 8, !tbaa !9
  %15 = load i64, ptr %7, align 8, !tbaa !9
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.stbds_string_arena, ptr %16, i32 0, i32 1
  %18 = load i64, ptr %17, align 8, !tbaa !11
  %19 = icmp ugt i64 %15, %18
  br i1 %19, label %20, label %96

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #5
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.stbds_string_arena, ptr %21, i32 0, i32 2
  %23 = load i8, ptr %22, align 8, !tbaa !13
  %24 = zext i8 %23 to i64
  store i64 %24, ptr %8, align 8, !tbaa !9
  %25 = load i64, ptr %8, align 8, !tbaa !9
  %26 = lshr i64 %25, 1
  %27 = shl i64 512, %26
  store i64 %27, ptr %8, align 8, !tbaa !9
  %28 = load i64, ptr %8, align 8, !tbaa !9
  %29 = icmp ult i64 %28, 1048576
  br i1 %29, label %30, label %35

30:                                               ; preds = %20
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.stbds_string_arena, ptr %31, i32 0, i32 2
  %33 = load i8, ptr %32, align 8, !tbaa !13
  %34 = add i8 %33, 1
  store i8 %34, ptr %32, align 8, !tbaa !13
  br label %35

35:                                               ; preds = %30, %20
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = load i64, ptr %8, align 8, !tbaa !9
  %38 = icmp ugt i64 %36, %37
  br i1 %38, label %39, label %77

39:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = add i64 8, %40
  %42 = call ptr @realloc(ptr noundef null, i64 noundef %41) #7
  store ptr %42, ptr %9, align 8, !tbaa !5
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.stbds_string_block, ptr %43, i32 0, i32 1
  %45 = getelementptr inbounds [8 x i8], ptr %44, i64 0, i64 0
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memmove.p0.p0.i64(ptr align 8 %45, ptr align 1 %46, i64 %47, i1 false)
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.stbds_string_arena, ptr %48, i32 0, i32 0
  %50 = load ptr, ptr %49, align 8, !tbaa !14
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %65

52:                                               ; preds = %39
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.stbds_string_arena, ptr %53, i32 0, i32 0
  %55 = load ptr, ptr %54, align 8, !tbaa !14
  %56 = getelementptr inbounds %struct.stbds_string_block, ptr %55, i32 0, i32 0
  %57 = load ptr, ptr %56, align 8, !tbaa !15
  %58 = load ptr, ptr %9, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.stbds_string_block, ptr %58, i32 0, i32 0
  store ptr %57, ptr %59, align 8, !tbaa !15
  %60 = load ptr, ptr %9, align 8, !tbaa !5
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.stbds_string_arena, ptr %61, i32 0, i32 0
  %63 = load ptr, ptr %62, align 8, !tbaa !14
  %64 = getelementptr inbounds %struct.stbds_string_block, ptr %63, i32 0, i32 0
  store ptr %60, ptr %64, align 8, !tbaa !15
  br label %73

65:                                               ; preds = %39
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.stbds_string_block, ptr %66, i32 0, i32 0
  store ptr null, ptr %67, align 8, !tbaa !15
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.stbds_string_arena, ptr %69, i32 0, i32 0
  store ptr %68, ptr %70, align 8, !tbaa !14
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.stbds_string_arena, ptr %71, i32 0, i32 1
  store i64 0, ptr %72, align 8, !tbaa !11
  br label %73

73:                                               ; preds = %65, %52
  %74 = load ptr, ptr %9, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.stbds_string_block, ptr %74, i32 0, i32 1
  %76 = getelementptr inbounds [8 x i8], ptr %75, i64 0, i64 0
  store ptr %76, ptr %3, align 8
  store i32 1, ptr %10, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  br label %93

77:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #5
  %78 = load i64, ptr %8, align 8, !tbaa !9
  %79 = add i64 8, %78
  %80 = call ptr @realloc(ptr noundef null, i64 noundef %79) #7
  store ptr %80, ptr %11, align 8, !tbaa !5
  %81 = load ptr, ptr %4, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.stbds_string_arena, ptr %81, i32 0, i32 0
  %83 = load ptr, ptr %82, align 8, !tbaa !14
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.stbds_string_block, ptr %84, i32 0, i32 0
  store ptr %83, ptr %85, align 8, !tbaa !15
  %86 = load ptr, ptr %11, align 8, !tbaa !5
  %87 = load ptr, ptr %4, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.stbds_string_arena, ptr %87, i32 0, i32 0
  store ptr %86, ptr %88, align 8, !tbaa !14
  %89 = load i64, ptr %8, align 8, !tbaa !9
  %90 = load ptr, ptr %4, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.stbds_string_arena, ptr %90, i32 0, i32 1
  store i64 %89, ptr %91, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #5
  br label %92

92:                                               ; preds = %77
  store i32 0, ptr %10, align 4
  br label %93

93:                                               ; preds = %92, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %94 = load i32, ptr %10, align 4
  switch i32 %94, label %118 [
    i32 0, label %95
  ]

95:                                               ; preds = %93
  br label %96

96:                                               ; preds = %95, %2
  %97 = load ptr, ptr %4, align 8, !tbaa !5
  %98 = getelementptr inbounds %struct.stbds_string_arena, ptr %97, i32 0, i32 0
  %99 = load ptr, ptr %98, align 8, !tbaa !14
  %100 = getelementptr inbounds %struct.stbds_string_block, ptr %99, i32 0, i32 1
  %101 = getelementptr inbounds [8 x i8], ptr %100, i64 0, i64 0
  %102 = load ptr, ptr %4, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.stbds_string_arena, ptr %102, i32 0, i32 1
  %104 = load i64, ptr %103, align 8, !tbaa !11
  %105 = getelementptr inbounds i8, ptr %101, i64 %104
  %106 = load i64, ptr %7, align 8, !tbaa !9
  %107 = sub i64 0, %106
  %108 = getelementptr inbounds i8, ptr %105, i64 %107
  store ptr %108, ptr %6, align 8, !tbaa !5
  %109 = load i64, ptr %7, align 8, !tbaa !9
  %110 = load ptr, ptr %4, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.stbds_string_arena, ptr %110, i32 0, i32 1
  %112 = load i64, ptr %111, align 8, !tbaa !11
  %113 = sub i64 %112, %109
  store i64 %113, ptr %111, align 8, !tbaa !11
  %114 = load ptr, ptr %6, align 8, !tbaa !5
  %115 = load ptr, ptr %5, align 8, !tbaa !5
  %116 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.memmove.p0.p0.i64(ptr align 1 %114, ptr align 1 %115, i64 %116, i1 false)
  %117 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %117, ptr %3, align 8
  store i32 1, ptr %10, align 4
  br label %118

118:                                              ; preds = %96, %93
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #5
  %119 = load ptr, ptr %3, align 8
  ret ptr %119
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { nounwind willreturn memory(read) "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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { nounwind allocsize(1) }

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"stbds_string_arena", !6, i64 0, !10, i64 8, !7, i64 16, !7, i64 17}
!13 = !{!12, !7, i64 16}
!14 = !{!12, !6, i64 0}
!15 = !{!16, !6, i64 0}
!16 = !{!"stbds_string_block", !6, i64 0, !7, i64 8}


; 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 nofree nounwind willreturn uwtable
define dso_local nonnull ptr @stbds_stralloc(ptr nocapture noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  %3 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #5
  %4 = add i64 %3, 1
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = load i64, ptr %5, align 8, !tbaa !5
  %7 = icmp ugt i64 %4, %6
  br i1 %7, label %8, label %._crit_edge

._crit_edge:                                      ; preds = %2
  %.pre = load ptr, ptr %0, align 8, !tbaa !11
  br label %28

8:                                                ; preds = %2
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  %10 = load i8, ptr %9, align 8, !tbaa !12
  %11 = lshr i8 %10, 1
  %12 = zext nneg i8 %11 to i64
  %13 = shl i64 512, %12
  %14 = icmp ult i64 %13, 1048576
  br i1 %14, label %15, label %17

15:                                               ; preds = %8
  %16 = add i8 %10, 1
  store i8 %16, ptr %9, align 8, !tbaa !12
  br label %17

17:                                               ; preds = %15, %8
  %.not45 = icmp ugt i64 %4, %13
  br i1 %.not45, label %18, label %25

18:                                               ; preds = %17
  %19 = add i64 %3, 9
  %malloc44 = tail call ptr @malloc(i64 %19)
  %20 = getelementptr inbounds i8, ptr %malloc44, i64 8
  tail call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 8 %20, ptr align 1 %1, i64 %4, i1 false)
  %21 = load ptr, ptr %0, align 8, !tbaa !11
  %.not = icmp eq ptr %21, null
  br i1 %.not, label %24, label %22

22:                                               ; preds = %18
  %23 = load ptr, ptr %21, align 8, !tbaa !13
  store ptr %23, ptr %malloc44, align 8, !tbaa !13
  store ptr %malloc44, ptr %21, align 8, !tbaa !13
  br label %.thread

24:                                               ; preds = %18
  store ptr null, ptr %malloc44, align 8, !tbaa !13
  store ptr %malloc44, ptr %0, align 8, !tbaa !11
  store i64 0, ptr %5, align 8, !tbaa !5
  br label %.thread

25:                                               ; preds = %17
  %26 = or disjoint i64 %13, 8
  %malloc = tail call ptr @malloc(i64 %26)
  %27 = load ptr, ptr %0, align 8, !tbaa !11
  store ptr %27, ptr %malloc, align 8, !tbaa !13
  store ptr %malloc, ptr %0, align 8, !tbaa !11
  br label %28

28:                                               ; preds = %._crit_edge, %25
  %29 = phi i64 [ %6, %._crit_edge ], [ %13, %25 ]
  %30 = phi ptr [ %.pre, %._crit_edge ], [ %malloc, %25 ]
  %31 = getelementptr inbounds i8, ptr %30, i64 8
  %32 = getelementptr inbounds i8, ptr %31, i64 %29
  %33 = xor i64 %3, -1
  %34 = getelementptr inbounds i8, ptr %32, i64 %33
  %35 = sub i64 %29, %4
  store i64 %35, ptr %5, align 8, !tbaa !5
  tail call void @llvm.memmove.p0.p0.i64(ptr nonnull align 1 %34, ptr align 1 %1, i64 %4, i1 false)
  br label %.thread

.thread:                                          ; preds = %24, %22, %28
  %.1 = phi ptr [ %34, %28 ], [ %20, %22 ], [ %20, %24 ]
  ret ptr %.1
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memmove.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

attributes #0 = { mustprogress nofree nounwind willreturn 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 nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 = { nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind willreturn memory(read) }

!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, !10, i64 8}
!6 = !{!"stbds_string_arena", !7, i64 0, !10, i64 8, !8, i64 16, !8, i64 17}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !8, i64 16}
!13 = !{!14, !7, i64 0}
!14 = !{!"stbds_string_block", !7, i64 0, !8, i64 8}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass