; LLVM IR from NervanaSystems/ngraph :: src/ngraph/runtime (aligned_buffer)

; 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.ngraph::runtime::AlignedBuffer" = type { ptr, ptr, ptr, i64 }

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6ngraph7runtime13AlignedBufferC2EmmPNS0_9AllocatorE(ptr noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store i64 %2, ptr %7, align 8, !tbaa !9
  store ptr %3, ptr %8, align 8, !tbaa !5
  %12 = load ptr, ptr %5, align 8
  %13 = getelementptr inbounds %"class.ngraph::runtime::AlignedBuffer", ptr %12, i32 0, i32 0
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %14, ptr %13, align 8, !tbaa !11
  %15 = getelementptr inbounds %"class.ngraph::runtime::AlignedBuffer", ptr %12, i32 0, i32 3
  %16 = load i64, ptr %6, align 8, !tbaa !9
  store i64 %16, ptr %15, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 1, ptr %9, align 8, !tbaa !9
  %17 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %9, ptr noundef nonnull align 8 dereferenceable(8) %6)
  %18 = load i64, ptr %17, align 8, !tbaa !9
  %19 = getelementptr inbounds %"class.ngraph::runtime::AlignedBuffer", ptr %12, i32 0, i32 3
  store i64 %18, ptr %19, align 8, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %20 = getelementptr inbounds %"class.ngraph::runtime::AlignedBuffer", ptr %12, i32 0, i32 3
  %21 = load i64, ptr %20, align 8, !tbaa !13
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = add i64 %21, %22
  store i64 %23, ptr %10, align 8, !tbaa !9
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = icmp ne ptr %24, null
  br i1 %25, label %26, label %36

26:                                               ; preds = %4
  %27 = getelementptr inbounds %"class.ngraph::runtime::AlignedBuffer", ptr %12, i32 0, i32 0
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  %29 = load i64, ptr %10, align 8, !tbaa !9
  %30 = load i64, ptr %7, align 8, !tbaa !9
  %31 = load ptr, ptr %28, align 8, !tbaa !14
  %32 = getelementptr inbounds ptr, ptr %31, i64 2
  %33 = load ptr, ptr %32, align 8
  %34 = call noundef ptr %33(ptr noundef nonnull align 8 dereferenceable(8) %28, i64 noundef %29, i64 noundef %30)
  %35 = getelementptr inbounds %"class.ngraph::runtime::AlignedBuffer", ptr %12, i32 0, i32 1
  store ptr %34, ptr %35, align 8, !tbaa !16
  br label %40

36:                                               ; preds = %4
  %37 = load i64, ptr %10, align 8, !tbaa !9
  %38 = call noundef ptr @_ZN6ngraph13ngraph_mallocEm(i64 noundef %37)
  %39 = getelementptr inbounds %"class.ngraph::runtime::AlignedBuffer", ptr %12, i32 0, i32 1
  store ptr %38, ptr %39, align 8, !tbaa !16
  br label %40

40:                                               ; preds = %36, %26
  %41 = getelementptr inbounds %"class.ngraph::runtime::AlignedBuffer", ptr %12, i32 0, i32 1
  %42 = load ptr, ptr %41, align 8, !tbaa !16
  %43 = getelementptr inbounds %"class.ngraph::runtime::AlignedBuffer", ptr %12, i32 0, i32 2
  store ptr %42, ptr %43, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %44 = getelementptr inbounds %"class.ngraph::runtime::AlignedBuffer", ptr %12, i32 0, i32 2
  %45 = load ptr, ptr %44, align 8, !tbaa !17
  %46 = ptrtoint ptr %45 to i64
  %47 = load i64, ptr %7, align 8, !tbaa !9
  %48 = urem i64 %46, %47
  store i64 %48, ptr %11, align 8, !tbaa !9
  %49 = load i64, ptr %11, align 8, !tbaa !9
  %50 = icmp ne i64 %49, 0
  br i1 %50, label %51, label %58

51:                                               ; preds = %40
  %52 = load i64, ptr %7, align 8, !tbaa !9
  %53 = load i64, ptr %11, align 8, !tbaa !9
  %54 = sub i64 %52, %53
  %55 = getelementptr inbounds %"class.ngraph::runtime::AlignedBuffer", ptr %12, i32 0, i32 2
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  %57 = getelementptr inbounds i8, ptr %56, i64 %54
  store ptr %57, ptr %55, align 8, !tbaa !17
  br label %58

58:                                               ; preds = %51, %40
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #1

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

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

declare noundef ptr @_ZN6ngraph13ngraph_mallocEm(i64 noundef) #3

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

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


; 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 uwtable
define dso_local void @_ZN6ngraph7runtime13AlignedBufferC2EmmPNS0_9AllocatorE(ptr nocapture noundef nonnull align 8 dereferenceable(32) %0, i64 noundef %1, i64 noundef %2, ptr noundef %3) unnamed_addr #0 align 2 {
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  store i64 %1, ptr %5, align 8, !tbaa !5
  store ptr %3, ptr %0, align 8, !tbaa !9
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  store i64 %1, ptr %7, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #4
  store i64 1, ptr %6, align 8, !tbaa !5
  %8 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %6, ptr noundef nonnull align 8 dereferenceable(8) %5)
  %9 = load i64, ptr %8, align 8, !tbaa !5
  store i64 %9, ptr %7, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #4
  %10 = add i64 %9, %2
  %.not = icmp eq ptr %3, null
  br i1 %.not, label %17, label %11

11:                                               ; preds = %4
  %12 = load ptr, ptr %0, align 8, !tbaa !9
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %13, i64 16
  %15 = load ptr, ptr %14, align 8
  %16 = call noundef ptr %15(ptr noundef nonnull align 8 dereferenceable(8) %12, i64 noundef %10, i64 noundef %2)
  br label %19

17:                                               ; preds = %4
  %18 = call noundef ptr @_ZN6ngraph13ngraph_mallocEm(i64 noundef %10)
  br label %19

19:                                               ; preds = %17, %11
  %.sink = phi ptr [ %18, %17 ], [ %16, %11 ]
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  store ptr %.sink, ptr %20, align 8
  %21 = ptrtoint ptr %.sink to i64
  %22 = urem i64 %21, %2
  %.not10 = icmp eq i64 %22, 0
  %23 = sub i64 %2, %22
  %storemerge.idx = select i1 %.not10, i64 0, i64 %23
  %storemerge = getelementptr inbounds i8, ptr %.sink, i64 %storemerge.idx
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %storemerge, ptr %24, align 8, !tbaa !15
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3maxImERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

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

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

declare noundef ptr @_ZN6ngraph13ngraph_mallocEm(i64 noundef) local_unnamed_addr #3

attributes #0 = { 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" }
attributes #1 = { inlinehint 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,MergedLoadStoreMotionPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass