; 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_array_header = type { i64, i64, ptr, i64 }

; Function Attrs: nounwind uwtable
define dso_local ptr @stbds_arrgrowf(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) #0 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca %struct.stbds_array_header, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %10) #4
  call void @llvm.memset.p0.i64(ptr align 8 %10, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %21

16:                                               ; preds = %4
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.stbds_array_header, ptr %17, i64 -1
  %19 = getelementptr inbounds %struct.stbds_array_header, ptr %18, i32 0, i32 0
  %20 = load i64, ptr %19, align 8, !tbaa !11
  br label %22

21:                                               ; preds = %4
  br label %22

22:                                               ; preds = %21, %16
  %23 = phi i64 [ %20, %16 ], [ 0, %21 ]
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = add i64 %23, %24
  store i64 %25, ptr %12, align 8, !tbaa !9
  %26 = load i64, ptr %12, align 8, !tbaa !9
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = icmp ugt i64 %26, %27
  br i1 %28, label %29, label %31

29:                                               ; preds = %22
  %30 = load i64, ptr %12, align 8, !tbaa !9
  store i64 %30, ptr %9, align 8, !tbaa !9
  br label %31

31:                                               ; preds = %29, %22
  %32 = load i64, ptr %9, align 8, !tbaa !9
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %40

35:                                               ; preds = %31
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.stbds_array_header, ptr %36, i64 -1
  %38 = getelementptr inbounds %struct.stbds_array_header, ptr %37, i32 0, i32 1
  %39 = load i64, ptr %38, align 8, !tbaa !13
  br label %41

40:                                               ; preds = %31
  br label %41

41:                                               ; preds = %40, %35
  %42 = phi i64 [ %39, %35 ], [ 0, %40 ]
  %43 = icmp ule i64 %32, %42
  br i1 %43, label %44, label %46

44:                                               ; preds = %41
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %45, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %112

46:                                               ; preds = %41
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = load ptr, ptr %6, align 8, !tbaa !5
  %49 = icmp ne ptr %48, null
  br i1 %49, label %50, label %55

50:                                               ; preds = %46
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.stbds_array_header, ptr %51, i64 -1
  %53 = getelementptr inbounds %struct.stbds_array_header, ptr %52, i32 0, i32 1
  %54 = load i64, ptr %53, align 8, !tbaa !13
  br label %56

55:                                               ; preds = %46
  br label %56

56:                                               ; preds = %55, %50
  %57 = phi i64 [ %54, %50 ], [ 0, %55 ]
  %58 = mul i64 2, %57
  %59 = icmp ult i64 %47, %58
  br i1 %59, label %60, label %72

60:                                               ; preds = %56
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = icmp ne ptr %61, null
  br i1 %62, label %63, label %68

63:                                               ; preds = %60
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.stbds_array_header, ptr %64, i64 -1
  %66 = getelementptr inbounds %struct.stbds_array_header, ptr %65, i32 0, i32 1
  %67 = load i64, ptr %66, align 8, !tbaa !13
  br label %69

68:                                               ; preds = %60
  br label %69

69:                                               ; preds = %68, %63
  %70 = phi i64 [ %67, %63 ], [ 0, %68 ]
  %71 = mul i64 2, %70
  store i64 %71, ptr %9, align 8, !tbaa !9
  br label %77

72:                                               ; preds = %56
  %73 = load i64, ptr %9, align 8, !tbaa !9
  %74 = icmp ult i64 %73, 4
  br i1 %74, label %75, label %76

75:                                               ; preds = %72
  store i64 4, ptr %9, align 8, !tbaa !9
  br label %76

76:                                               ; preds = %75, %72
  br label %77

77:                                               ; preds = %76, %69
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = icmp ne ptr %78, null
  br i1 %79, label %80, label %83

80:                                               ; preds = %77
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.stbds_array_header, ptr %81, i64 -1
  br label %84

83:                                               ; preds = %77
  br label %84

84:                                               ; preds = %83, %80
  %85 = phi ptr [ %82, %80 ], [ null, %83 ]
  %86 = load i64, ptr %7, align 8, !tbaa !9
  %87 = load i64, ptr %9, align 8, !tbaa !9
  %88 = mul i64 %86, %87
  %89 = add i64 %88, 32
  %90 = call ptr @realloc(ptr noundef %85, i64 noundef %89) #5
  store ptr %90, ptr %11, align 8, !tbaa !5
  %91 = load ptr, ptr %11, align 8, !tbaa !5
  %92 = getelementptr inbounds i8, ptr %91, i64 32
  store ptr %92, ptr %11, align 8, !tbaa !5
  %93 = load ptr, ptr %6, align 8, !tbaa !5
  %94 = icmp eq ptr %93, null
  br i1 %94, label %95, label %105

95:                                               ; preds = %84
  %96 = load ptr, ptr %11, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.stbds_array_header, ptr %96, i64 -1
  %98 = getelementptr inbounds %struct.stbds_array_header, ptr %97, i32 0, i32 0
  store i64 0, ptr %98, align 8, !tbaa !11
  %99 = load ptr, ptr %11, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.stbds_array_header, ptr %99, i64 -1
  %101 = getelementptr inbounds %struct.stbds_array_header, ptr %100, i32 0, i32 2
  store ptr null, ptr %101, align 8, !tbaa !14
  %102 = load ptr, ptr %11, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.stbds_array_header, ptr %102, i64 -1
  %104 = getelementptr inbounds %struct.stbds_array_header, ptr %103, i32 0, i32 3
  store i64 0, ptr %104, align 8, !tbaa !15
  br label %106

105:                                              ; preds = %84
  br label %106

106:                                              ; preds = %105, %95
  %107 = load i64, ptr %9, align 8, !tbaa !9
  %108 = load ptr, ptr %11, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.stbds_array_header, ptr %108, i64 -1
  %110 = getelementptr inbounds %struct.stbds_array_header, ptr %109, i32 0, i32 1
  store i64 %107, ptr %110, align 8, !tbaa !13
  %111 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %111, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %112

112:                                              ; preds = %106, %44
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %10) #4
  %113 = load ptr, ptr %5, align 8
  ret ptr %113
}

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { nounwind }
attributes #5 = { 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 0}
!12 = !{!"", !10, i64 0, !10, i64 8, !6, i64 16, !10, i64 24}
!13 = !{!12, !10, i64 8}
!14 = !{!12, !6, i64 16}
!15 = !{!12, !10, i64 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"

; Function Attrs: mustprogress nounwind willreturn uwtable
define dso_local ptr @stbds_arrgrowf(ptr noundef %0, i64 noundef %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %.thread36

5:                                                ; preds = %4
  %spec.select34 = tail call i64 @llvm.umax.i64(i64 %2, i64 %3)
  %.not33.not = icmp eq i64 %spec.select34, 0
  br i1 %.not33.not, label %24, label %.thread44

.thread36:                                        ; preds = %4
  %6 = getelementptr inbounds i8, ptr %0, i64 -32
  %7 = load i64, ptr %6, align 8, !tbaa !5
  %8 = add i64 %7, %2
  %spec.select = tail call i64 @llvm.umax.i64(i64 %8, i64 %3)
  %9 = getelementptr inbounds i8, ptr %0, i64 -24
  %10 = load i64, ptr %9, align 8, !tbaa !11
  %.not3338 = icmp ugt i64 %spec.select, %10
  br i1 %.not3338, label %.thread40, label %24

.thread40:                                        ; preds = %.thread36
  %11 = shl i64 %10, 1
  %12 = icmp ult i64 %spec.select, %11
  br i1 %12, label %13, label %.thread44

.thread44:                                        ; preds = %5, %.thread40
  %spec.select35394346 = phi i64 [ %spec.select, %.thread40 ], [ %spec.select34, %5 ]
  %spec.store.select = tail call i64 @llvm.umax.i64(i64 %spec.select35394346, i64 4)
  br label %13

13:                                               ; preds = %.thread40, %.thread44
  %.1 = phi i64 [ %spec.store.select, %.thread44 ], [ %11, %.thread40 ]
  %14 = getelementptr inbounds i8, ptr %0, i64 -32
  %15 = select i1 %.not, ptr null, ptr %14
  %16 = mul i64 %.1, %1
  %17 = add i64 %16, 32
  %18 = tail call ptr @realloc(ptr noundef %15, i64 noundef %17) #4
  %19 = getelementptr inbounds i8, ptr %18, i64 32
  br i1 %.not, label %20, label %22

20:                                               ; preds = %13
  store i64 0, ptr %18, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %18, i64 16
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %21, i8 0, i64 16, i1 false)
  br label %22

22:                                               ; preds = %13, %20
  %23 = getelementptr inbounds i8, ptr %18, i64 8
  store i64 %.1, ptr %23, align 8, !tbaa !11
  br label %24

24:                                               ; preds = %.thread36, %5, %22
  %.0 = phi ptr [ %19, %22 ], [ null, %5 ], [ %0, %.thread36 ]
  ret ptr %.0
}

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

; Function Attrs: mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite)
declare noalias noundef ptr @realloc(ptr allocptr nocapture noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #3

attributes #0 = { mustprogress 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: write) }
attributes #2 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 8}


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