; LLVM IR from embeddednirvana/A-Rudimentary-RTOS-for-Satellite-Control :: fs (sat_fs)

; 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._sat_FAT = type { [0 x i32], [0 x i32], [4 x i32] }
%struct._sat_MAT = type { i32, [2 x i8], [8 x i32], [8 x i32], [2 x i32], i8 }

@root = external dso_local global ptr, align 8
@mat = external dso_local global [0 x ptr], align 8
@root_fat = external dso_local global %struct._sat_FAT, align 4
@root_mat = external dso_local global [0 x %struct._sat_MAT], align 4

; 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 zeroext i8 @setup_FAT() #1

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @setup_MAT() #1

; Function Attrs: nounwind uwtable
define dso_local zeroext i8 @reset_fat_mat() #1 {
  %1 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #2
  store ptr @root_fat, ptr @root, align 8, !tbaa !5
  %2 = call zeroext i8 @setup_FAT()
  store i8 0, ptr %1, align 1, !tbaa !9
  br label %3

3:                                                ; preds = %15, %0
  %4 = load i8, ptr %1, align 1, !tbaa !9
  %5 = zext i8 %4 to i32
  %6 = icmp slt i32 %5, 0
  br i1 %6, label %7, label %18

7:                                                ; preds = %3
  %8 = load i8, ptr %1, align 1, !tbaa !9
  %9 = zext i8 %8 to i32
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds %struct._sat_MAT, ptr @root_mat, i64 %10
  %12 = load i8, ptr %1, align 1, !tbaa !9
  %13 = zext i8 %12 to i64
  %14 = getelementptr inbounds [0 x ptr], ptr @mat, i64 0, i64 %13
  store ptr %11, ptr %14, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %7
  %16 = load i8, ptr %1, align 1, !tbaa !9
  %17 = add i8 %16, 1
  store i8 %17, ptr %1, align 1, !tbaa !9
  br label %3, !llvm.loop !10

18:                                               ; preds = %3
  %19 = call zeroext i8 @setup_MAT()
  call void @llvm.lifetime.end.p0(i64 1, ptr %1) #2
  ret i8 0
}

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 }

!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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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._sat_FAT = type { [0 x i32], [0 x i32], [4 x i32] }

@root = external dso_local local_unnamed_addr global ptr, align 8
@root_fat = external dso_local global %struct._sat_FAT, align 4

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @setup_FAT() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @setup_MAT() local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef zeroext i8 @reset_fat_mat() local_unnamed_addr #0 {
  store ptr @root_fat, ptr @root, align 8, !tbaa !5
  %1 = tail call zeroext i8 @setup_FAT()
  %2 = tail call zeroext i8 @setup_MAT()
  ret i8 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" }

!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: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass