; 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
define dso_local noundef i64 @_ZN3xla20cpu_function_runtime18AlignedBufferBytesEPKNS0_10BufferInfoEmb(ptr noundef %0, i64 noundef %1, i1 noundef zeroext %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  %6 = alloca i8, align 1
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i8, align 1
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %10 = zext i1 %2 to i8
  store i8 %10, ptr %6, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %11

11:                                               ; preds = %45, %3
  %12 = load i64, ptr %8, align 8, !tbaa !9
  %13 = load i64, ptr %5, align 8, !tbaa !9
  %14 = icmp ult i64 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %48

16:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = getelementptr inbounds %"class.xla::cpu_function_runtime::BufferInfo", ptr %17, i64 %18
  %20 = call noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo14is_temp_bufferEv(ptr noundef nonnull align 8 dereferenceable(16) %19)
  br i1 %20, label %31, label %21

21:                                               ; preds = %16
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = load i64, ptr %8, align 8, !tbaa !9
  %24 = getelementptr inbounds %"class.xla::cpu_function_runtime::BufferInfo", ptr %22, i64 %23
  %25 = call noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo18is_entry_parameterEv(ptr noundef nonnull align 8 dereferenceable(16) %24)
  br i1 %25, label %26, label %29

26:                                               ; preds = %21
  %27 = load i8, ptr %6, align 1, !tbaa !11, !range !13, !noundef !14
  %28 = trunc i8 %27 to i1
  br label %29

29:                                               ; preds = %26, %21
  %30 = phi i1 [ false, %21 ], [ %28, %26 ]
  br label %31

31:                                               ; preds = %29, %16
  %32 = phi i1 [ true, %16 ], [ %30, %29 ]
  %33 = zext i1 %32 to i8
  store i8 %33, ptr %9, align 1, !tbaa !11
  %34 = load i8, ptr %9, align 1, !tbaa !11, !range !13, !noundef !14
  %35 = trunc i8 %34 to i1
  br i1 %35, label %36, label %44

36:                                               ; preds = %31
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i64, ptr %8, align 8, !tbaa !9
  %39 = getelementptr inbounds %"class.xla::cpu_function_runtime::BufferInfo", ptr %37, i64 %38
  %40 = call noundef i64 @_ZNK3xla20cpu_function_runtime10BufferInfo4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %39)
  %41 = call noundef i64 @_ZN3xla12_GLOBAL__N_18align_toEmm(i64 noundef %40, i64 noundef 64)
  %42 = load i64, ptr %7, align 8, !tbaa !9
  %43 = add i64 %42, %41
  store i64 %43, ptr %7, align 8, !tbaa !9
  br label %44

44:                                               ; preds = %36, %31
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  br label %45

45:                                               ; preds = %44
  %46 = load i64, ptr %8, align 8, !tbaa !9
  %47 = add i64 %46, 1
  store i64 %47, ptr %8, align 8, !tbaa !9
  br label %11, !llvm.loop !15

48:                                               ; preds = %15
  %49 = load i64, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i64 %49
}

; 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

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
define dso_local noundef i64 @_ZN3xla20cpu_function_runtime18AlignedBufferBytesEPKNS0_10BufferInfoEmb(ptr noundef %0, i64 noundef %1, i1 noundef zeroext %2) local_unnamed_addr #0 {
  %.not = icmp eq i64 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  br i1 %2, label %.lr.ph.split, label %.lr.ph.split.us

.lr.ph.split.us:                                  ; preds = %.lr.ph, %11
  %.014.us = phi i64 [ %.1.us, %11 ], [ 0, %.lr.ph ]
  %.01213.us = phi i64 [ %12, %11 ], [ 0, %.lr.ph ]
  %4 = getelementptr inbounds %"class.xla::cpu_function_runtime::BufferInfo", ptr %0, i64 %.01213.us
  %5 = tail call noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo14is_temp_bufferEv(ptr noundef nonnull align 8 dereferenceable(16) %4)
  br i1 %5, label %.critedge.us, label %6

6:                                                ; preds = %.lr.ph.split.us
  %7 = tail call noundef zeroext i1 @_ZNK3xla20cpu_function_runtime10BufferInfo18is_entry_parameterEv(ptr noundef nonnull align 8 dereferenceable(16) %4)
  br label %11

.critedge.us:                                     ; preds = %.lr.ph.split.us
  %8 = tail call noundef i64 @_ZNK3xla20cpu_function_runtime10BufferInfo4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %4)
  %9 = tail call noundef i64 @_ZN3xla12_GLOBAL__N_18align_toEmm(i64 noundef %8, i64 noundef 64)
  %10 = add i64 %9, %.014.us
  br label %11

11:                                               ; preds = %6, %.critedge.us
  %.1.us = phi i64 [ %10, %.critedge.us ], [ %.014.us, %6 ]
  %12 = add nuw i64 %.01213.us, 1
  %exitcond.not = icmp eq i64 %12, %1
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.split.us, !llvm.loop !5

._crit_edge:                                      ; preds = %11, %20, %3
  %.0.lcssa = phi i64 [ 0, %3 ], [ %.1, %20 ], [ %.1.us, %11 ]
  ret i64 %.0.lcssa

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

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

.critedge:                                        ; preds = %.lr.ph.split, %15
  %17 = tail call noundef i64 @_ZNK3xla20cpu_function_runtime10BufferInfo4sizeEv(ptr noundef nonnull align 8 dereferenceable(16) %13)
  %18 = tail call noundef i64 @_ZN3xla12_GLOBAL__N_18align_toEmm(i64 noundef %17, i64 noundef 64)
  %19 = add i64 %18, %.014
  br label %20

20:                                               ; preds = %.critedge, %15
  %.1 = phi i64 [ %19, %.critedge ], [ %.014, %15 ]
  %21 = add nuw i64 %.01213, 1
  %exitcond16.not = icmp eq i64 %21, %1
  br i1 %exitcond16.not, label %._crit_edge, label %.lr.ph.split, !llvm.loop !5
}

; 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

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


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