; LLVM IR from artagnon/phoenixfs :: persist (load_dr_tree)

; 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.dir_record = type { [4096 x i8], ptr }

@path_buf = external dso_local global [4096 x i8], align 16
@.str = external hidden unnamed_addr constant [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [27 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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

declare i32 @fclose(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 uwtable
declare dso_local ptr @load_vfr_tree(ptr noundef) #3

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #1

declare void @die(ptr noundef, ...) #1

declare ptr @insert(ptr noundef, i16 noundef zeroext, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @load_dr_tree(ptr noundef %0) #3 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i16, align 2
  %7 = alloca i16, align 2
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 2, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 2, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 2, ptr %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store ptr null, ptr %3, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 2 %6, i8 0, i64 2, i1 false)
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = call i64 @fread(ptr noundef %6, i64 noundef 2, i64 noundef 1, ptr noundef %10)
  %12 = icmp ult i64 %11, 1
  br i1 %12, label %13, label %14

13:                                               ; preds = %1
  call void (ptr, ...) @die(ptr noundef @.str.3)
  br label %14

14:                                               ; preds = %13, %1
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %15

15:                                               ; preds = %57, %14
  %16 = load i32, ptr %8, align 4, !tbaa !9
  %17 = load i16, ptr %6, align 2, !tbaa !11
  %18 = zext i16 %17 to i32
  %19 = icmp slt i32 %16, %18
  br i1 %19, label %20, label %60

20:                                               ; preds = %15
  call void @llvm.memset.p0.i64(ptr align 2 %5, i8 0, i64 2, i1 false)
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = call i64 @fread(ptr noundef %5, i64 noundef 2, i64 noundef 1, ptr noundef %21)
  %23 = icmp ult i64 %22, 1
  br i1 %23, label %24, label %25

24:                                               ; preds = %20
  call void (ptr, ...) @die(ptr noundef @.str.4)
  br label %25

25:                                               ; preds = %24, %20
  call void @llvm.memset.p0.i64(ptr align 2 %7, i8 0, i64 2, i1 false)
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = call i64 @fread(ptr noundef %7, i64 noundef 2, i64 noundef 1, ptr noundef %26)
  %28 = icmp ult i64 %27, 1
  br i1 %28, label %29, label %30

29:                                               ; preds = %25
  call void (ptr, ...) @die(ptr noundef @.str.5)
  br label %30

30:                                               ; preds = %29, %25
  call void @llvm.memset.p0.i64(ptr align 16 @path_buf, i8 0, i64 4096, i1 false)
  %31 = load i16, ptr %7, align 2, !tbaa !11
  %32 = zext i16 %31 to i64
  %33 = mul i64 %32, 1
  %34 = load ptr, ptr %2, align 8, !tbaa !5
  %35 = call i64 @fread(ptr noundef @path_buf, i64 noundef %33, i64 noundef 1, ptr noundef %34)
  %36 = icmp ult i64 %35, 1
  br i1 %36, label %37, label %38

37:                                               ; preds = %30
  call void (ptr, ...) @die(ptr noundef @.str.6)
  br label %38

38:                                               ; preds = %37, %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %39 = call noalias ptr @fopen(ptr noundef @.str, ptr noundef @.str.1)
  store ptr %39, ptr %9, align 8, !tbaa !5
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = icmp ne ptr %40, null
  br i1 %41, label %42, label %47

42:                                               ; preds = %38
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %43, ptr noundef @.str.10, i32 noundef 247, ptr noundef @path_buf) #5
  %45 = load ptr, ptr %9, align 8, !tbaa !5
  %46 = call i32 @fclose(ptr noundef %45)
  br label %47

47:                                               ; preds = %42, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  %48 = call ptr @make_dr(ptr noundef @path_buf)
  store ptr %48, ptr %4, align 8, !tbaa !5
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = load i16, ptr %5, align 2, !tbaa !11
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = call ptr @insert(ptr noundef %49, i16 noundef zeroext %50, ptr noundef %51)
  store ptr %52, ptr %3, align 8, !tbaa !5
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = call ptr @load_vfr_tree(ptr noundef %53)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.dir_record, ptr %55, i32 0, i32 1
  store ptr %54, ptr %56, align 8, !tbaa !13
  br label %57

57:                                               ; preds = %47
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %8, align 4, !tbaa !9
  br label %15, !llvm.loop !15

60:                                               ; preds = %15
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr %6) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  ret ptr %61
}

declare ptr @make_dr(ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !6, i64 4096}
!14 = !{!"dir_record", !7, i64 0, !6, i64 4096}
!15 = distinct !{!15, !16}
!16 = !{!"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"

@path_buf = external dso_local global [4096 x i8], align 16
@.str = external hidden unnamed_addr constant [19 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [16 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [21 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [27 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: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) 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: nounwind uwtable
declare dso_local ptr @load_vfr_tree(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #1

declare void @die(ptr noundef, ...) local_unnamed_addr #4

declare ptr @insert(ptr noundef, i16 noundef zeroext, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
define dso_local ptr @load_dr_tree(ptr noundef %0) local_unnamed_addr #2 {
  %2 = alloca i16, align 2
  %3 = alloca i16, align 2
  %4 = alloca i16, align 2
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %2) #5
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %3) #5
  call void @llvm.lifetime.start.p0(i64 2, ptr nonnull %4) #5
  store i16 0, ptr %3, align 2
  %5 = call i64 @fread(ptr noundef nonnull %3, i64 noundef 2, i64 noundef 1, ptr noundef %0)
  %6 = icmp eq i64 %5, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %1
  tail call void (ptr, ...) @die(ptr noundef nonnull @.str.3) #5
  br label %8

8:                                                ; preds = %7, %1
  %9 = load i16, ptr %3, align 2, !tbaa !5
  %10 = zext i16 %9 to i32
  %.not17 = icmp eq i16 %9, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8, %29
  %.016 = phi ptr [ %32, %29 ], [ null, %8 ]
  %.01315 = phi i32 [ %35, %29 ], [ 0, %8 ]
  store i16 0, ptr %2, align 2
  %11 = call i64 @fread(ptr noundef nonnull %2, i64 noundef 2, i64 noundef 1, ptr noundef %0)
  %12 = icmp eq i64 %11, 0
  br i1 %12, label %13, label %14

13:                                               ; preds = %.lr.ph
  tail call void (ptr, ...) @die(ptr noundef nonnull @.str.4) #5
  br label %14

14:                                               ; preds = %13, %.lr.ph
  store i16 0, ptr %4, align 2
  %15 = call i64 @fread(ptr noundef nonnull %4, i64 noundef 2, i64 noundef 1, ptr noundef %0)
  %16 = icmp eq i64 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %14
  tail call void (ptr, ...) @die(ptr noundef nonnull @.str.5) #5
  br label %18

18:                                               ; preds = %17, %14
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4096) @path_buf, i8 0, i64 4096, i1 false)
  %19 = load i16, ptr %4, align 2, !tbaa !5
  %20 = zext i16 %19 to i64
  %21 = tail call i64 @fread(ptr noundef nonnull @path_buf, i64 noundef %20, i64 noundef 1, ptr noundef %0)
  %22 = icmp eq i64 %21, 0
  br i1 %22, label %23, label %24

23:                                               ; preds = %18
  tail call void (ptr, ...) @die(ptr noundef nonnull @.str.6) #5
  br label %24

24:                                               ; preds = %23, %18
  %25 = tail call noalias ptr @fopen(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1)
  %.not = icmp eq ptr %25, null
  br i1 %.not, label %29, label %26

26:                                               ; preds = %24
  %27 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef nonnull %25, ptr noundef nonnull @.str.10, i32 noundef 247, ptr noundef nonnull @path_buf) #5
  %28 = tail call i32 @fclose(ptr noundef nonnull %25)
  br label %29

29:                                               ; preds = %26, %24
  %30 = tail call ptr @make_dr(ptr noundef nonnull @path_buf) #5
  %31 = load i16, ptr %2, align 2, !tbaa !5
  %32 = tail call ptr @insert(ptr noundef %.016, i16 noundef zeroext %31, ptr noundef %30) #5
  %33 = tail call ptr @load_vfr_tree(ptr noundef %0)
  %34 = getelementptr inbounds i8, ptr %30, i64 4096
  store ptr %33, ptr %34, align 8, !tbaa !9
  %35 = add nuw nsw i32 %.01315, 1
  %exitcond.not = icmp eq i32 %35, %10
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %29, %8
  %.0.lcssa = phi ptr [ null, %8 ], [ %32, %29 ]
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %4) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 2, ptr nonnull %2) #5
  ret ptr %.0.lcssa
}

declare ptr @make_dr(ptr noundef) local_unnamed_addr #4

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

!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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !11, i64 4096}
!10 = !{!"dir_record", !7, i64 0, !11, i64 4096}
!11 = !{!"any pointer", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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