; LLVM IR from clibs/clib :: deps/copy (copy)

; 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.tinydir_dir = type { [4096 x i8], i32, i64, ptr, ptr, ptr }
%struct.tinydir_file = type { [4096 x i8], [256 x i8], ptr, i32, i32, %struct.stat }
%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 }

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @copy_dir(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca %struct.tinydir_dir, align 8
  %7 = alloca %struct.tinydir_file, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4136, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4512, ptr %7) #4
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = call i32 @tinydir_open(ptr noundef %6, ptr noundef %8)
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  call void @check_dir(ptr noundef %10)
  br label %11

11:                                               ; preds = %40, %2
  %12 = getelementptr inbounds %struct.tinydir_dir, ptr %6, i32 0, i32 1
  %13 = load i32, ptr %12, align 8, !tbaa !11
  %14 = icmp ne i32 %13, 0
  br i1 %14, label %15, label %41

15:                                               ; preds = %11
  %16 = call i32 @tinydir_readfile(ptr noundef %6, ptr noundef %7)
  store i32 %16, ptr %5, align 4, !tbaa !9
  %17 = icmp ne i32 0, %16
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  br label %41

19:                                               ; preds = %15
  %20 = getelementptr inbounds %struct.tinydir_file, ptr %7, i32 0, i32 1
  %21 = getelementptr inbounds [256 x i8], ptr %20, i64 0, i64 0
  %22 = call i32 @strcmp(ptr noundef @.str, ptr noundef %21) #5
  %23 = icmp eq i32 0, %22
  br i1 %23, label %29, label %24

24:                                               ; preds = %19
  %25 = getelementptr inbounds %struct.tinydir_file, ptr %7, i32 0, i32 1
  %26 = getelementptr inbounds [256 x i8], ptr %25, i64 0, i64 0
  %27 = call i32 @strcmp(ptr noundef @.str.1, ptr noundef %26) #5
  %28 = icmp eq i32 0, %27
  br i1 %28, label %29, label %30

29:                                               ; preds = %24, %19
  br label %36

30:                                               ; preds = %24
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = call i32 @copy(ptr noundef byval(%struct.tinydir_file) align 8 %7, ptr noundef %31)
  store i32 %32, ptr %5, align 4, !tbaa !9
  %33 = icmp ne i32 0, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %30
  br label %41

35:                                               ; preds = %30
  br label %36

36:                                               ; preds = %35, %29
  %37 = call i32 @tinydir_next(ptr noundef %6)
  store i32 %37, ptr %5, align 4, !tbaa !9
  %38 = icmp ne i32 0, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  br label %41

40:                                               ; preds = %36
  br label %11, !llvm.loop !14

41:                                               ; preds = %39, %34, %18, %11
  call void @tinydir_close(ptr noundef %6)
  %42 = load i32, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4512, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4136, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret i32 %42
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tinydir_open(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden void @check_dir(ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tinydir_readfile(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @copy(ptr noundef byval(%struct.tinydir_file) align 8, ptr noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tinydir_next(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @tinydir_close(ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { inlinehint 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 willreturn memory(read) "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(read) }

!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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 4096}
!12 = !{!"tinydir_dir", !7, i64 0, !10, i64 4096, !13, i64 4104, !6, i64 4112, !6, i64 4120, !6, i64 4128}
!13 = !{!"long", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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"

%struct.tinydir_dir = type { [4096 x i8], i32, i64, ptr, ptr, ptr }
%struct.tinydir_file = type { [4096 x i8], [256 x i8], ptr, i32, i32, %struct.stat }
%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 }

@.str = external hidden unnamed_addr constant [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: nounwind uwtable
define dso_local i32 @copy_dir(ptr noundef %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca %struct.tinydir_dir, align 8
  %4 = alloca %struct.tinydir_file, align 8
  call void @llvm.lifetime.start.p0(i64 4136, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 4512, ptr nonnull %4) #4
  %5 = call i32 @tinydir_open(ptr noundef nonnull %3, ptr noundef %0)
  call void @check_dir(ptr noundef %1)
  %.old = getelementptr inbounds i8, ptr %3, i64 4096
  %.old1 = load i32, ptr %.old, align 8, !tbaa !5
  %.old2.not = icmp eq i32 %.old1, 0
  br i1 %.old2.not, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %2
  %6 = getelementptr inbounds i8, ptr %4, i64 4096
  br label %7

7:                                                ; preds = %.preheader, %17
  %8 = call i32 @tinydir_readfile(ptr noundef nonnull %3, ptr noundef nonnull %4)
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %.loopexit

9:                                                ; preds = %7
  %10 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str, ptr noundef nonnull dereferenceable(1) %6) #5
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %17, label %12

12:                                               ; preds = %9
  %13 = call i32 @strcmp(ptr noundef nonnull dereferenceable(1) @.str.1, ptr noundef nonnull dereferenceable(1) %6) #5
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %17, label %15

15:                                               ; preds = %12
  %16 = call i32 @copy(ptr noundef nonnull byval(%struct.tinydir_file) align 8 %4, ptr noundef %1)
  %.not7 = icmp eq i32 %16, 0
  br i1 %.not7, label %17, label %.loopexit

17:                                               ; preds = %15, %9, %12
  %18 = call i32 @tinydir_next(ptr noundef nonnull %3)
  %19 = icmp eq i32 %18, 0
  %20 = load i32, ptr %.old, align 8
  %21 = icmp ne i32 %20, 0
  %or.cond = select i1 %19, i1 %21, i1 false
  br i1 %or.cond, label %7, label %.loopexit, !llvm.loop !12

.loopexit:                                        ; preds = %17, %15, %7, %2
  %.0 = phi i32 [ 0, %2 ], [ %16, %15 ], [ %18, %17 ], [ %8, %7 ]
  call void @tinydir_close(ptr noundef nonnull %3)
  call void @llvm.lifetime.end.p0(i64 4512, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4136, ptr nonnull %3) #4
  ret i32 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tinydir_open(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden void @check_dir(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tinydir_readfile(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden i32 @copy(ptr noundef byval(%struct.tinydir_file) align 8, ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @tinydir_next(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @tinydir_close(ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { inlinehint 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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(read) }

!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, !9, i64 4096}
!6 = !{!"tinydir_dir", !7, i64 0, !9, i64 4096, !10, i64 4104, !11, i64 4112, !11, i64 4120, !11, i64 4128}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!"any pointer", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass