; LLVM IR from wumo/vkg :: src/par/test (test_filecache)

; 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.filecache_table_t = type { [64 x %struct.filecache_entry_t], i32, i32 }
%struct.filecache_entry_t = type { i64, i64, ptr, i32 }

@_fileprefix = external hidden global [4096 x i8], align 16
@_tablepath = external hidden global [4096 x i8], align 16
@_table = external hidden global ptr, align 8

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

; Function Attrs: nounwind
declare ptr @strcpy(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare ptr @strcat(ptr noundef, ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @par_filecache_evict_all() #2 {
  %1 = alloca [4096 x i8], align 16
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4096, ptr %1) #3
  %4 = load ptr, ptr @_table, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  br i1 %5, label %7, label %6

6:                                                ; preds = %0
  call void @_read_or_create_tablefile()
  br label %7

7:                                                ; preds = %6, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #3
  %8 = load ptr, ptr @_table, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.filecache_table_t, ptr %8, i32 0, i32 0
  %10 = getelementptr inbounds [64 x %struct.filecache_entry_t], ptr %9, i64 0, i64 0
  store ptr %10, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #3
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %28, %7
  %12 = load i32, ptr %3, align 4, !tbaa !9
  %13 = load ptr, ptr @_table, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.filecache_table_t, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = icmp slt i32 %12, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #3
  br label %33

18:                                               ; preds = %11
  %19 = getelementptr inbounds [4096 x i8], ptr %1, i64 0, i64 0
  %20 = call ptr @strcpy(ptr noundef %19, ptr noundef @_fileprefix) #3
  %21 = getelementptr inbounds [4096 x i8], ptr %1, i64 0, i64 0
  %22 = load ptr, ptr %2, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.filecache_entry_t, ptr %22, i32 0, i32 2
  %24 = load ptr, ptr %23, align 8, !tbaa !13
  %25 = call ptr @strcat(ptr noundef %21, ptr noundef %24) #3
  %26 = getelementptr inbounds [4096 x i8], ptr %1, i64 0, i64 0
  %27 = call i32 @remove(ptr noundef %26) #3
  br label %28

28:                                               ; preds = %18
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = add nsw i32 %29, 1
  store i32 %30, ptr %3, align 4, !tbaa !9
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.filecache_entry_t, ptr %31, i32 1
  store ptr %32, ptr %2, align 8, !tbaa !5
  br label %11, !llvm.loop !16

33:                                               ; preds = %17
  %34 = load ptr, ptr @_table, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.filecache_table_t, ptr %34, i32 0, i32 1
  store i32 0, ptr %35, align 8, !tbaa !11
  %36 = load ptr, ptr @_table, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.filecache_table_t, ptr %36, i32 0, i32 2
  store i32 0, ptr %37, align 4, !tbaa !18
  %38 = call i32 @remove(ptr noundef @_tablepath) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #3
  call void @llvm.lifetime.end.p0(i64 4096, ptr %1) #3
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @_read_or_create_tablefile() #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 2048}
!12 = !{!"", !7, i64 0, !10, i64 2048, !10, i64 2052}
!13 = !{!14, !6, i64 16}
!14 = !{!"", !15, i64 0, !15, i64 8, !6, i64 16, !10, i64 24}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!12, !10, i64 2052}


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

@_fileprefix = external hidden global [4096 x i8], align 16
@_tablepath = external hidden global [4096 x i8], align 16
@_table = external hidden local_unnamed_addr global ptr, align 8

; 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 nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcat(ptr noalias noundef returned, ptr noalias nocapture noundef readonly) local_unnamed_addr #1

; 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 nounwind
declare noundef i32 @remove(ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @par_filecache_evict_all() local_unnamed_addr #3 {
  %1 = alloca [4096 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %1) #4
  %2 = load ptr, ptr @_table, align 8, !tbaa !5
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %3, label %4

3:                                                ; preds = %0
  tail call void @_read_or_create_tablefile()
  %.pre = load ptr, ptr @_table, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %3, %0
  %5 = phi ptr [ %.pre, %3 ], [ %2, %0 ]
  %6 = getelementptr inbounds i8, ptr %5, i64 2048
  %7 = load i32, ptr %6, align 8, !tbaa !9
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %4
  %.lcssa5 = phi ptr [ %5, %4 ], [ %19, %.lr.ph ]
  %9 = getelementptr inbounds i8, ptr %.lcssa5, i64 2048
  store i32 0, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %.lcssa5, i64 2052
  store i32 0, ptr %10, align 4, !tbaa !12
  %11 = call i32 @remove(ptr noundef nonnull @_tablepath) #4
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %1) #4
  ret void

.lr.ph:                                           ; preds = %4, %.lr.ph
  %.07 = phi i32 [ %17, %.lr.ph ], [ 0, %4 ]
  %.036 = phi ptr [ %18, %.lr.ph ], [ %5, %4 ]
  %12 = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @_fileprefix) #4
  %13 = getelementptr inbounds i8, ptr %.036, i64 16
  %14 = load ptr, ptr %13, align 8, !tbaa !13
  %15 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) %14) #4
  %16 = call i32 @remove(ptr noundef nonnull %1) #4
  %17 = add nuw nsw i32 %.07, 1
  %18 = getelementptr inbounds i8, ptr %.036, i64 32
  %19 = load ptr, ptr @_table, align 8, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %19, i64 2048
  %21 = load i32, ptr %20, align 8, !tbaa !9
  %22 = icmp slt i32 %17, %21
  br i1 %22, label %.lr.ph, label %._crit_edge, !llvm.loop !16
}

; Function Attrs: nounwind uwtable
declare hidden void @_read_or_create_tablefile() local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 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 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 #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/C++ TBAA"}
!9 = !{!10, !11, i64 2048}
!10 = !{!"", !7, i64 0, !11, i64 2048, !11, i64 2052}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 2052}
!13 = !{!14, !6, i64 16}
!14 = !{!"", !15, i64 0, !15, i64 8, !6, i64 16, !11, i64 24}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


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