; LLVM IR from yinqiwen/ardb :: src/common/util (file_helper)

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

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

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

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

declare i32 @open(ptr noundef, i32 noundef, ...) #2

declare i32 @close(i32 noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #3

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4ardb9file_copyERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) #4 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca [4096 x i8], align 16
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4096, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %14) #6
  %16 = call i32 (ptr, i32, ...) @open(ptr noundef %15, i32 noundef 0)
  store i32 %16, ptr %7, align 4, !tbaa !9
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = icmp slt i32 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %92

20:                                               ; preds = %2
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %21) #6
  %23 = call i32 @remove(ptr noundef %22) #6
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %24) #6
  %26 = call i32 (ptr, i32, ...) @open(ptr noundef %25, i32 noundef 193, i32 noundef 438)
  store i32 %26, ptr %6, align 4, !tbaa !9
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %20
  br label %79

30:                                               ; preds = %20
  br label %31

31:                                               ; preds = %66, %30
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = getelementptr inbounds [4096 x i8], ptr %8, i64 0, i64 0
  %34 = call i64 @read(i32 noundef %32, ptr noundef %33, i64 noundef 4096)
  store i64 %34, ptr %9, align 8, !tbaa !11
  %35 = load i64, ptr %9, align 8, !tbaa !11
  %36 = icmp sgt i64 %35, 0
  br i1 %36, label %37, label %67

37:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %38 = getelementptr inbounds [4096 x i8], ptr %8, i64 0, i64 0
  store ptr %38, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  br label %39

39:                                               ; preds = %60, %37
  %40 = load i32, ptr %6, align 4, !tbaa !9
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = load i64, ptr %9, align 8, !tbaa !11
  %43 = call i64 @write(i32 noundef %40, ptr noundef %41, i64 noundef %42)
  store i64 %43, ptr %13, align 8, !tbaa !11
  %44 = load i64, ptr %13, align 8, !tbaa !11
  %45 = icmp sge i64 %44, 0
  br i1 %45, label %46, label %53

46:                                               ; preds = %39
  %47 = load i64, ptr %13, align 8, !tbaa !11
  %48 = load i64, ptr %9, align 8, !tbaa !11
  %49 = sub nsw i64 %48, %47
  store i64 %49, ptr %9, align 8, !tbaa !11
  %50 = load i64, ptr %13, align 8, !tbaa !11
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i64 %50
  store ptr %52, ptr %12, align 8, !tbaa !5
  br label %59

53:                                               ; preds = %39
  %54 = call ptr @__errno_location() #7
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = icmp ne i32 %55, 4
  br i1 %56, label %57, label %58

57:                                               ; preds = %53
  store i32 2, ptr %11, align 4
  br label %64

58:                                               ; preds = %53
  br label %59

59:                                               ; preds = %58, %46
  br label %60

60:                                               ; preds = %59
  %61 = load i64, ptr %9, align 8, !tbaa !11
  %62 = icmp sgt i64 %61, 0
  br i1 %62, label %39, label %63, !llvm.loop !13

63:                                               ; preds = %60
  store i32 0, ptr %11, align 4
  br label %64

64:                                               ; preds = %63, %57
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  %65 = load i32, ptr %11, align 4
  switch i32 %65, label %92 [
    i32 0, label %66
    i32 2, label %79
  ]

66:                                               ; preds = %64
  br label %31, !llvm.loop !15

67:                                               ; preds = %31
  %68 = load i64, ptr %9, align 8, !tbaa !11
  %69 = icmp eq i64 %68, 0
  br i1 %69, label %70, label %78

70:                                               ; preds = %67
  %71 = load i32, ptr %6, align 4, !tbaa !9
  %72 = call i32 @close(i32 noundef %71)
  %73 = icmp slt i32 %72, 0
  br i1 %73, label %74, label %75

74:                                               ; preds = %70
  store i32 -1, ptr %6, align 4, !tbaa !9
  br label %79

75:                                               ; preds = %70
  %76 = load i32, ptr %7, align 4, !tbaa !9
  %77 = call i32 @close(i32 noundef %76)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %92

78:                                               ; preds = %67
  br label %79

79:                                               ; preds = %78, %74, %64, %29
  %80 = call ptr @__errno_location() #7
  %81 = load i32, ptr %80, align 4, !tbaa !9
  store i32 %81, ptr %10, align 4, !tbaa !9
  %82 = load i32, ptr %7, align 4, !tbaa !9
  %83 = call i32 @close(i32 noundef %82)
  %84 = load i32, ptr %6, align 4, !tbaa !9
  %85 = icmp sge i32 %84, 0
  br i1 %85, label %86, label %89

86:                                               ; preds = %79
  %87 = load i32, ptr %6, align 4, !tbaa !9
  %88 = call i32 @close(i32 noundef %87)
  br label %89

89:                                               ; preds = %86, %79
  %90 = load i32, ptr %10, align 4, !tbaa !9
  %91 = call ptr @__errno_location() #7
  store i32 %90, ptr %91, align 4, !tbaa !9
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %92

92:                                               ; preds = %89, %75, %64, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4096, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %93 = load i32, ptr %3, align 4
  ret i32 %93
}

; Function Attrs: nounwind
declare i32 @remove(ptr noundef) #5

declare i64 @read(i32 noundef, ptr noundef, i64 noundef) #2

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #2

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


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

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

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

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

declare i32 @close(i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN4ardb9file_copyERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(32) %1) local_unnamed_addr #5 {
  %3 = alloca [4096 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %3) #7
  %4 = tail call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #7
  %5 = tail call i32 (ptr, i32, ...) @open(ptr noundef %4, i32 noundef 0)
  %6 = icmp slt i32 %5, 0
  br i1 %6, label %40, label %7

7:                                                ; preds = %2
  %8 = tail call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #7
  %9 = tail call i32 @remove(ptr noundef %8) #7
  %10 = tail call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) %1) #7
  %11 = tail call i32 (ptr, i32, ...) @open(ptr noundef %10, i32 noundef 193, i32 noundef 438)
  %12 = icmp slt i32 %11, 0
  br i1 %12, label %.thread, label %.preheader37

.preheader37:                                     ; preds = %7
  %13 = call i64 @read(i32 noundef %5, ptr noundef nonnull %3, i64 noundef 4096)
  %14 = icmp sgt i64 %13, 0
  br i1 %14, label %.preheader, label %._crit_edge

.loopexit:                                        ; preds = %25
  %15 = call i64 @read(i32 noundef %5, ptr noundef nonnull %3, i64 noundef 4096)
  %16 = icmp sgt i64 %15, 0
  br i1 %16, label %.preheader.backedge, label %._crit_edge

.preheader:                                       ; preds = %.preheader37, %.preheader.backedge
  %.027 = phi i64 [ %.027.be, %.preheader.backedge ], [ %13, %.preheader37 ]
  %.024 = phi ptr [ %.024.be, %.preheader.backedge ], [ %3, %.preheader37 ]
  %17 = call i64 @write(i32 noundef %11, ptr noundef %.024, i64 noundef %.027)
  %18 = icmp sgt i64 %17, -1
  br i1 %18, label %19, label %22

19:                                               ; preds = %.preheader
  %20 = sub nsw i64 %.027, %17
  %21 = getelementptr inbounds i8, ptr %.024, i64 %17
  br label %25

22:                                               ; preds = %.preheader
  %23 = tail call ptr @__errno_location() #8
  %24 = load i32, ptr %23, align 4, !tbaa !5
  %.not = icmp eq i32 %24, 4
  br i1 %.not, label %25, label %.thread

25:                                               ; preds = %19, %22
  %.128 = phi i64 [ %20, %19 ], [ %.027, %22 ]
  %.1 = phi ptr [ %21, %19 ], [ %.024, %22 ]
  %26 = icmp sgt i64 %.128, 0
  br i1 %26, label %.preheader.backedge, label %.loopexit

.preheader.backedge:                              ; preds = %25, %.loopexit
  %.027.be = phi i64 [ %.128, %25 ], [ %15, %.loopexit ]
  %.024.be = phi ptr [ %.1, %25 ], [ %3, %.loopexit ]
  br label %.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %.loopexit, %.preheader37
  %.lcssa = phi i64 [ %13, %.preheader37 ], [ %15, %.loopexit ]
  %27 = icmp eq i64 %.lcssa, 0
  br i1 %27, label %28, label %.thread

28:                                               ; preds = %._crit_edge
  %29 = tail call i32 @close(i32 noundef %11)
  %30 = icmp slt i32 %29, 0
  br i1 %30, label %.thread, label %31

31:                                               ; preds = %28
  %32 = tail call i32 @close(i32 noundef %5)
  br label %40

.thread:                                          ; preds = %22, %28, %._crit_edge, %7
  %.026 = phi i32 [ %11, %7 ], [ %11, %._crit_edge ], [ -1, %28 ], [ %11, %22 ]
  %33 = tail call ptr @__errno_location() #8
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = tail call i32 @close(i32 noundef %5)
  %36 = icmp sgt i32 %.026, -1
  br i1 %36, label %37, label %39

37:                                               ; preds = %.thread
  %38 = tail call i32 @close(i32 noundef %.026)
  br label %39

39:                                               ; preds = %37, %.thread
  store i32 %34, ptr %33, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %2, %39, %31
  %.0 = phi i32 [ -1, %39 ], [ 0, %31 ], [ -1, %2 ]
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %3) #7
  ret i32 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @remove(ptr nocapture noundef readonly) local_unnamed_addr #6

; Function Attrs: nofree
declare noundef i64 @read(i32 noundef, ptr nocapture noundef, i64 noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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" }
attributes #2 = { nofree "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 = { "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 = { 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 #5 = { 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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