; LLVM IR from ssvb/tinymembench :: util (alloc_four_nonaliased_buffers)

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

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

; 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 @alloc_four_nonaliased_buffers(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef %4, i32 noundef %5, ptr noundef %6, i32 noundef %7) #1 {
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i32, align 4
  %22 = alloca ptr, align 8
  %23 = alloca ptr, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !9
  store ptr %2, ptr %11, align 8, !tbaa !5
  store i32 %3, ptr %12, align 4, !tbaa !9
  store ptr %4, ptr %13, align 8, !tbaa !5
  store i32 %5, ptr %14, align 4, !tbaa !9
  store ptr %6, ptr %15, align 8, !tbaa !5
  store i32 %7, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #4
  %24 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %24, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %25 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %25, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %26 = load ptr, ptr %13, align 8, !tbaa !5
  store ptr %26, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %27 = load ptr, ptr %15, align 8, !tbaa !5
  store ptr %27, ptr %20, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #4
  store i32 1048448, ptr %21, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #4
  %28 = load ptr, ptr %17, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %30, label %33

30:                                               ; preds = %8
  %31 = load i32, ptr %10, align 4, !tbaa !9
  %32 = icmp slt i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %30, %8
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %33, %30
  %35 = load ptr, ptr %18, align 8, !tbaa !5
  %36 = icmp ne ptr %35, null
  br i1 %36, label %37, label %40

37:                                               ; preds = %34
  %38 = load i32, ptr %12, align 4, !tbaa !9
  %39 = icmp slt i32 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %37, %34
  store i32 0, ptr %12, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %40, %37
  %42 = load ptr, ptr %19, align 8, !tbaa !5
  %43 = icmp ne ptr %42, null
  br i1 %43, label %44, label %47

44:                                               ; preds = %41
  %45 = load i32, ptr %14, align 4, !tbaa !9
  %46 = icmp slt i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %44, %41
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %47, %44
  %49 = load ptr, ptr %20, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %54

51:                                               ; preds = %48
  %52 = load i32, ptr %16, align 4, !tbaa !9
  %53 = icmp slt i32 %52, 0
  br i1 %53, label %54, label %55

54:                                               ; preds = %51, %48
  store i32 0, ptr %16, align 4, !tbaa !9
  br label %55

55:                                               ; preds = %54, %51
  %56 = load i32, ptr %10, align 4, !tbaa !9
  %57 = load i32, ptr %12, align 4, !tbaa !9
  %58 = add nsw i32 %56, %57
  %59 = load i32, ptr %14, align 4, !tbaa !9
  %60 = add nsw i32 %58, %59
  %61 = load i32, ptr %16, align 4, !tbaa !9
  %62 = add nsw i32 %60, %61
  %63 = add nsw i32 %62, 9437184
  %64 = sext i32 %63 to i64
  %65 = call noalias ptr @malloc(i64 noundef %64) #5
  store ptr %65, ptr %22, align 8, !tbaa !5
  store ptr %65, ptr %23, align 8, !tbaa !5
  %66 = load ptr, ptr %22, align 8, !tbaa !5
  %67 = load i32, ptr %10, align 4, !tbaa !9
  %68 = load i32, ptr %12, align 4, !tbaa !9
  %69 = add nsw i32 %67, %68
  %70 = load i32, ptr %14, align 4, !tbaa !9
  %71 = add nsw i32 %69, %70
  %72 = load i32, ptr %16, align 4, !tbaa !9
  %73 = add nsw i32 %71, %72
  %74 = add nsw i32 %73, 9437184
  %75 = sext i32 %74 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %66, i8 -52, i64 %75, i1 false)
  %76 = load ptr, ptr %23, align 8, !tbaa !5
  %77 = call ptr @align_up(ptr noundef %76, i32 noundef 1048576)
  store ptr %77, ptr %23, align 8, !tbaa !5
  %78 = load ptr, ptr %17, align 8, !tbaa !5
  %79 = icmp ne ptr %78, null
  br i1 %79, label %80, label %93

80:                                               ; preds = %55
  %81 = load ptr, ptr %23, align 8, !tbaa !5
  %82 = load i32, ptr %21, align 4, !tbaa !9
  %83 = and i32 -1431655766, %82
  %84 = zext i32 %83 to i64
  %85 = getelementptr inbounds i8, ptr %81, i64 %84
  %86 = load ptr, ptr %17, align 8, !tbaa !5
  store ptr %85, ptr %86, align 8, !tbaa !5
  %87 = load ptr, ptr %17, align 8, !tbaa !5
  %88 = load ptr, ptr %87, align 8, !tbaa !5
  %89 = load i32, ptr %10, align 4, !tbaa !9
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds i8, ptr %88, i64 %90
  %92 = call ptr @align_up(ptr noundef %91, i32 noundef 1048576)
  store ptr %92, ptr %23, align 8, !tbaa !5
  br label %93

93:                                               ; preds = %80, %55
  %94 = load ptr, ptr %18, align 8, !tbaa !5
  %95 = icmp ne ptr %94, null
  br i1 %95, label %96, label %109

96:                                               ; preds = %93
  %97 = load ptr, ptr %23, align 8, !tbaa !5
  %98 = load i32, ptr %21, align 4, !tbaa !9
  %99 = and i32 1431655765, %98
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds i8, ptr %97, i64 %100
  %102 = load ptr, ptr %18, align 8, !tbaa !5
  store ptr %101, ptr %102, align 8, !tbaa !5
  %103 = load ptr, ptr %18, align 8, !tbaa !5
  %104 = load ptr, ptr %103, align 8, !tbaa !5
  %105 = load i32, ptr %12, align 4, !tbaa !9
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds i8, ptr %104, i64 %106
  %108 = call ptr @align_up(ptr noundef %107, i32 noundef 1048576)
  store ptr %108, ptr %23, align 8, !tbaa !5
  br label %109

109:                                              ; preds = %96, %93
  %110 = load ptr, ptr %19, align 8, !tbaa !5
  %111 = icmp ne ptr %110, null
  br i1 %111, label %112, label %125

112:                                              ; preds = %109
  %113 = load ptr, ptr %23, align 8, !tbaa !5
  %114 = load i32, ptr %21, align 4, !tbaa !9
  %115 = and i32 -858993460, %114
  %116 = zext i32 %115 to i64
  %117 = getelementptr inbounds i8, ptr %113, i64 %116
  %118 = load ptr, ptr %19, align 8, !tbaa !5
  store ptr %117, ptr %118, align 8, !tbaa !5
  %119 = load ptr, ptr %19, align 8, !tbaa !5
  %120 = load ptr, ptr %119, align 8, !tbaa !5
  %121 = load i32, ptr %14, align 4, !tbaa !9
  %122 = sext i32 %121 to i64
  %123 = getelementptr inbounds i8, ptr %120, i64 %122
  %124 = call ptr @align_up(ptr noundef %123, i32 noundef 1048576)
  store ptr %124, ptr %23, align 8, !tbaa !5
  br label %125

125:                                              ; preds = %112, %109
  %126 = load ptr, ptr %20, align 8, !tbaa !5
  %127 = icmp ne ptr %126, null
  br i1 %127, label %128, label %135

128:                                              ; preds = %125
  %129 = load ptr, ptr %23, align 8, !tbaa !5
  %130 = load i32, ptr %21, align 4, !tbaa !9
  %131 = and i32 858993459, %130
  %132 = sext i32 %131 to i64
  %133 = getelementptr inbounds i8, ptr %129, i64 %132
  %134 = load ptr, ptr %20, align 8, !tbaa !5
  store ptr %133, ptr %134, align 8, !tbaa !5
  br label %135

135:                                              ; preds = %128, %125
  %136 = load ptr, ptr %22, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #4
  ret ptr %136
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden ptr @align_up(ptr noundef, i32 noundef) #1

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

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


; 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
define dso_local noundef ptr @alloc_four_nonaliased_buffers(ptr noundef writeonly %0, i32 noundef %1, ptr noundef writeonly %2, i32 noundef %3, ptr noundef writeonly %4, i32 noundef %5, ptr noundef writeonly %6, i32 noundef %7) local_unnamed_addr #0 {
  %9 = icmp eq ptr %0, null
  %10 = tail call i32 @llvm.smax.i32(i32 %1, i32 0)
  %11 = add nuw nsw i32 %10, 9437184
  %12 = icmp eq ptr %2, null
  %13 = tail call i32 @llvm.smax.i32(i32 %3, i32 0)
  %spec.store.select9 = select i1 %12, i32 0, i32 %13
  %14 = icmp eq ptr %4, null
  %15 = tail call i32 @llvm.smax.i32(i32 %5, i32 0)
  %spec.store.select8 = select i1 %14, i32 0, i32 %15
  %16 = icmp eq ptr %6, null
  %17 = tail call i32 @llvm.smax.i32(i32 %7, i32 0)
  %spec.store.select10 = select i1 %16, i32 0, i32 %17
  %18 = select i1 %9, i32 9437184, i32 %11
  %19 = add nuw nsw i32 %18, %spec.store.select9
  %20 = add nuw nsw i32 %19, %spec.store.select8
  %21 = add nuw nsw i32 %20, %spec.store.select10
  %22 = zext nneg i32 %21 to i64
  %23 = tail call noalias ptr @malloc(i64 noundef %22) #4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %23, i8 -52, i64 %22, i1 false)
  %24 = tail call ptr @align_up(ptr noundef %23, i32 noundef 1048576)
  br i1 %9, label %30, label %25

25:                                               ; preds = %8
  %26 = getelementptr inbounds i8, ptr %24, i64 699008
  store ptr %26, ptr %0, align 8, !tbaa !5
  %27 = zext nneg i32 %10 to i64
  %28 = getelementptr inbounds i8, ptr %26, i64 %27
  %29 = tail call ptr @align_up(ptr noundef nonnull %28, i32 noundef 1048576)
  br label %30

30:                                               ; preds = %25, %8
  %.0 = phi ptr [ %29, %25 ], [ %24, %8 ]
  br i1 %12, label %36, label %31

31:                                               ; preds = %30
  %32 = getelementptr inbounds i8, ptr %.0, i64 349440
  store ptr %32, ptr %2, align 8, !tbaa !5
  %33 = zext nneg i32 %13 to i64
  %34 = getelementptr inbounds i8, ptr %32, i64 %33
  %35 = tail call ptr @align_up(ptr noundef nonnull %34, i32 noundef 1048576)
  br label %36

36:                                               ; preds = %31, %30
  %.1 = phi ptr [ %35, %31 ], [ %.0, %30 ]
  br i1 %14, label %42, label %37

37:                                               ; preds = %36
  %38 = getelementptr inbounds i8, ptr %.1, i64 838784
  store ptr %38, ptr %4, align 8, !tbaa !5
  %39 = zext nneg i32 %15 to i64
  %40 = getelementptr inbounds i8, ptr %38, i64 %39
  %41 = tail call ptr @align_up(ptr noundef nonnull %40, i32 noundef 1048576)
  br label %42

42:                                               ; preds = %37, %36
  %.2 = phi ptr [ %41, %37 ], [ %.1, %36 ]
  br i1 %16, label %45, label %43

43:                                               ; preds = %42
  %44 = getelementptr inbounds i8, ptr %.2, i64 209664
  store ptr %44, ptr %6, align 8, !tbaa !5
  br label %45

45:                                               ; preds = %43, %42
  ret ptr %23
}

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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @align_up(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nounwind allocsize(0) }

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


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass