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

@files = external dso_local global [32 x ptr], align 16
@FreeRTOS_errno = external global i32, align 4
@.str.36 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.37 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.38 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.50 = external hidden unnamed_addr constant [4 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

; 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 i32 @fd_check(i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @open(ptr noundef, i32 noundef) #1

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

12:                                               ; preds = %2
  br i1 true, label %20, label %14

13:                                               ; preds = %2
  br i1 false, label %20, label %14

14:                                               ; preds = %13, %12
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = call i32 @strcmp(ptr noundef %15, ptr noundef @.str.37) #4
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %14
  br i1 true, label %20, label %21

19:                                               ; preds = %14
  br i1 false, label %20, label %21

20:                                               ; preds = %19, %18, %13, %12
  store i32 8192, ptr %6, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %20, %19, %18
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = call i32 @strcmp(ptr noundef %22, ptr noundef @.str.38) #4
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  br i1 true, label %39, label %27

26:                                               ; preds = %21
  br i1 false, label %39, label %27

27:                                               ; preds = %26, %25
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = call i32 @strcmp(ptr noundef %28, ptr noundef @.str.39) #4
  %30 = icmp eq i32 %29, 0
  br i1 %30, label %31, label %32

31:                                               ; preds = %27
  br i1 true, label %39, label %33

32:                                               ; preds = %27
  br i1 false, label %39, label %33

33:                                               ; preds = %32, %31
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = call i32 @strcmp(ptr noundef %34, ptr noundef @.str.40) #4
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %33
  br i1 true, label %39, label %40

38:                                               ; preds = %33
  br i1 false, label %39, label %40

39:                                               ; preds = %38, %37, %32, %31, %26, %25
  store i32 41024, ptr %6, align 4, !tbaa !9
  br label %40

40:                                               ; preds = %39, %38, %37
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = call i32 @strcmp(ptr noundef %41, ptr noundef @.str.41) #4
  %43 = icmp eq i32 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %40
  br i1 true, label %52, label %46

45:                                               ; preds = %40
  br i1 false, label %52, label %46

46:                                               ; preds = %45, %44
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = call i32 @strcmp(ptr noundef %47, ptr noundef @.str.42) #4
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %46
  br i1 true, label %52, label %53

51:                                               ; preds = %46
  br i1 false, label %52, label %53

52:                                               ; preds = %51, %50, %45, %44
  store i32 32834, ptr %6, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %52, %51, %50
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = call i32 @strcmp(ptr noundef %54, ptr noundef @.str.43) #4
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %53
  br i1 true, label %71, label %59

58:                                               ; preds = %53
  br i1 false, label %71, label %59

59:                                               ; preds = %58, %57
  %60 = load ptr, ptr %5, align 8, !tbaa !5
  %61 = call i32 @strcmp(ptr noundef %60, ptr noundef @.str.44) #4
  %62 = icmp eq i32 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %59
  br i1 true, label %71, label %65

64:                                               ; preds = %59
  br i1 false, label %71, label %65

65:                                               ; preds = %64, %63
  %66 = load ptr, ptr %5, align 8, !tbaa !5
  %67 = call i32 @strcmp(ptr noundef %66, ptr noundef @.str.45) #4
  %68 = icmp eq i32 %67, 0
  br i1 %68, label %69, label %70

69:                                               ; preds = %65
  br i1 true, label %71, label %72

70:                                               ; preds = %65
  br i1 false, label %71, label %72

71:                                               ; preds = %70, %69, %64, %63, %58, %57
  store i32 41026, ptr %6, align 4, !tbaa !9
  br label %72

72:                                               ; preds = %71, %70, %69
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = call i32 @strcmp(ptr noundef %73, ptr noundef @.str.46) #4
  %75 = icmp eq i32 %74, 0
  br i1 %75, label %76, label %77

76:                                               ; preds = %72
  br i1 true, label %84, label %78

77:                                               ; preds = %72
  br i1 false, label %84, label %78

78:                                               ; preds = %77, %76
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = call i32 @strcmp(ptr noundef %79, ptr noundef @.str.47) #4
  %81 = icmp eq i32 %80, 0
  br i1 %81, label %82, label %83

82:                                               ; preds = %78
  br i1 true, label %84, label %85

83:                                               ; preds = %78
  br i1 false, label %84, label %85

84:                                               ; preds = %83, %82, %77, %76
  store i32 33026, ptr %6, align 4, !tbaa !9
  br label %85

85:                                               ; preds = %84, %83, %82
  %86 = load ptr, ptr %5, align 8, !tbaa !5
  %87 = call i32 @strcmp(ptr noundef %86, ptr noundef @.str.48) #4
  %88 = icmp eq i32 %87, 0
  br i1 %88, label %89, label %90

89:                                               ; preds = %85
  br i1 true, label %103, label %91

90:                                               ; preds = %85
  br i1 false, label %103, label %91

91:                                               ; preds = %90, %89
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = call i32 @strcmp(ptr noundef %92, ptr noundef @.str.49) #4
  %94 = icmp eq i32 %93, 0
  br i1 %94, label %95, label %96

95:                                               ; preds = %91
  br i1 true, label %103, label %97

96:                                               ; preds = %91
  br i1 false, label %103, label %97

97:                                               ; preds = %96, %95
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = call i32 @strcmp(ptr noundef %98, ptr noundef @.str.50) #4
  %100 = icmp eq i32 %99, 0
  br i1 %100, label %101, label %102

101:                                              ; preds = %97
  br i1 true, label %103, label %104

102:                                              ; preds = %97
  br i1 false, label %103, label %104

103:                                              ; preds = %102, %101, %96, %95, %90, %89
  store i32 41218, ptr %6, align 4, !tbaa !9
  br label %104

104:                                              ; preds = %103, %102, %101
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %105 = load ptr, ptr %4, align 8, !tbaa !5
  %106 = load i32, ptr %6, align 4, !tbaa !9
  %107 = call i32 @open(ptr noundef %105, i32 noundef %106)
  store i32 %107, ptr %7, align 4, !tbaa !9
  %108 = load i32, ptr %7, align 4, !tbaa !9
  %109 = call i32 @fd_check(i32 noundef %108)
  %110 = icmp ne i32 %109, 0
  br i1 %110, label %111, label %112

111:                                              ; preds = %104
  store ptr null, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %124

112:                                              ; preds = %104
  %113 = load i32, ptr %7, align 4, !tbaa !9
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [32 x ptr], ptr @files, i64 0, i64 %114
  %116 = load ptr, ptr %115, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.file, ptr %116, i32 0, i32 0
  %118 = load i32, ptr %117, align 8, !tbaa !11
  %119 = and i32 %118, -17
  store i32 %119, ptr %117, align 8, !tbaa !11
  %120 = load i32, ptr %7, align 4, !tbaa !9
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [32 x ptr], ptr @files, i64 0, i64 %121
  %123 = load ptr, ptr %122, align 8, !tbaa !5
  store ptr %123, ptr %3, align 8
  store i32 1, ptr %8, align 4
  br label %124

124:                                              ; preds = %112, %111
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %125 = load ptr, ptr %3, align 8
  ret ptr %125
}

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcmp(ptr noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = !{!"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, !10, i64 0}
!12 = !{!"file", !10, i64 0, !6, i64 8, !6, i64 16}


; 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
@FreeRTOS_errno = external local_unnamed_addr global i32, align 4
@.str.38 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.39 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.40 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.41 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.42 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.43 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.44 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.45 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.46 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.47 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.48 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.49 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.50 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @fopen(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #0 {
  store i32 0, ptr @FreeRTOS_errno, align 4, !tbaa !5
  %3 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.38) #2
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %11, label %5

5:                                                ; preds = %2
  %6 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.39) #2
  %7 = icmp eq i32 %6, 0
  br i1 %7, label %11, label %8

8:                                                ; preds = %5
  %9 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.40) #2
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %8, %5, %2
  br label %12

12:                                               ; preds = %8, %11
  %.1 = phi i32 [ 41024, %11 ], [ 8192, %8 ]
  %13 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.41) #2
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %18, label %15

15:                                               ; preds = %12
  %16 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.42) #2
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %15, %12
  br label %19

19:                                               ; preds = %15, %18
  %.2 = phi i32 [ 32834, %18 ], [ %.1, %15 ]
  %20 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.43) #2
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %28, label %22

22:                                               ; preds = %19
  %23 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.44) #2
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %28, label %25

25:                                               ; preds = %22
  %26 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.45) #2
  %27 = icmp eq i32 %26, 0
  br i1 %27, label %28, label %29

28:                                               ; preds = %25, %22, %19
  br label %29

29:                                               ; preds = %25, %28
  %.3 = phi i32 [ 41026, %28 ], [ %.2, %25 ]
  %30 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.46) #2
  %31 = icmp eq i32 %30, 0
  br i1 %31, label %35, label %32

32:                                               ; preds = %29
  %33 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.47) #2
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %36

35:                                               ; preds = %32, %29
  br label %36

36:                                               ; preds = %32, %35
  %.4 = phi i32 [ 33026, %35 ], [ %.3, %32 ]
  %37 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.48) #2
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %45, label %39

39:                                               ; preds = %36
  %40 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.49) #2
  %41 = icmp eq i32 %40, 0
  br i1 %41, label %45, label %42

42:                                               ; preds = %39
  %43 = tail call i32 @strcmp(ptr noundef nonnull dereferenceable(1) %1, ptr noundef nonnull dereferenceable(1) @.str.50) #2
  %44 = icmp eq i32 %43, 0
  br i1 %44, label %45, label %46

45:                                               ; preds = %42, %39, %36
  br label %46

46:                                               ; preds = %42, %45
  %.5 = phi i32 [ 41218, %45 ], [ %.4, %42 ]
  %47 = tail call i32 @open(ptr noundef %0, i32 noundef %.5)
  %48 = tail call i32 @fd_check(i32 noundef %47)
  %.not = icmp eq i32 %48, 0
  br i1 %.not, label %49, label %55

49:                                               ; preds = %46
  %50 = sext i32 %47 to i64
  %51 = getelementptr inbounds [32 x ptr], ptr @files, i64 0, i64 %50
  %52 = load ptr, ptr %51, align 8, !tbaa !9
  %53 = load i32, ptr %52, align 8, !tbaa !11
  %54 = and i32 %53, -17
  store i32 %54, ptr %52, align 8, !tbaa !11
  br label %55

55:                                               ; preds = %46, %49
  %.0 = phi ptr [ %52, %49 ], [ null, %46 ]
  ret ptr %.0
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i32 @strcmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #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 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 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, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"file", !6, i64 0, !10, i64 8, !10, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass