; LLVM IR from gulrak/filesystem :: test/impl_test.ll (ZN3ghc10filesystem10equivalentERKNS0_4pathES3_RSt10error_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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }
%"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: nounwind willreturn memory(none)
declare ptr @__errno_location() #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

; 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) #3

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

; Function Attrs: nounwind
declare i32 @stat(ptr noundef, ptr noundef) #4

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3ghc10filesystem10equivalentERKNS0_4pathES3_RSt10error_code(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(16) %2) #0 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca %struct.stat, align 8
  %9 = alloca %struct.stat, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca %"class.std::error_code", align 8
  %14 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  call void @_ZNSt10error_code5clearEv(ptr noundef nonnull align 8 dereferenceable(16) %15) #5
  call void @llvm.lifetime.start.p0(i64 144, ptr %8) #5
  call void @llvm.lifetime.start.p0(i64 144, ptr %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = call noundef ptr @_ZNK3ghc10filesystem4path5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %16) #5
  %18 = call i32 @stat(ptr noundef %17, ptr noundef %8) #5
  store i32 %18, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %19 = call ptr @__errno_location() #6
  %20 = load i32, ptr %19, align 4, !tbaa !9
  store i32 %20, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #5
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = call noundef ptr @_ZNK3ghc10filesystem4path5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %21) #5
  %23 = call i32 @stat(ptr noundef %22, ptr noundef %9) #5
  store i32 %23, ptr %12, align 4, !tbaa !9
  %24 = load i32, ptr %10, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %29, label %26

26:                                               ; preds = %3
  %27 = load i32, ptr %12, align 4, !tbaa !9
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %45

29:                                               ; preds = %26, %3
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #5
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %34

32:                                               ; preds = %29
  %33 = load i32, ptr %11, align 4, !tbaa !9
  br label %37

34:                                               ; preds = %29
  %35 = call ptr @__errno_location() #6
  %36 = load i32, ptr %35, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %34, %32
  %38 = phi i32 [ %33, %32 ], [ %36, %34 ]
  %39 = call { i32, ptr } @_ZN3ghc10filesystem6detail17make_system_errorEi(i32 noundef %38)
  %40 = getelementptr inbounds { i32, ptr }, ptr %13, i32 0, i32 0
  %41 = extractvalue { i32, ptr } %39, 0
  store i32 %41, ptr %40, align 8
  %42 = getelementptr inbounds { i32, ptr }, ptr %13, i32 0, i32 1
  %43 = extractvalue { i32, ptr } %39, 1
  store ptr %43, ptr %42, align 8
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %44, ptr align 8 %13, i64 16, i1 false), !tbaa.struct !11
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #5
  store i1 false, ptr %4, align 1
  store i32 1, ptr %14, align 4
  br label %73

45:                                               ; preds = %26
  %46 = getelementptr inbounds %struct.stat, ptr %8, i32 0, i32 0
  %47 = load i64, ptr %46, align 8, !tbaa !12
  %48 = getelementptr inbounds %struct.stat, ptr %9, i32 0, i32 0
  %49 = load i64, ptr %48, align 8, !tbaa !12
  %50 = icmp eq i64 %47, %49
  br i1 %50, label %51, label %71

51:                                               ; preds = %45
  %52 = getelementptr inbounds %struct.stat, ptr %8, i32 0, i32 1
  %53 = load i64, ptr %52, align 8, !tbaa !16
  %54 = getelementptr inbounds %struct.stat, ptr %9, i32 0, i32 1
  %55 = load i64, ptr %54, align 8, !tbaa !16
  %56 = icmp eq i64 %53, %55
  br i1 %56, label %57, label %71

57:                                               ; preds = %51
  %58 = getelementptr inbounds %struct.stat, ptr %8, i32 0, i32 8
  %59 = load i64, ptr %58, align 8, !tbaa !17
  %60 = getelementptr inbounds %struct.stat, ptr %9, i32 0, i32 8
  %61 = load i64, ptr %60, align 8, !tbaa !17
  %62 = icmp eq i64 %59, %61
  br i1 %62, label %63, label %71

63:                                               ; preds = %57
  %64 = getelementptr inbounds %struct.stat, ptr %8, i32 0, i32 12
  %65 = getelementptr inbounds %struct.timespec, ptr %64, i32 0, i32 0
  %66 = load i64, ptr %65, align 8, !tbaa !18
  %67 = getelementptr inbounds %struct.stat, ptr %9, i32 0, i32 12
  %68 = getelementptr inbounds %struct.timespec, ptr %67, i32 0, i32 0
  %69 = load i64, ptr %68, align 8, !tbaa !18
  %70 = icmp eq i64 %66, %69
  br label %71

71:                                               ; preds = %63, %57, %51, %45
  %72 = phi i1 [ false, %57 ], [ false, %51 ], [ false, %45 ], [ %70, %63 ]
  store i1 %72, ptr %4, align 1
  store i32 1, ptr %14, align 4
  br label %73

73:                                               ; preds = %71, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 144, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 144, ptr %8) #5
  %74 = load i1, ptr %4, align 1
  ret i1 %74
}

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 = { nounwind willreturn memory(none) "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(none) }

!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 = !{!"int", !7, i64 0}
!11 = !{i64 0, i64 4, !9, i64 8, i64 8, !5}
!12 = !{!13, !14, i64 0}
!13 = !{!"_ZTS4stat", !14, i64 0, !14, i64 8, !14, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !14, i64 40, !14, i64 48, !14, i64 56, !14, i64 64, !15, i64 72, !15, i64 88, !15, i64 104, !7, i64 120}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTS8timespec", !14, i64 0, !14, i64 8}
!16 = !{!13, !14, i64 8}
!17 = !{!13, !14, i64 48}
!18 = !{!13, !14, i64 88}


; 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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

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

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() 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

; 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: nofree nounwind
declare noundef i32 @stat(ptr nocapture noundef readonly, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN3ghc10filesystem10equivalentERKNS0_4pathES3_RSt10error_code(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1, ptr noundef nonnull align 8 dereferenceable(16) %2) local_unnamed_addr #0 {
  %4 = alloca %struct.stat, align 8
  %5 = alloca %struct.stat, align 8
  tail call void @_ZNSt10error_code5clearEv(ptr noundef nonnull align 8 dereferenceable(16) %2) #4
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %5) #4
  %6 = tail call noundef ptr @_ZNK3ghc10filesystem4path5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #4
  %7 = call i32 @stat(ptr noundef %6, ptr noundef nonnull %4) #4
  %8 = tail call ptr @__errno_location() #5
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = tail call noundef ptr @_ZNK3ghc10filesystem4path5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #4
  %11 = call i32 @stat(ptr noundef %10, ptr noundef nonnull %5) #4
  %12 = or i32 %11, %7
  %or.cond.not = icmp eq i32 %12, 0
  br i1 %or.cond.not, label %21, label %13

13:                                               ; preds = %3
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %14, label %16

14:                                               ; preds = %13
  %15 = load i32, ptr %8, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %13, %14
  %17 = phi i32 [ %15, %14 ], [ %9, %13 ]
  %18 = tail call { i32, ptr } @_ZN3ghc10filesystem6detail17make_system_errorEi(i32 noundef %17)
  %19 = extractvalue { i32, ptr } %18, 0
  %20 = extractvalue { i32, ptr } %18, 1
  store i32 %19, ptr %2, align 8, !tbaa !5
  %.sroa.42.0..sroa_idx = getelementptr inbounds i8, ptr %2, i64 8
  store ptr %20, ptr %.sroa.42.0..sroa_idx, align 8, !tbaa !9
  br label %43

21:                                               ; preds = %3
  %22 = load i64, ptr %4, align 8, !tbaa !11
  %23 = load i64, ptr %5, align 8, !tbaa !11
  %24 = icmp eq i64 %22, %23
  br i1 %24, label %25, label %43

25:                                               ; preds = %21
  %26 = getelementptr inbounds i8, ptr %4, i64 8
  %27 = load i64, ptr %26, align 8, !tbaa !15
  %28 = getelementptr inbounds i8, ptr %5, i64 8
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = icmp eq i64 %27, %29
  br i1 %30, label %31, label %43

31:                                               ; preds = %25
  %32 = getelementptr inbounds i8, ptr %4, i64 48
  %33 = load i64, ptr %32, align 8, !tbaa !16
  %34 = getelementptr inbounds i8, ptr %5, i64 48
  %35 = load i64, ptr %34, align 8, !tbaa !16
  %36 = icmp eq i64 %33, %35
  br i1 %36, label %37, label %43

37:                                               ; preds = %31
  %38 = getelementptr inbounds i8, ptr %4, i64 88
  %39 = load i64, ptr %38, align 8, !tbaa !17
  %40 = getelementptr inbounds i8, ptr %5, i64 88
  %41 = load i64, ptr %40, align 8, !tbaa !17
  %42 = icmp eq i64 %39, %41
  br label %43

43:                                               ; preds = %21, %25, %31, %37, %16
  %.0 = phi i1 [ false, %16 ], [ false, %31 ], [ false, %25 ], [ false, %21 ], [ %42, %37 ]
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %4) #4
  ret i1 %.0
}

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 nofree nosync nounwind willreturn memory(none) "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 = { 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(none) }

!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 0}
!12 = !{!"_ZTS4stat", !13, i64 0, !13, i64 8, !13, i64 16, !6, i64 24, !6, i64 28, !6, i64 32, !6, i64 36, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !14, i64 72, !14, i64 88, !14, i64 104, !7, i64 120}
!13 = !{!"long", !7, i64 0}
!14 = !{!"_ZTS8timespec", !13, i64 0, !13, i64 8}
!15 = !{!12, !13, i64 8}
!16 = !{!12, !13, i64 48}
!17 = !{!12, !13, i64 88}


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