; 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_MAT = type { i32, [2 x i8], [8 x i32], [8 x i32], [2 x i32], i8 }

@mat = external dso_local global [0 x 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 @is_file_ready2_delete(i32 noundef %0) #1 {
  %2 = alloca i8, align 1
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  store i8 0, ptr %4, align 1, !tbaa !9
  br label %6

6:                                                ; preds = %31, %1
  %7 = load i8, ptr %4, align 1, !tbaa !9
  %8 = zext i8 %7 to i32
  %9 = icmp slt i32 %8, 2
  br i1 %9, label %10, label %32

10:                                               ; preds = %6
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds [0 x ptr], ptr @mat, i64 0, i64 %12
  %14 = load ptr, ptr %13, align 8, !tbaa !10
  %15 = getelementptr inbounds %struct._sat_MAT, ptr %14, i32 0, i32 3
  %16 = load i8, ptr %4, align 1, !tbaa !9
  %17 = zext i8 %16 to i32
  %18 = ashr i32 %17, 5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [8 x i32], ptr %15, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = icmp ne i32 %21, 0
  %23 = xor i1 %22, true
  %24 = zext i1 %23 to i32
  %25 = load i8, ptr %4, align 1, !tbaa !9
  %26 = zext i8 %25 to i32
  %27 = shl i32 1, %26
  %28 = and i32 %24, %27
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %10
  br label %32

31:                                               ; preds = %10
  br label %6, !llvm.loop !12

32:                                               ; preds = %30, %6
  %33 = load i8, ptr %4, align 1, !tbaa !9
  %34 = zext i8 %33 to i32
  %35 = icmp eq i32 %34, 2
  br i1 %35, label %36, label %65

36:                                               ; preds = %32
  %37 = load i32, ptr %3, align 4, !tbaa !5
  %38 = zext i32 %37 to i64
  %39 = getelementptr inbounds [0 x ptr], ptr @mat, i64 0, i64 %38
  %40 = load ptr, ptr %39, align 8, !tbaa !10
  %41 = getelementptr inbounds %struct._sat_MAT, ptr %40, i32 0, i32 3
  %42 = load i8, ptr %4, align 1, !tbaa !9
  %43 = zext i8 %42 to i32
  %44 = ashr i32 %43, 5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [8 x i32], ptr %41, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i8, ptr %4, align 1, !tbaa !9
  %49 = zext i8 %48 to i32
  %50 = shl i32 1, %49
  %51 = or i32 %47, %50
  %52 = load i32, ptr %3, align 4, !tbaa !5
  %53 = zext i32 %52 to i64
  %54 = getelementptr inbounds [0 x ptr], ptr @mat, i64 0, i64 %53
  %55 = load ptr, ptr %54, align 8, !tbaa !10
  %56 = getelementptr inbounds %struct._sat_MAT, ptr %55, i32 0, i32 3
  %57 = load i8, ptr %4, align 1, !tbaa !9
  %58 = zext i8 %57 to i64
  %59 = getelementptr inbounds [8 x i32], ptr %56, i64 0, i64 %58
  store i32 %51, ptr %59, align 4, !tbaa !5
  %60 = load i32, ptr %3, align 4, !tbaa !5
  %61 = call zeroext i8 @delete_file(i32 noundef %60)
  %62 = icmp ne i8 %61, 0
  br i1 %62, label %63, label %64

63:                                               ; preds = %36
  store i8 0, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %66

64:                                               ; preds = %36
  store i8 1, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %66

65:                                               ; preds = %32
  store i8 17, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %66

66:                                               ; preds = %65, %64, %63
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  %67 = load i8, ptr %2, align 1
  ret i8 %67
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @delete_file(i32 noundef) #1

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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"any pointer", !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"

@mat = external dso_local local_unnamed_addr global [0 x ptr], align 8

; Function Attrs: nofree norecurse nosync nounwind memory(read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i8 @is_file_ready2_delete(i32 noundef %0) local_unnamed_addr #0 {
  %2 = zext i32 %0 to i64
  %3 = getelementptr inbounds [0 x ptr], ptr @mat, i64 0, i64 %2
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 40
  %6 = load i32, ptr %5, align 4, !tbaa !9
  %.not.not = icmp eq i32 %6, 0
  br i1 %.not.not, label %7, label %.split, !llvm.loop !11

.split:                                           ; preds = %1, %.split
  br label %.split

7:                                                ; preds = %1
  ret i8 17
}

attributes #0 = { nofree norecurse nosync nounwind memory(read, 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}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


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