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

@files = external dso_local global [32 x ptr], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @fd_new() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %1) #2
  store i32 -1, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #2
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %17, %0
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 32
  br i1 %6, label %8, label %7

7:                                                ; preds = %4
  store i32 2, ptr %3, align 4
  br label %20

8:                                                ; preds = %4
  %9 = load i32, ptr %2, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [32 x ptr], ptr @files, i64 0, i64 %10
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  %13 = icmp eq ptr %12, null
  br i1 %13, label %14, label %16

14:                                               ; preds = %8
  %15 = load i32, ptr %2, align 4, !tbaa !5
  store i32 %15, ptr %1, align 4, !tbaa !5
  store i32 2, ptr %3, align 4
  br label %20

16:                                               ; preds = %8
  br label %17

17:                                               ; preds = %16
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %2, align 4, !tbaa !5
  br label %4, !llvm.loop !11

20:                                               ; preds = %14, %7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #2
  br label %21

21:                                               ; preds = %20
  %22 = load i32, ptr %1, align 4, !tbaa !5
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %1) #2
  ret i32 %22
}

; 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

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 = !{!"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 = distinct !{!11, !12}
!12 = !{!"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"

@files = external dso_local local_unnamed_addr global [32 x ptr], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local i32 @fd_new() local_unnamed_addr #0 {
  %1 = load ptr, ptr @files, align 16, !tbaa !5
  %2 = icmp eq ptr %1, null
  br i1 %2, label %96, label %3

3:                                                ; preds = %0
  %4 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 8), align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %96, label %6

6:                                                ; preds = %3
  %7 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 16), align 16, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %96, label %9

9:                                                ; preds = %6
  %10 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 24), align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %96, label %12

12:                                               ; preds = %9
  %13 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 32), align 16, !tbaa !5
  %14 = icmp eq ptr %13, null
  br i1 %14, label %96, label %15

15:                                               ; preds = %12
  %16 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 40), align 8, !tbaa !5
  %17 = icmp eq ptr %16, null
  br i1 %17, label %96, label %18

18:                                               ; preds = %15
  %19 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 48), align 16, !tbaa !5
  %20 = icmp eq ptr %19, null
  br i1 %20, label %96, label %21

21:                                               ; preds = %18
  %22 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 56), align 8, !tbaa !5
  %23 = icmp eq ptr %22, null
  br i1 %23, label %96, label %24

24:                                               ; preds = %21
  %25 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 64), align 16, !tbaa !5
  %26 = icmp eq ptr %25, null
  br i1 %26, label %96, label %27

27:                                               ; preds = %24
  %28 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 72), align 8, !tbaa !5
  %29 = icmp eq ptr %28, null
  br i1 %29, label %96, label %30

30:                                               ; preds = %27
  %31 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 80), align 16, !tbaa !5
  %32 = icmp eq ptr %31, null
  br i1 %32, label %96, label %33

33:                                               ; preds = %30
  %34 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 88), align 8, !tbaa !5
  %35 = icmp eq ptr %34, null
  br i1 %35, label %96, label %36

36:                                               ; preds = %33
  %37 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 96), align 16, !tbaa !5
  %38 = icmp eq ptr %37, null
  br i1 %38, label %96, label %39

39:                                               ; preds = %36
  %40 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 104), align 8, !tbaa !5
  %41 = icmp eq ptr %40, null
  br i1 %41, label %96, label %42

42:                                               ; preds = %39
  %43 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 112), align 16, !tbaa !5
  %44 = icmp eq ptr %43, null
  br i1 %44, label %96, label %45

45:                                               ; preds = %42
  %46 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 120), align 8, !tbaa !5
  %47 = icmp eq ptr %46, null
  br i1 %47, label %96, label %48

48:                                               ; preds = %45
  %49 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 128), align 16, !tbaa !5
  %50 = icmp eq ptr %49, null
  br i1 %50, label %96, label %51

51:                                               ; preds = %48
  %52 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 136), align 8, !tbaa !5
  %53 = icmp eq ptr %52, null
  br i1 %53, label %96, label %54

54:                                               ; preds = %51
  %55 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 144), align 16, !tbaa !5
  %56 = icmp eq ptr %55, null
  br i1 %56, label %96, label %57

57:                                               ; preds = %54
  %58 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 152), align 8, !tbaa !5
  %59 = icmp eq ptr %58, null
  br i1 %59, label %96, label %60

60:                                               ; preds = %57
  %61 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 160), align 16, !tbaa !5
  %62 = icmp eq ptr %61, null
  br i1 %62, label %96, label %63

63:                                               ; preds = %60
  %64 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 168), align 8, !tbaa !5
  %65 = icmp eq ptr %64, null
  br i1 %65, label %96, label %66

66:                                               ; preds = %63
  %67 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 176), align 16, !tbaa !5
  %68 = icmp eq ptr %67, null
  br i1 %68, label %96, label %69

69:                                               ; preds = %66
  %70 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 184), align 8, !tbaa !5
  %71 = icmp eq ptr %70, null
  br i1 %71, label %96, label %72

72:                                               ; preds = %69
  %73 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 192), align 16, !tbaa !5
  %74 = icmp eq ptr %73, null
  br i1 %74, label %96, label %75

75:                                               ; preds = %72
  %76 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 200), align 8, !tbaa !5
  %77 = icmp eq ptr %76, null
  br i1 %77, label %96, label %78

78:                                               ; preds = %75
  %79 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 208), align 16, !tbaa !5
  %80 = icmp eq ptr %79, null
  br i1 %80, label %96, label %81

81:                                               ; preds = %78
  %82 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 216), align 8, !tbaa !5
  %83 = icmp eq ptr %82, null
  br i1 %83, label %96, label %84

84:                                               ; preds = %81
  %85 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 224), align 16, !tbaa !5
  %86 = icmp eq ptr %85, null
  br i1 %86, label %96, label %87

87:                                               ; preds = %84
  %88 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 232), align 8, !tbaa !5
  %89 = icmp eq ptr %88, null
  br i1 %89, label %96, label %90

90:                                               ; preds = %87
  %91 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 240), align 16, !tbaa !5
  %92 = icmp eq ptr %91, null
  br i1 %92, label %96, label %93

93:                                               ; preds = %90
  %94 = load ptr, ptr getelementptr inbounds (i8, ptr @files, i64 248), align 8, !tbaa !5
  %95 = icmp eq ptr %94, null
  %spec.select = select i1 %95, i32 31, i32 -1
  br label %96

96:                                               ; preds = %93, %90, %87, %84, %81, %78, %75, %72, %69, %66, %63, %60, %57, %54, %51, %48, %45, %42, %39, %36, %33, %30, %27, %24, %21, %18, %15, %12, %9, %6, %3, %0
  %.05 = phi i32 [ 0, %0 ], [ 1, %3 ], [ 2, %6 ], [ 3, %9 ], [ 4, %12 ], [ 5, %15 ], [ 6, %18 ], [ 7, %21 ], [ 8, %24 ], [ 9, %27 ], [ 10, %30 ], [ 11, %33 ], [ 12, %36 ], [ 13, %39 ], [ 14, %42 ], [ 15, %45 ], [ 16, %48 ], [ 17, %51 ], [ 18, %54 ], [ 19, %57 ], [ 20, %60 ], [ 21, %63 ], [ 22, %66 ], [ 23, %69 ], [ 24, %72 ], [ 25, %75 ], [ 26, %78 ], [ 27, %81 ], [ 28, %84 ], [ 29, %87 ], [ 30, %90 ], [ %spec.select, %93 ]
  ret i32 %.05
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, argmem: none, inaccessiblemem: none) 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" }

!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"}


; Effective O3 passes: GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass