; LLVM IR from embeddednirvana/A-Rudimentary-RTOS-for-Satellite-Control :: fs/patches (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] }

@root = external dso_local global ptr, align 8

; 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
define dso_local zeroext i8 @setup_FAT() #1 {
  %1 = alloca i8, align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr %1) #2
  %2 = load ptr, ptr @root, align 8, !tbaa !5
  %3 = getelementptr inbounds %struct._sat_FAT, ptr %2, i32 0, i32 0
  %4 = getelementptr inbounds [0 x i32], ptr %3, i64 0, i64 0
  store i32 30720000, ptr %4, align 4, !tbaa !9
  %5 = load ptr, ptr @root, align 8, !tbaa !5
  %6 = getelementptr inbounds %struct._sat_FAT, ptr %5, i32 0, i32 1
  %7 = getelementptr inbounds [0 x i32], ptr %6, i64 0, i64 0
  store i32 60000, ptr %7, align 4, !tbaa !9
  %8 = load ptr, ptr @root, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct._sat_FAT, ptr %8, i32 0, i32 2
  %10 = getelementptr inbounds [4 x i32], ptr %9, i64 0, i64 0
  %11 = load i32, ptr %10, align 4, !tbaa !9
  %12 = and i32 %11, 0
  %13 = load ptr, ptr @root, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct._sat_FAT, ptr %13, i32 0, i32 2
  %15 = getelementptr inbounds [4 x i32], ptr %14, i64 0, i64 0
  store i32 %12, ptr %15, align 4, !tbaa !9
  store i8 1, ptr %1, align 1, !tbaa !11
  br label %16

16:                                               ; preds = %77, %0
  %17 = load i8, ptr %1, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %80

20:                                               ; preds = %16
  %21 = load ptr, ptr @root, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct._sat_FAT, ptr %21, i32 0, i32 1
  %23 = load i8, ptr %1, align 1, !tbaa !11
  %24 = zext i8 %23 to i32
  %25 = sub nsw i32 %24, 1
  %26 = sext i32 %25 to i64
  %27 = getelementptr inbounds [0 x i32], ptr %22, i64 0, i64 %26
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = add i32 %28, 64
  %30 = load ptr, ptr @root, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._sat_FAT, ptr %30, i32 0, i32 1
  %32 = load i8, ptr %1, align 1, !tbaa !11
  %33 = zext i8 %32 to i64
  %34 = getelementptr inbounds [0 x i32], ptr %31, i64 0, i64 %33
  store i32 %29, ptr %34, align 4, !tbaa !9
  %35 = load ptr, ptr @root, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct._sat_FAT, ptr %35, i32 0, i32 1
  %37 = load i8, ptr %1, align 1, !tbaa !11
  %38 = zext i8 %37 to i64
  %39 = getelementptr inbounds [0 x i32], ptr %36, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !9
  %41 = shl i32 %40, 9
  %42 = load ptr, ptr @root, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct._sat_FAT, ptr %42, i32 0, i32 0
  %44 = load i8, ptr %1, align 1, !tbaa !11
  %45 = zext i8 %44 to i64
  %46 = getelementptr inbounds [0 x i32], ptr %43, i64 0, i64 %45
  store i32 %41, ptr %46, align 4, !tbaa !9
  %47 = load ptr, ptr @root, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._sat_FAT, ptr %47, i32 0, i32 2
  %49 = load ptr, ptr @root, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct._sat_FAT, ptr %49, i32 0, i32 1
  %51 = load i8, ptr %1, align 1, !tbaa !11
  %52 = zext i8 %51 to i64
  %53 = getelementptr inbounds [0 x i32], ptr %50, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !9
  %55 = lshr i32 %54, 5
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds [4 x i32], ptr %48, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = load ptr, ptr @root, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._sat_FAT, ptr %59, i32 0, i32 1
  %61 = load i8, ptr %1, align 1, !tbaa !11
  %62 = zext i8 %61 to i64
  %63 = getelementptr inbounds [0 x i32], ptr %60, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = shl i32 0, %64
  %66 = and i32 %58, %65
  %67 = load ptr, ptr @root, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct._sat_FAT, ptr %67, i32 0, i32 2
  %69 = load ptr, ptr @root, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct._sat_FAT, ptr %69, i32 0, i32 1
  %71 = load i8, ptr %1, align 1, !tbaa !11
  %72 = zext i8 %71 to i64
  %73 = getelementptr inbounds [0 x i32], ptr %70, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !9
  %75 = zext i32 %74 to i64
  %76 = getelementptr inbounds [4 x i32], ptr %68, i64 0, i64 %75
  store i32 %66, ptr %76, align 4, !tbaa !9
  br label %77

77:                                               ; preds = %20
  %78 = load i8, ptr %1, align 1, !tbaa !11
  %79 = add i8 %78, 1
  store i8 %79, ptr %1, align 1, !tbaa !11
  br label %16, !llvm.loop !12

80:                                               ; preds = %16
  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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

@root = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i8 @setup_FAT() local_unnamed_addr #0 {
  %1 = load ptr, ptr @root, align 8, !tbaa !5
  store i32 0, ptr %1, align 4, !tbaa !9
  ret i8 0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: write, 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"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}


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