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

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

@files = external dso_local global [32 x ptr], align 16
@FreeRTOS_errno = external global i32, align 4
@__files = external dso_local global [32 x %struct.file], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @fd_new() #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @fd_delete(i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @fd_check(i32 noundef) #0

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

15:                                               ; preds = %2
  %16 = load ptr, ptr %8, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.node, ptr %16, i32 0, i32 1
  %18 = getelementptr inbounds %struct.file_operations, ptr %17, i32 0, i32 0
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = icmp eq ptr %19, null
  br i1 %20, label %21, label %22

21:                                               ; preds = %15, %2
  store i32 2, ptr @FreeRTOS_errno, align 4, !tbaa !9
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %94

22:                                               ; preds = %15
  %23 = call i32 @fd_new()
  store i32 %23, ptr %6, align 4, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = call i32 @fd_check(i32 noundef %24)
  %26 = icmp ne i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %22
  store i32 2, ptr @FreeRTOS_errno, align 4, !tbaa !9
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %94

28:                                               ; preds = %22
  %29 = load i32, ptr %6, align 4, !tbaa !9
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [32 x %struct.file], ptr @__files, i64 0, i64 %30
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [32 x ptr], ptr @files, i64 0, i64 %33
  store ptr %31, ptr %34, align 8, !tbaa !5
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = load i32, ptr %6, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [32 x ptr], ptr @files, i64 0, i64 %37
  %39 = load ptr, ptr %38, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.file, ptr %39, i32 0, i32 1
  store ptr %35, ptr %40, align 8, !tbaa !14
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = load i32, ptr %6, align 4, !tbaa !9
  %43 = sext i32 %42 to i64
  %44 = getelementptr inbounds [32 x ptr], ptr @files, i64 0, i64 %43
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.file, ptr %45, i32 0, i32 0
  store i32 %41, ptr %46, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.node, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds [64 x i8], ptr %49, i64 0, i64 0
  %51 = call ptr @strstr(ptr noundef %47, ptr noundef %50) #5
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.node, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds [64 x i8], ptr %53, i64 0, i64 0
  %55 = call i64 @strlen(ptr noundef %54) #5
  %56 = getelementptr inbounds i8, ptr %51, i64 %55
  store ptr %56, ptr %10, align 8, !tbaa !5
  br label %57

57:                                               ; preds = %62, %28
  %58 = load ptr, ptr %10, align 8, !tbaa !5
  %59 = load i8, ptr %58, align 1, !tbaa !17
  %60 = sext i8 %59 to i32
  %61 = icmp eq i32 %60, 47
  br i1 %61, label %62, label %65

62:                                               ; preds = %57
  %63 = load ptr, ptr %10, align 8, !tbaa !5
  %64 = getelementptr inbounds i8, ptr %63, i32 1
  store ptr %64, ptr %10, align 8, !tbaa !5
  br label %57, !llvm.loop !18

65:                                               ; preds = %57
  %66 = load i32, ptr %6, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [32 x ptr], ptr @files, i64 0, i64 %67
  %69 = load ptr, ptr %68, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.file, ptr %69, i32 0, i32 1
  %71 = load ptr, ptr %70, align 8, !tbaa !14
  %72 = getelementptr inbounds %struct.node, ptr %71, i32 0, i32 1
  %73 = getelementptr inbounds %struct.file_operations, ptr %72, i32 0, i32 0
  %74 = load ptr, ptr %73, align 8, !tbaa !11
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [32 x ptr], ptr @files, i64 0, i64 %76
  %78 = load ptr, ptr %77, align 8, !tbaa !5
  %79 = load ptr, ptr %10, align 8, !tbaa !5
  %80 = call i32 %74(ptr noundef %78, ptr noundef %79)
  store i32 %80, ptr %7, align 4, !tbaa !9
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = icmp ne i32 %81, 0
  br i1 %82, label %83, label %90

83:                                               ; preds = %65
  %84 = load i32, ptr @FreeRTOS_errno, align 4, !tbaa !9
  %85 = icmp eq i32 %84, 0
  br i1 %85, label %86, label %87

86:                                               ; preds = %83
  store i32 5, ptr @FreeRTOS_errno, align 4, !tbaa !9
  br label %87

87:                                               ; preds = %86, %83
  %88 = load i32, ptr %6, align 4, !tbaa !9
  %89 = call i32 @fd_delete(i32 noundef %88)
  store i32 -1, ptr %7, align 4, !tbaa !9
  br label %92

90:                                               ; preds = %65
  store i32 0, ptr @FreeRTOS_errno, align 4, !tbaa !9
  %91 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %91, ptr %7, align 4, !tbaa !9
  br label %92

92:                                               ; preds = %90, %87
  %93 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %93, ptr %3, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %94

94:                                               ; preds = %92, %27, %21
  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 4, ptr %6) #4
  %95 = load i32, ptr %3, align 4
  ret i32 %95
}

declare ptr @node_find(ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #3

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 = { "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, !6, i64 64}
!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, !6, i64 8}
!15 = !{!"file", !10, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!15, !10, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"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.file = type { i32, ptr, ptr }

@files = external dso_local local_unnamed_addr global [32 x ptr], align 16
@FreeRTOS_errno = external local_unnamed_addr global i32, align 4
@__files = external dso_local global [32 x %struct.file], align 16

; Function Attrs: nounwind uwtable
declare dso_local i32 @fd_new() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @fd_delete(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @fd_check(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @open(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call ptr @node_find(ptr noundef %0, i32 noundef 0) #3
  store i32 0, ptr @FreeRTOS_errno, align 4, !tbaa !5
  %4 = icmp eq ptr %3, null
  br i1 %4, label %9, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %3, i64 64
  %7 = load ptr, ptr %6, align 8, !tbaa !9
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %10

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

10:                                               ; preds = %5
  %11 = tail call i32 @fd_new()
  %12 = tail call i32 @fd_check(i32 noundef %11)
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %14, label %13

13:                                               ; preds = %10
  store i32 2, ptr @FreeRTOS_errno, align 4, !tbaa !5
  br label %36

14:                                               ; preds = %10
  %15 = sext i32 %11 to i64
  %16 = getelementptr inbounds [32 x %struct.file], ptr @__files, i64 0, i64 %15
  %17 = getelementptr inbounds [32 x ptr], ptr @files, i64 0, i64 %15
  store ptr %16, ptr %17, align 8, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %16, i64 8
  store ptr %3, ptr %18, align 8, !tbaa !14
  store i32 %1, ptr %16, align 8, !tbaa !16
  %19 = tail call ptr @strstr(ptr noundef nonnull dereferenceable(1) %0, ptr noundef nonnull dereferenceable(1) %3) #4
  %20 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %3) #4
  %21 = getelementptr inbounds i8, ptr %19, i64 %20
  br label %22

22:                                               ; preds = %22, %14
  %.0 = phi ptr [ %21, %14 ], [ %25, %22 ]
  %23 = load i8, ptr %.0, align 1, !tbaa !17
  %24 = icmp eq i8 %23, 47
  %25 = getelementptr inbounds i8, ptr %.0, i64 1
  br i1 %24, label %22, label %26, !llvm.loop !18

26:                                               ; preds = %22
  %27 = load ptr, ptr %6, align 8, !tbaa !9
  %28 = tail call i32 %27(ptr noundef nonnull %16, ptr noundef nonnull %.0) #3
  %.not25 = icmp eq i32 %28, 0
  br i1 %.not25, label %35, label %29

29:                                               ; preds = %26
  %30 = load i32, ptr @FreeRTOS_errno, align 4, !tbaa !5
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  store i32 5, ptr @FreeRTOS_errno, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %32, %29
  %34 = tail call i32 @fd_delete(i32 noundef %11)
  br label %36

35:                                               ; preds = %26
  store i32 0, ptr @FreeRTOS_errno, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %33, %35, %13, %9
  %.022 = phi i32 [ -1, %9 ], [ -1, %13 ], [ -1, %33 ], [ %11, %35 ]
  ret i32 %.022
}

declare ptr @node_find(ptr noundef, i32 noundef) local_unnamed_addr #1

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

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

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 = { "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 = { 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 #3 = { nounwind }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 64}
!10 = !{!"node", !7, i64 0, !11, i64 64, !12, i64 152, !12, i64 160, !12, i64 168}
!11 = !{!"file_operations", !12, i64 0, !12, i64 8, !12, i64 16, !12, i64 24, !12, i64 32, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !12, i64 72, !12, i64 80}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!15, !12, i64 8}
!15 = !{!"file", !6, i64 0, !12, i64 8, !12, i64 16}
!16 = !{!15, !6, i64 0}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass