; LLVM IR from gulrak/filesystem :: test/impl_test.ll (ZN3ghc10filesystem5spaceERKNS0_4pathERSt10error_code)

; 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.ghc::filesystem::space_info" = type { i64, i64, i64 }
%struct.statvfs = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, [6 x i32] }
%"class.std::error_code" = type { i32, ptr }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { i32, ptr } @_ZN3ghc10filesystem6detail17make_system_errorEi(i32 noundef) #0

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3ghc10filesystem4path5c_strEv(ptr noundef nonnull align 8 dereferenceable(32)) #0 align 2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3ghc10filesystem5spaceERKNS0_4pathERSt10error_code(ptr dead_on_unwind noalias writable sret(%"struct.ghc::filesystem::space_info") align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(16) %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca %struct.statvfs, align 8
  %7 = alloca %"class.std::error_code", align 8
  %8 = alloca i32, align 4
  store ptr %1, ptr %4, align 8, !tbaa !5
  store ptr %2, ptr %5, align 8, !tbaa !5
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  call void @_ZNSt10error_code5clearEv(ptr noundef nonnull align 8 dereferenceable(16) %9) #4
  call void @llvm.lifetime.start.p0(i64 112, ptr %6) #4
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = call noundef ptr @_ZNK3ghc10filesystem4path5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %10) #4
  %12 = call i32 @statvfs(ptr noundef %11, ptr noundef %6) #4
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %24

14:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #4
  %15 = call { i32, ptr } @_ZN3ghc10filesystem6detail17make_system_errorEi(i32 noundef 0)
  %16 = getelementptr inbounds { i32, ptr }, ptr %7, i32 0, i32 0
  %17 = extractvalue { i32, ptr } %15, 0
  store i32 %17, ptr %16, align 8
  %18 = getelementptr inbounds { i32, ptr }, ptr %7, i32 0, i32 1
  %19 = extractvalue { i32, ptr } %15, 1
  store ptr %19, ptr %18, align 8
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %20, ptr align 8 %7, i64 16, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #4
  %21 = getelementptr inbounds %"struct.ghc::filesystem::space_info", ptr %0, i32 0, i32 0
  store i64 -1, ptr %21, align 8, !tbaa !12
  %22 = getelementptr inbounds %"struct.ghc::filesystem::space_info", ptr %0, i32 0, i32 1
  store i64 -1, ptr %22, align 8, !tbaa !15
  %23 = getelementptr inbounds %"struct.ghc::filesystem::space_info", ptr %0, i32 0, i32 2
  store i64 -1, ptr %23, align 8, !tbaa !16
  store i32 1, ptr %8, align 4
  br label %43

24:                                               ; preds = %3
  %25 = getelementptr inbounds %"struct.ghc::filesystem::space_info", ptr %0, i32 0, i32 0
  %26 = getelementptr inbounds %struct.statvfs, ptr %6, i32 0, i32 2
  %27 = load i64, ptr %26, align 8, !tbaa !17
  %28 = getelementptr inbounds %struct.statvfs, ptr %6, i32 0, i32 1
  %29 = load i64, ptr %28, align 8, !tbaa !19
  %30 = mul i64 %27, %29
  store i64 %30, ptr %25, align 8, !tbaa !12
  %31 = getelementptr inbounds %"struct.ghc::filesystem::space_info", ptr %0, i32 0, i32 1
  %32 = getelementptr inbounds %struct.statvfs, ptr %6, i32 0, i32 3
  %33 = load i64, ptr %32, align 8, !tbaa !20
  %34 = getelementptr inbounds %struct.statvfs, ptr %6, i32 0, i32 1
  %35 = load i64, ptr %34, align 8, !tbaa !19
  %36 = mul i64 %33, %35
  store i64 %36, ptr %31, align 8, !tbaa !15
  %37 = getelementptr inbounds %"struct.ghc::filesystem::space_info", ptr %0, i32 0, i32 2
  %38 = getelementptr inbounds %struct.statvfs, ptr %6, i32 0, i32 4
  %39 = load i64, ptr %38, align 8, !tbaa !21
  %40 = getelementptr inbounds %struct.statvfs, ptr %6, i32 0, i32 1
  %41 = load i64, ptr %40, align 8, !tbaa !19
  %42 = mul i64 %39, %41
  store i64 %42, ptr %37, align 8, !tbaa !16
  store i32 1, ptr %8, align 4
  br label %43

43:                                               ; preds = %24, %14
  call void @llvm.lifetime.end.p0(i64 112, ptr %6) #4
  ret void
}

; Function Attrs: nounwind
declare i32 @statvfs(ptr noundef, ptr noundef) #3

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { nounwind "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 = !{i64 0, i64 4, !10, i64 8, i64 8, !5}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !14, i64 0}
!13 = !{!"_ZTSN3ghc10filesystem10space_infoE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"long", !7, i64 0}
!15 = !{!13, !14, i64 8}
!16 = !{!13, !14, i64 16}
!17 = !{!18, !14, i64 16}
!18 = !{!"_ZTS7statvfs", !14, i64 0, !14, i64 8, !14, i64 16, !14, i64 24, !14, i64 32, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !14, i64 72, !14, i64 80, !7, i64 88}
!19 = !{!18, !14, i64 8}
!20 = !{!18, !14, i64 24}
!21 = !{!18, !14, i64 32}


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

%"struct.ghc::filesystem::space_info" = type { i64, i64, i64 }
%struct.statvfs = type { i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, i64, [6 x i32] }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local { i32, ptr } @_ZN3ghc10filesystem6detail17make_system_errorEi(i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNK3ghc10filesystem4path5c_strEv(ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt10error_code5clearEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_ZN3ghc10filesystem5spaceERKNS0_4pathERSt10error_code(ptr dead_on_unwind noalias nocapture writable writeonly sret(%"struct.ghc::filesystem::space_info") align 8 %0, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(16) %2) local_unnamed_addr #0 {
  %4 = alloca %struct.statvfs, align 8
  tail call void @_ZNSt10error_code5clearEv(ptr noundef nonnull align 8 dereferenceable(16) %2) #3
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %4) #3
  %5 = tail call noundef ptr @_ZNK3ghc10filesystem4path5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #3
  %6 = call i32 @statvfs(ptr noundef %5, ptr noundef nonnull %4) #3
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %11, label %7

7:                                                ; preds = %3
  %8 = tail call { i32, ptr } @_ZN3ghc10filesystem6detail17make_system_errorEi(i32 noundef 0)
  %9 = extractvalue { i32, ptr } %8, 0
  %10 = extractvalue { i32, ptr } %8, 1
  store i32 %9, ptr %2, align 8, !tbaa !5
  %.sroa.41.0..sroa_idx = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %10, ptr %.sroa.41.0..sroa_idx, align 8, !tbaa !9
  br label %23

11:                                               ; preds = %3
  %12 = getelementptr inbounds i8, ptr %4, i64 16
  %13 = load i64, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds i8, ptr %4, i64 8
  %15 = load i64, ptr %14, align 8, !tbaa !14
  %16 = mul i64 %15, %13
  %17 = getelementptr inbounds i8, ptr %4, i64 24
  %18 = load i64, ptr %17, align 8, !tbaa !15
  %19 = mul i64 %18, %15
  %20 = getelementptr inbounds i8, ptr %4, i64 32
  %21 = load i64, ptr %20, align 8, !tbaa !16
  %22 = mul i64 %21, %15
  br label %23

23:                                               ; preds = %11, %7
  %.sink5 = phi i64 [ %16, %11 ], [ -1, %7 ]
  %.sink4 = phi i64 [ %19, %11 ], [ -1, %7 ]
  %.sink = phi i64 [ %22, %11 ], [ -1, %7 ]
  store i64 %.sink5, ptr %0, align 8
  %24 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %.sink4, ptr %24, align 8
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %.sink, ptr %25, align 8
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %4) #3
  ret void
}

; Function Attrs: nofree nounwind
declare noundef i32 @statvfs(ptr nocapture noundef readonly, ptr nocapture noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nofree nounwind "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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !13, i64 16}
!12 = !{!"_ZTS7statvfs", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !13, i64 80, !7, i64 88}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!12, !13, i64 24}
!16 = !{!12, !13, i64 32}


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