; 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_file = type { [2 x %struct._sat_message], i8 }
%struct._sat_message = type { [512 x i8], i8 }
%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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; 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 @write_file(i32 noundef %0, ptr noundef %1) #2 {
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca %struct._sat_file, align 1
  %7 = alloca %struct._sat_message, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1027, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 513, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #3
  %11 = load ptr, ptr @root, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct._sat_FAT, ptr %11, i32 0, i32 2
  %13 = load i32, ptr %4, align 4, !tbaa !5
  %14 = lshr i32 %13, 5
  %15 = zext i32 %14 to i64
  %16 = getelementptr inbounds [4 x i32], ptr %12, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  %19 = xor i1 %18, true
  %20 = zext i1 %19 to i32
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = shl i32 1, %21
  %23 = and i32 %20, %22
  %24 = icmp ne i32 %23, 0
  br i1 %24, label %25, label %52

25:                                               ; preds = %2
  store i8 0, ptr %9, align 1, !tbaa !11
  br label %26

26:                                               ; preds = %44, %25
  %27 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %6, ptr align 1 %27, i64 1027, i1 false), !tbaa.struct !12
  %28 = getelementptr inbounds %struct._sat_file, ptr %6, i32 0, i32 0
  %29 = load i8, ptr %9, align 1, !tbaa !11
  %30 = zext i8 %29 to i64
  %31 = getelementptr inbounds [2 x %struct._sat_message], ptr %28, i64 0, i64 %30
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %7, ptr align 1 %31, i64 513, i1 false), !tbaa.struct !13
  store ptr %7, ptr %8, align 8, !tbaa !9
  br label %32

32:                                               ; preds = %26
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = load ptr, ptr %8, align 8, !tbaa !9
  %35 = load i8, ptr %9, align 1, !tbaa !11
  %36 = add i8 %35, 1
  store i8 %36, ptr %9, align 1, !tbaa !11
  %37 = call zeroext i8 @write_message(i32 noundef %33, ptr noundef %34, i8 noundef zeroext %35)
  %38 = zext i8 %37 to i32
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %40, label %44

40:                                               ; preds = %32
  %41 = load i8, ptr %9, align 1, !tbaa !11
  %42 = zext i8 %41 to i32
  %43 = icmp slt i32 %42, 2
  br label %44

44:                                               ; preds = %40, %32
  %45 = phi i1 [ false, %32 ], [ %43, %40 ]
  br i1 %45, label %26, label %46, !llvm.loop !14

46:                                               ; preds = %44
  %47 = load i8, ptr %9, align 1, !tbaa !11
  %48 = zext i8 %47 to i32
  %49 = icmp eq i32 %48, 2
  br i1 %49, label %50, label %51

50:                                               ; preds = %46
  store i8 0, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %53

51:                                               ; preds = %46
  store i8 17, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %53

52:                                               ; preds = %2
  store i8 1, ptr %3, align 1
  store i32 1, ptr %10, align 4
  br label %53

53:                                               ; preds = %52, %51, %50
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 513, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 1027, ptr %6) #3
  %54 = load i8, ptr %3, align 1
  ret i8 %54
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @write_message(i32 noundef, ptr noundef, i8 noundef zeroext) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 = !{!7, !7, i64 0}
!12 = !{i64 0, i64 1026, !11, i64 1026, i64 1, !11}
!13 = !{i64 0, i64 512, !11, i64 512, i64 1, !11}
!14 = distinct !{!14, !15}
!15 = !{!"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_message = type { [512 x i8], i8 }

@root = external dso_local local_unnamed_addr global ptr, align 8

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress 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 range(i8 0, 18) i8 @write_file(i32 noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #2 {
  %3 = alloca %struct._sat_message, align 1
  call void @llvm.lifetime.start.p0(i64 513, ptr nonnull %3) #3
  %4 = load ptr, ptr @root, align 8, !tbaa !5
  %5 = lshr i32 %0, 5
  %6 = zext nneg i32 %5 to i64
  %7 = getelementptr inbounds [4 x i32], ptr %4, i64 0, i64 %6
  %8 = load i32, ptr %7, align 4, !tbaa !9
  %9 = or i32 %8, %0
  %narrow = icmp eq i32 %9, 0
  br i1 %narrow, label %.preheader.preheader, label %.loopexit

.preheader.preheader:                             ; preds = %2
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(513) %3, ptr noundef nonnull align 1 dereferenceable(513) %1, i64 513, i1 false)
  %10 = call zeroext i8 @write_message(i32 noundef %0, ptr noundef nonnull %3, i8 noundef zeroext 0)
  %.not = icmp eq i8 %10, 0
  br i1 %.not, label %.loopexit, label %.loopexit.loopexit.loopexit

.loopexit.loopexit.loopexit:                      ; preds = %.preheader.preheader
  %11 = getelementptr inbounds i8, ptr %1, i64 513
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(513) %3, ptr noundef nonnull align 1 dereferenceable(513) %11, i64 513, i1 false)
  %12 = call zeroext i8 @write_message(i32 noundef %0, ptr noundef nonnull %3, i8 noundef zeroext 1)
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader.preheader, %.loopexit.loopexit.loopexit, %2
  %.09 = phi i8 [ 1, %2 ], [ 17, %.preheader.preheader ], [ 0, %.loopexit.loopexit.loopexit ]
  call void @llvm.lifetime.end.p0(i64 513, ptr nonnull %3) #3
  ret i8 %.09
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @write_message(i32 noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LoopFullUnrollPass,LoopSimplifyPass,MemCpyOptPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass