; LLVM IR from NVIDIA/tensorflow :: tensorflow/compiler/xla (cpu_function_runtime)

; 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.xla::cpu_function_runtime::BufferInfo" = type { i64, i64 }

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN3xla20cpu_function_runtime18AlignedBufferBytesEPKNS0_10BufferInfoEmb(ptr noundef, i64 noundef, i1 noundef zeroext) #0

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo14is_temp_bufferEv(ptr noundef nonnull align 8 dereferenceable(16)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo18is_entry_parameterEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i64 @_ZN3xla12_GLOBAL__N_18align_toEmm(i64 noundef, i64 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK3xla20cpu_function_runtime10BufferInfo4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

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

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN3xla20cpu_function_runtime23MallocContiguousBuffersEPKNS0_10BufferInfoEmbPPvb(ptr noundef %0, i64 noundef %1, i1 noundef zeroext %2, ptr noundef %3, i1 noundef zeroext %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca i8, align 1
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca i64, align 8
  %15 = alloca i8, align 1
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  %16 = zext i1 %2 to i8
  store i8 %16, ptr %8, align 1, !tbaa !11
  store ptr %3, ptr %9, align 8, !tbaa !5
  %17 = zext i1 %4 to i8
  store i8 %17, ptr %10, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i64, ptr %7, align 8, !tbaa !9
  %20 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %21 = trunc i8 %20 to i1
  %22 = call noundef i64 @_ZN3xla20cpu_function_runtime18AlignedBufferBytesEPKNS0_10BufferInfoEmb(ptr noundef %18, i64 noundef %19, i1 noundef zeroext %21)
  store i64 %22, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  store ptr null, ptr %12, align 8, !tbaa !5
  %23 = load i64, ptr %11, align 8, !tbaa !9
  %24 = icmp ugt i64 %23, 0
  br i1 %24, label %25, label %35

25:                                               ; preds = %5
  %26 = load i64, ptr %11, align 8, !tbaa !9
  %27 = call noundef ptr @_ZN3xla12_GLOBAL__N_114aligned_mallocEmi(i64 noundef %26, i32 noundef 64)
  store ptr %27, ptr %12, align 8, !tbaa !5
  %28 = load i8, ptr %10, align 1, !tbaa !11, !range !13, !noundef !14
  %29 = trunc i8 %28 to i1
  br i1 %29, label %30, label %34

30:                                               ; preds = %25
  br label %31

31:                                               ; preds = %30
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  br label %34

34:                                               ; preds = %33, %25
  br label %35

35:                                               ; preds = %34, %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %36 = load ptr, ptr %12, align 8, !tbaa !5
  %37 = ptrtoint ptr %36 to i64
  store i64 %37, ptr %13, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store i64 0, ptr %14, align 8, !tbaa !9
  br label %38

38:                                               ; preds = %81, %35
  %39 = load i64, ptr %14, align 8, !tbaa !9
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = icmp ult i64 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  br label %84

43:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #3
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load i64, ptr %14, align 8, !tbaa !9
  %46 = getelementptr inbounds %"class.xla::cpu_function_runtime::BufferInfo", ptr %44, i64 %45
  %47 = call noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo14is_temp_bufferEv(ptr noundef nonnull align 8 dereferenceable(16) %46)
  br i1 %47, label %58, label %48

48:                                               ; preds = %43
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load i64, ptr %14, align 8, !tbaa !9
  %51 = getelementptr inbounds %"class.xla::cpu_function_runtime::BufferInfo", ptr %49, i64 %50
  %52 = call noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo18is_entry_parameterEv(ptr noundef nonnull align 8 dereferenceable(16) %51)
  br i1 %52, label %53, label %56

53:                                               ; preds = %48
  %54 = load i8, ptr %8, align 1, !tbaa !11, !range !13, !noundef !14
  %55 = trunc i8 %54 to i1
  br label %56

56:                                               ; preds = %53, %48
  %57 = phi i1 [ false, %48 ], [ %55, %53 ]
  br label %58

58:                                               ; preds = %56, %43
  %59 = phi i1 [ true, %43 ], [ %57, %56 ]
  %60 = zext i1 %59 to i8
  store i8 %60, ptr %15, align 1, !tbaa !11
  %61 = load i8, ptr %15, align 1, !tbaa !11, !range !13, !noundef !14
  %62 = trunc i8 %61 to i1
  br i1 %62, label %63, label %76

63:                                               ; preds = %58
  %64 = load i64, ptr %13, align 8, !tbaa !9
  %65 = inttoptr i64 %64 to ptr
  %66 = load ptr, ptr %9, align 8, !tbaa !5
  %67 = load i64, ptr %14, align 8, !tbaa !9
  %68 = getelementptr inbounds ptr, ptr %66, i64 %67
  store ptr %65, ptr %68, align 8, !tbaa !5
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = load i64, ptr %14, align 8, !tbaa !9
  %71 = getelementptr inbounds %"class.xla::cpu_function_runtime::BufferInfo", ptr %69, i64 %70
  %72 = call noundef i64 @_ZNK3xla20cpu_function_runtime10BufferInfo4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %71)
  %73 = call noundef i64 @_ZN3xla12_GLOBAL__N_18align_toEmm(i64 noundef %72, i64 noundef 64)
  %74 = load i64, ptr %13, align 8, !tbaa !9
  %75 = add i64 %74, %73
  store i64 %75, ptr %13, align 8, !tbaa !9
  br label %80

76:                                               ; preds = %58
  %77 = load ptr, ptr %9, align 8, !tbaa !5
  %78 = load i64, ptr %14, align 8, !tbaa !9
  %79 = getelementptr inbounds ptr, ptr %77, i64 %78
  store ptr null, ptr %79, align 8, !tbaa !5
  br label %80

80:                                               ; preds = %76, %63
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #3
  br label %81

81:                                               ; preds = %80
  %82 = load i64, ptr %14, align 8, !tbaa !9
  %83 = add i64 %82, 1
  store i64 %83, ptr %14, align 8, !tbaa !9
  br label %38, !llvm.loop !15

84:                                               ; preds = %42
  %85 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret ptr %85
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN3xla12_GLOBAL__N_114aligned_mallocEmi(i64 noundef, i32 noundef) #2

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


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

%"class.xla::cpu_function_runtime::BufferInfo" = type { i64, i64 }

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN3xla20cpu_function_runtime18AlignedBufferBytesEPKNS0_10BufferInfoEmb(ptr noundef, i64 noundef, i1 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo14is_temp_bufferEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo18is_entry_parameterEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef i64 @_ZN3xla12_GLOBAL__N_18align_toEmm(i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNK3xla20cpu_function_runtime10BufferInfo4sizeEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_ZN3xla20cpu_function_runtime23MallocContiguousBuffersEPKNS0_10BufferInfoEmbPPvb(ptr noundef %0, i64 noundef %1, i1 noundef zeroext %2, ptr nocapture noundef writeonly %3, i1 noundef zeroext %4) local_unnamed_addr #0 {
  %6 = tail call noundef i64 @_ZN3xla20cpu_function_runtime18AlignedBufferBytesEPKNS0_10BufferInfoEmb(ptr noundef %0, i64 noundef %1, i1 noundef zeroext %2)
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %9, label %7

7:                                                ; preds = %5
  %8 = tail call noundef ptr @_ZN3xla12_GLOBAL__N_114aligned_mallocEmi(i64 noundef %6, i32 noundef 64)
  br label %9

9:                                                ; preds = %7, %5
  %.0 = phi ptr [ %8, %7 ], [ null, %5 ]
  %.not29 = icmp eq i64 %1, 0
  br i1 %.not29, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %9
  %10 = ptrtoint ptr %.0 to i64
  br i1 %2, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph, %20
  %.02428.us = phi i64 [ %21, %20 ], [ 0, %.lr.ph ]
  %.02527.us = phi i64 [ %.1.us, %20 ], [ %10, %.lr.ph ]
  %11 = getelementptr inbounds %"class.xla::cpu_function_runtime::BufferInfo", ptr %0, i64 %.02428.us
  %12 = tail call noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo14is_temp_bufferEv(ptr noundef nonnull align 8 dereferenceable(16) %11)
  %13 = getelementptr inbounds ptr, ptr %3, i64 %.02428.us
  br i1 %12, label %.critedge.us, label %14

14:                                               ; preds = %.lr.ph.split.us
  %15 = tail call noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo18is_entry_parameterEv(ptr noundef nonnull align 8 dereferenceable(16) %11)
  store ptr null, ptr %13, align 8, !tbaa !5
  br label %20

.critedge.us:                                     ; preds = %.lr.ph.split.us
  %16 = inttoptr i64 %.02527.us to ptr
  store ptr %16, ptr %13, align 8, !tbaa !5
  %17 = tail call noundef i64 @_ZNK3xla20cpu_function_runtime10BufferInfo4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %11)
  %18 = tail call noundef i64 @_ZN3xla12_GLOBAL__N_18align_toEmm(i64 noundef %17, i64 noundef 64)
  %19 = add i64 %18, %.02527.us
  br label %20

20:                                               ; preds = %.critedge.us, %14
  %.1.us = phi i64 [ %19, %.critedge.us ], [ %.02527.us, %14 ]
  %21 = add nuw i64 %.02428.us, 1
  %exitcond.not = icmp eq i64 %21, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !9

._crit_edge:                                      ; preds = %20, %33, %9
  ret ptr %.0

.lr.ph.split:                                     ; preds = %.lr.ph, %33
  %.02428 = phi i64 [ %34, %33 ], [ 0, %.lr.ph ]
  %.02527 = phi i64 [ %.1, %33 ], [ %10, %.lr.ph ]
  %22 = getelementptr inbounds %"class.xla::cpu_function_runtime::BufferInfo", ptr %0, i64 %.02428
  %23 = tail call noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo14is_temp_bufferEv(ptr noundef nonnull align 8 dereferenceable(16) %22)
  br i1 %23, label %.critedge, label %24

24:                                               ; preds = %.lr.ph.split
  %25 = tail call noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo18is_entry_parameterEv(ptr noundef nonnull align 8 dereferenceable(16) %22)
  br i1 %25, label %.critedge, label %31

.critedge:                                        ; preds = %.lr.ph.split, %24
  %26 = inttoptr i64 %.02527 to ptr
  %27 = getelementptr inbounds ptr, ptr %3, i64 %.02428
  store ptr %26, ptr %27, align 8, !tbaa !5
  %28 = tail call noundef i64 @_ZNK3xla20cpu_function_runtime10BufferInfo4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %22)
  %29 = tail call noundef i64 @_ZN3xla12_GLOBAL__N_18align_toEmm(i64 noundef %28, i64 noundef 64)
  %30 = add i64 %29, %.02527
  br label %33

31:                                               ; preds = %24
  %32 = getelementptr inbounds ptr, ptr %3, i64 %.02428
  store ptr null, ptr %32, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %31, %.critedge
  %.1 = phi i64 [ %30, %.critedge ], [ %.02527, %31 ]
  %34 = add nuw i64 %.02428, 1
  %exitcond31.not = icmp eq i64 %34, %1
  br i1 %exitcond31.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !9
}

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZN3xla12_GLOBAL__N_114aligned_mallocEmi(i64 noundef, i32 noundef) local_unnamed_addr #1

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 = { 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" }

!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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass