; LLVM IR from ctlst-tech/catpilot :: os/fatfs/fsa (node)

; 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.node = type { [64 x i8], %struct.file_operations, ptr, ptr, ptr }
%struct.file_operations = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@root_node = external hidden global %struct.node, align 8
@FreeRTOS_errno = external global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local ptr @node_find(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %2
  store i32 22, ptr @FreeRTOS_errno, align 4, !tbaa !9
  store ptr null, ptr %3, align 8
  br label %43

14:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store ptr @root_node, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  store ptr null, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  store ptr null, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #2
  br label %15

15:                                               ; preds = %34, %14
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = call ptr @node_get_token(ptr noundef %16, ptr noundef %9, ptr noundef %8)
  store ptr %17, ptr %10, align 8, !tbaa !5
  %18 = icmp ne ptr %17, null
  br i1 %18, label %19, label %36

19:                                               ; preds = %15
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.node, ptr %20, i32 0, i32 4
  %22 = load ptr, ptr %21, align 8, !tbaa !11
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = load i64, ptr %9, align 8, !tbaa !14
  %25 = call ptr @node_find_sibling(ptr noundef %22, ptr noundef %23, i64 noundef %24)
  store ptr %25, ptr %6, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %34

28:                                               ; preds = %19
  %29 = load i32, ptr %5, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %33

31:                                               ; preds = %28
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %32, ptr %6, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %31, %28
  br label %36

34:                                               ; preds = %19
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %35, ptr %7, align 8, !tbaa !5
  br label %15, !llvm.loop !16

36:                                               ; preds = %33, %15
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = icmp eq ptr %37, null
  br i1 %38, label %39, label %40

39:                                               ; preds = %36
  store i32 2, ptr @FreeRTOS_errno, align 4, !tbaa !9
  br label %41

40:                                               ; preds = %36
  store i32 0, ptr @FreeRTOS_errno, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %40, %39
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %42, ptr %3, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  br label %43

43:                                               ; preds = %41, %13
  %44 = load ptr, ptr %3, align 8
  ret ptr %44
}

; 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 ptr @node_get_token(ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden ptr @node_find_sibling(ptr noundef, ptr noundef, i64 noundef) #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 }

!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 168}
!12 = !{!"node", !7, i64 0, !13, i64 64, !6, i64 152, !6, i64 160, !6, i64 168}
!13 = !{!"file_operations", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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.node = type { [64 x i8], %struct.file_operations, ptr, ptr, ptr }
%struct.file_operations = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@root_node = external hidden global %struct.node, align 8
@FreeRTOS_errno = external local_unnamed_addr global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local ptr @node_find(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = icmp eq ptr %0, null
  br i1 %5, label %6, label %7

6:                                                ; preds = %2
  store i32 22, ptr @FreeRTOS_errno, align 4, !tbaa !5
  br label %19

7:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #2
  store ptr null, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #2
  br label %8

8:                                                ; preds = %10, %7
  %.011 = phi ptr [ @root_node, %7 ], [ %14, %10 ]
  %.010 = phi ptr [ null, %7 ], [ %14, %10 ]
  %9 = call ptr @node_get_token(ptr noundef nonnull %0, ptr noundef nonnull %4, ptr noundef nonnull %3)
  %.not = icmp eq ptr %9, null
  br i1 %.not, label %.loopexit, label %10

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %.011, i64 168
  %12 = load ptr, ptr %11, align 8, !tbaa !11
  %13 = load i64, ptr %4, align 8, !tbaa !14
  %14 = call ptr @node_find_sibling(ptr noundef %12, ptr noundef nonnull %9, i64 noundef %13)
  %15 = icmp eq ptr %14, null
  br i1 %15, label %16, label %8, !llvm.loop !16

16:                                               ; preds = %10
  %17 = icmp eq i32 %1, 0
  %spec.select = select i1 %17, ptr %.010, ptr null
  br label %.loopexit

.loopexit:                                        ; preds = %8, %16
  %.1 = phi ptr [ %spec.select, %16 ], [ %.011, %8 ]
  %18 = icmp eq ptr %.1, null
  %. = select i1 %18, i32 2, i32 0
  store i32 %., ptr @FreeRTOS_errno, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #2
  br label %19

19:                                               ; preds = %.loopexit, %6
  %.0 = phi ptr [ null, %6 ], [ %.1, %.loopexit ]
  ret ptr %.0
}

; Function Attrs: mustprogress 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 ptr @node_get_token(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden ptr @node_find_sibling(ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !10, i64 168}
!12 = !{!"node", !7, i64 0, !13, i64 64, !10, i64 152, !10, i64 160, !10, i64 168}
!13 = !{!"file_operations", !10, i64 0, !10, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass