; LLVM IR from narke/Aragveli :: src/extra/fs (tarfs)

; 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.anon = type { ptr, ptr }
%struct.node = type { i8, i8, [50 x i8], %union.anon, %struct.anon.1 }
%union.anon = type { %struct.folder }
%struct.folder = type { ptr, %struct.anon.0 }
%struct.anon.0 = type { ptr }
%struct.anon.1 = type { ptr, ptr }
%struct.path_node = type { [50 x i8], %struct.anon.2 }
%struct.anon.2 = type { ptr }

@path_nodes = external dso_local global %struct.anon, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @resolve_node(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, 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 8, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  %9 = load ptr, ptr %3, align 8, !tbaa !5
  %10 = call i32 @path_nodes_to_list(ptr noundef %9)
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %11, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %12 = load ptr, ptr @path_nodes, align 8, !tbaa !11
  store ptr %12, ptr %8, align 8, !tbaa !5
  br label %13

13:                                               ; preds = %52, %2
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %57

16:                                               ; preds = %13
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.node, ptr %17, i32 0, i32 3
  %19 = getelementptr inbounds %struct.folder, ptr %18, i32 0, i32 1
  %20 = getelementptr inbounds %struct.anon.0, ptr %19, i32 0, i32 0
  %21 = load ptr, ptr %20, align 8, !tbaa !13
  store ptr %21, ptr %6, align 8, !tbaa !5
  br label %22

22:                                               ; preds = %42, %16
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = icmp ne ptr %23, null
  br i1 %24, label %25, label %47

25:                                               ; preds = %22
  %26 = load ptr, ptr %8, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.path_node, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds [50 x i8], ptr %27, i64 0, i64 0
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.node, ptr %29, i32 0, i32 2
  %31 = getelementptr inbounds [50 x i8], ptr %30, i64 0, i64 0
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.path_node, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds [50 x i8], ptr %33, i64 0, i64 0
  %35 = call i64 @strnlen(ptr noundef %34, i64 noundef 50)
  %36 = add i64 %35, 1
  %37 = call i32 @strncmp(ptr noundef %28, ptr noundef %31, i64 noundef %36) #4
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %41

39:                                               ; preds = %25
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %40, ptr %5, align 8, !tbaa !5
  store i32 1, ptr %7, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %39, %25
  br label %42

42:                                               ; preds = %41
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.node, ptr %43, i32 0, i32 4
  %45 = getelementptr inbounds %struct.anon.1, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !14
  store ptr %46, ptr %6, align 8, !tbaa !5
  br label %22, !llvm.loop !16

47:                                               ; preds = %22
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %51, label %50

50:                                               ; preds = %47
  store ptr null, ptr %5, align 8, !tbaa !5
  br label %57

51:                                               ; preds = %47
  br label %52

52:                                               ; preds = %51
  %53 = load ptr, ptr %8, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.path_node, ptr %53, i32 0, i32 1
  %55 = getelementptr inbounds %struct.anon.2, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !18
  store ptr %56, ptr %8, align 8, !tbaa !5
  br label %13, !llvm.loop !21

57:                                               ; preds = %50, %13
  %58 = call i32 @path_nodes_list_delete()
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret ptr %59
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @path_nodes_to_list(ptr noundef) #0

; Function Attrs: nounwind
declare i32 @strncmp(ptr noundef, ptr noundef, i64 noundef) #2

declare i64 @strnlen(ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden i32 @path_nodes_list_delete() #0

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

attributes #0 = { 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !6, i64 72}
!15 = !{!"node", !7, i64 0, !7, i64 1, !7, i64 2, !7, i64 56, !12, i64 72}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = !{!19, !6, i64 56}
!19 = !{!"path_node", !7, i64 0, !20, i64 56}
!20 = !{!"", !6, i64 0}
!21 = distinct !{!21, !17}


; 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.anon = type { ptr, ptr }

@path_nodes = external dso_local local_unnamed_addr global %struct.anon, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @resolve_node(ptr noundef %0, ptr noundef readonly %1) local_unnamed_addr #0 {
  %3 = tail call i32 @path_nodes_to_list(ptr noundef %0)
  %.026 = load ptr, ptr @path_nodes, align 8, !tbaa !5
  %.not27 = icmp eq ptr %.026, null
  br i1 %.not27, label %._crit_edge33, label %.lr.ph32

4:                                                ; preds = %._crit_edge
  %5 = getelementptr inbounds i8, ptr %.030, i64 56
  %.0 = load ptr, ptr %5, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge33, label %.lr.ph32, !llvm.loop !9

.lr.ph32:                                         ; preds = %2, %4
  %.030 = phi ptr [ %.0, %4 ], [ %.026, %2 ]
  %.01229 = phi i32 [ 1, %4 ], [ 0, %2 ]
  %.01428 = phi ptr [ %.115.lcssa, %4 ], [ %1, %2 ]
  %6 = getelementptr inbounds i8, ptr %.01428, i64 64
  %.01320 = load ptr, ptr %6, align 8, !tbaa !11
  %.not1721 = icmp eq ptr %.01320, null
  br i1 %.not1721, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph32
  %7 = tail call i64 @strnlen(ptr noundef nonnull dereferenceable(1) %.030, i64 noundef 50)
  %8 = add i64 %7, 1
  br label %9

9:                                                ; preds = %.lr.ph, %9
  %.01324 = phi ptr [ %.01320, %.lr.ph ], [ %.013, %9 ]
  %.123 = phi i32 [ %.01229, %.lr.ph ], [ %spec.select19, %9 ]
  %.11522 = phi ptr [ %.01428, %.lr.ph ], [ %spec.select, %9 ]
  %10 = getelementptr inbounds i8, ptr %.01324, i64 2
  %11 = tail call i32 @strncmp(ptr noundef nonnull %.030, ptr noundef nonnull %10, i64 noundef %8) #2
  %12 = icmp eq i32 %11, 0
  %spec.select = select i1 %12, ptr %.01324, ptr %.11522
  %spec.select19 = select i1 %12, i32 1, i32 %.123
  %13 = getelementptr inbounds i8, ptr %.01324, i64 72
  %.013 = load ptr, ptr %13, align 8, !tbaa !11
  %.not17 = icmp eq ptr %.013, null
  br i1 %.not17, label %._crit_edge, label %9, !llvm.loop !12

._crit_edge:                                      ; preds = %9, %.lr.ph32
  %.115.lcssa = phi ptr [ %.01428, %.lr.ph32 ], [ %spec.select, %9 ]
  %.1.lcssa = phi i32 [ %.01229, %.lr.ph32 ], [ %spec.select19, %9 ]
  %.not18 = icmp eq i32 %.1.lcssa, 0
  br i1 %.not18, label %._crit_edge33, label %4

._crit_edge33:                                    ; preds = %4, %._crit_edge, %2
  %.3 = phi ptr [ %1, %2 ], [ null, %._crit_edge ], [ %.115.lcssa, %4 ]
  %14 = tail call i32 @path_nodes_list_delete()
  ret ptr %.3
}

; Function Attrs: nounwind uwtable
declare hidden i32 @path_nodes_to_list(ptr noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strnlen(ptr nocapture noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare hidden i32 @path_nodes_list_delete() local_unnamed_addr #0

attributes #0 = { 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 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 #2 = { 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 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}


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