; LLVM IR from joembedded/JesFs :: jesfs_hl (fs_write)

; 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.SFLASH_INFO = type { i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, %union.SF_BUFFER, i8 }
%union.SF_BUFFER = type { [32 x i32] }
%struct.FS_DESC = type { i32, i32, i32, i32, i32, i32, i16, i8 }

@sflash_info = external global %struct.SFLASH_INFO, 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 i32 @fs_track_crc32(ptr noundef, i32 noundef, i32 noundef) #1

declare signext i16 @_supply_voltage_check() #2

declare signext i16 @sflash_SectorWrite(i32 noundef, ptr noundef, i32 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @sflash_get_free_sector() #1

; Function Attrs: nounwind uwtable
define dso_local signext i16 @fs_write(ptr noundef %0, ptr noundef %1, i32 noundef %2) #1 {
  %4 = alloca i16, align 2
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i16, align 2
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %13 = load i8, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 11), align 4, !tbaa !11
  %14 = zext i8 %13 to i32
  %15 = and i32 %14, 3
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %3
  store i16 -148, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %180

18:                                               ; preds = %3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.FS_DESC, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 4, !tbaa !14
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  store i16 -117, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %180

24:                                               ; preds = %18
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.FS_DESC, ptr %25, i32 0, i32 7
  %27 = load i8, ptr %26, align 2, !tbaa !16
  %28 = zext i8 %27 to i32
  %29 = and i32 %28, 8
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %41

31:                                               ; preds = %24
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.FS_DESC, ptr %32, i32 0, i32 2
  %34 = load i32, ptr %33, align 4, !tbaa !17
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.FS_DESC, ptr %35, i32 0, i32 3
  %37 = load i32, ptr %36, align 4, !tbaa !18
  %38 = icmp ne i32 %34, %37
  br i1 %38, label %39, label %40

39:                                               ; preds = %31
  store i16 -130, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %180

40:                                               ; preds = %31
  br label %50

41:                                               ; preds = %24
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.FS_DESC, ptr %42, i32 0, i32 7
  %44 = load i8, ptr %43, align 2, !tbaa !16
  %45 = zext i8 %44 to i32
  %46 = and i32 %45, 4
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %49, label %48

48:                                               ; preds = %41
  store i16 -118, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %180

49:                                               ; preds = %41
  br label %50

50:                                               ; preds = %49, %40
  %51 = call signext i16 @_supply_voltage_check()
  %52 = icmp ne i16 %51, 0
  br i1 %52, label %53, label %58

53:                                               ; preds = %50
  %54 = load i8, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 11), align 4, !tbaa !11
  %55 = zext i8 %54 to i32
  %56 = or i32 %55, 2
  %57 = trunc i32 %56 to i8
  store i8 %57, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 11), align 4, !tbaa !11
  store i16 -147, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %180

58:                                               ; preds = %50
  br label %59

59:                                               ; preds = %178, %58
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %62, label %179

62:                                               ; preds = %59
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.FS_DESC, ptr %63, i32 0, i32 6
  %65 = load i16, ptr %64, align 4, !tbaa !19
  %66 = zext i16 %65 to i32
  %67 = sub nsw i32 4096, %66
  store i32 %67, ptr %9, align 4, !tbaa !9
  %68 = load i32, ptr %9, align 4, !tbaa !9
  %69 = icmp ugt i32 %68, 4096
  br i1 %69, label %70, label %71

70:                                               ; preds = %62
  store i16 -112, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %180

71:                                               ; preds = %62
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %109, label %74

74:                                               ; preds = %71
  %75 = call i32 @sflash_get_free_sector()
  store i32 %75, ptr %11, align 4, !tbaa !9
  %76 = load i32, ptr %11, align 4, !tbaa !9
  %77 = icmp ne i32 %76, 0
  br i1 %77, label %79, label %78

78:                                               ; preds = %74
  store i16 -113, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %180

79:                                               ; preds = %74
  %80 = load ptr, ptr %5, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.FS_DESC, ptr %80, i32 0, i32 1
  %82 = load i32, ptr %81, align 4, !tbaa !20
  %83 = add i32 %82, 8
  %84 = call signext i16 @sflash_SectorWrite(i32 noundef %83, ptr noundef %11, i32 noundef 4)
  store i16 %84, ptr %8, align 2, !tbaa !21
  %85 = load i16, ptr %8, align 2, !tbaa !21
  %86 = icmp ne i16 %85, 0
  br i1 %86, label %87, label %89

87:                                               ; preds = %79
  %88 = load i16, ptr %8, align 2, !tbaa !21
  store i16 %88, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %180

89:                                               ; preds = %79
  %90 = load i32, ptr %11, align 4, !tbaa !9
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.FS_DESC, ptr %91, i32 0, i32 1
  store i32 %90, ptr %92, align 4, !tbaa !20
  %93 = load ptr, ptr %5, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.FS_DESC, ptr %93, i32 0, i32 6
  store i16 12, ptr %94, align 4, !tbaa !19
  store i32 4084, ptr %9, align 4, !tbaa !9
  store i32 -41637, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), align 4, !tbaa !22
  %95 = load ptr, ptr %5, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.FS_DESC, ptr %95, i32 0, i32 0
  %97 = load i32, ptr %96, align 4, !tbaa !14
  store i32 %97, ptr getelementptr inbounds ([32 x i32], ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i64 0, i64 1), align 4, !tbaa !22
  %98 = load ptr, ptr %5, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.FS_DESC, ptr %98, i32 0, i32 1
  %100 = load i32, ptr %99, align 4, !tbaa !20
  %101 = call signext i16 @sflash_SectorWrite(i32 noundef %100, ptr noundef getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i32 noundef 8)
  store i16 %101, ptr %8, align 2, !tbaa !21
  %102 = load i16, ptr %8, align 2, !tbaa !21
  %103 = icmp ne i16 %102, 0
  br i1 %103, label %104, label %106

104:                                              ; preds = %89
  %105 = load i16, ptr %8, align 2, !tbaa !21
  store i16 %105, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %180

106:                                              ; preds = %89
  %107 = load i32, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 4), align 4, !tbaa !23
  %108 = sub i32 %107, 4096
  store i32 %108, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 4), align 4, !tbaa !23
  br label %109

109:                                              ; preds = %106, %71
  %110 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %110, ptr %10, align 4, !tbaa !9
  %111 = load i32, ptr %10, align 4, !tbaa !9
  %112 = load i32, ptr %9, align 4, !tbaa !9
  %113 = icmp ugt i32 %111, %112
  br i1 %113, label %114, label %116

114:                                              ; preds = %109
  %115 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %115, ptr %10, align 4, !tbaa !9
  br label %116

116:                                              ; preds = %114, %109
  %117 = load ptr, ptr %5, align 8, !tbaa !5
  %118 = getelementptr inbounds %struct.FS_DESC, ptr %117, i32 0, i32 7
  %119 = load i8, ptr %118, align 2, !tbaa !16
  %120 = zext i8 %119 to i32
  %121 = and i32 %120, 16
  %122 = icmp ne i32 %121, 0
  br i1 %122, label %123, label %132

123:                                              ; preds = %116
  %124 = load ptr, ptr %6, align 8, !tbaa !5
  %125 = load i32, ptr %10, align 4, !tbaa !9
  %126 = load ptr, ptr %5, align 8, !tbaa !5
  %127 = getelementptr inbounds %struct.FS_DESC, ptr %126, i32 0, i32 4
  %128 = load i32, ptr %127, align 4, !tbaa !24
  %129 = call i32 @fs_track_crc32(ptr noundef %124, i32 noundef %125, i32 noundef %128)
  %130 = load ptr, ptr %5, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.FS_DESC, ptr %130, i32 0, i32 4
  store i32 %129, ptr %131, align 4, !tbaa !24
  br label %132

132:                                              ; preds = %123, %116
  %133 = load ptr, ptr %5, align 8, !tbaa !5
  %134 = getelementptr inbounds %struct.FS_DESC, ptr %133, i32 0, i32 1
  %135 = load i32, ptr %134, align 4, !tbaa !20
  %136 = load ptr, ptr %5, align 8, !tbaa !5
  %137 = getelementptr inbounds %struct.FS_DESC, ptr %136, i32 0, i32 6
  %138 = load i16, ptr %137, align 4, !tbaa !19
  %139 = zext i16 %138 to i32
  %140 = add i32 %135, %139
  %141 = load ptr, ptr %6, align 8, !tbaa !5
  %142 = load i32, ptr %10, align 4, !tbaa !9
  %143 = call signext i16 @sflash_SectorWrite(i32 noundef %140, ptr noundef %141, i32 noundef %142)
  store i16 %143, ptr %8, align 2, !tbaa !21
  %144 = load i16, ptr %8, align 2, !tbaa !21
  %145 = icmp ne i16 %144, 0
  br i1 %145, label %146, label %148

146:                                              ; preds = %132
  %147 = load i16, ptr %8, align 2, !tbaa !21
  store i16 %147, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %180

148:                                              ; preds = %132
  %149 = load i32, ptr %10, align 4, !tbaa !9
  %150 = load i32, ptr %7, align 4, !tbaa !9
  %151 = sub i32 %150, %149
  store i32 %151, ptr %7, align 4, !tbaa !9
  %152 = load i32, ptr %10, align 4, !tbaa !9
  %153 = load ptr, ptr %6, align 8, !tbaa !5
  %154 = zext i32 %152 to i64
  %155 = getelementptr inbounds i8, ptr %153, i64 %154
  store ptr %155, ptr %6, align 8, !tbaa !5
  %156 = load i32, ptr %10, align 4, !tbaa !9
  %157 = load ptr, ptr %5, align 8, !tbaa !5
  %158 = getelementptr inbounds %struct.FS_DESC, ptr %157, i32 0, i32 6
  %159 = load i16, ptr %158, align 4, !tbaa !19
  %160 = zext i16 %159 to i32
  %161 = add i32 %160, %156
  %162 = trunc i32 %161 to i16
  store i16 %162, ptr %158, align 4, !tbaa !19
  %163 = load i32, ptr %10, align 4, !tbaa !9
  %164 = load ptr, ptr %5, align 8, !tbaa !5
  %165 = getelementptr inbounds %struct.FS_DESC, ptr %164, i32 0, i32 2
  %166 = load i32, ptr %165, align 4, !tbaa !17
  %167 = add i32 %166, %163
  store i32 %167, ptr %165, align 4, !tbaa !17
  %168 = load ptr, ptr %5, align 8, !tbaa !5
  %169 = getelementptr inbounds %struct.FS_DESC, ptr %168, i32 0, i32 3
  %170 = load i32, ptr %169, align 4, !tbaa !18
  %171 = icmp ne i32 %170, -1
  br i1 %171, label %172, label %178

172:                                              ; preds = %148
  %173 = load ptr, ptr %5, align 8, !tbaa !5
  %174 = getelementptr inbounds %struct.FS_DESC, ptr %173, i32 0, i32 2
  %175 = load i32, ptr %174, align 4, !tbaa !17
  %176 = load ptr, ptr %5, align 8, !tbaa !5
  %177 = getelementptr inbounds %struct.FS_DESC, ptr %176, i32 0, i32 3
  store i32 %175, ptr %177, align 4, !tbaa !18
  br label %178

178:                                              ; preds = %172, %148
  br label %59, !llvm.loop !25

179:                                              ; preds = %59
  store i16 0, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %180

180:                                              ; preds = %179, %146, %104, %87, %78, %70, %53, %48, %39, %23, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #3
  %181 = load i16, ptr %4, align 2
  ret i16 %181
}

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 = { "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}
!11 = !{!12, !7, i64 160}
!12 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !13, i64 20, !13, i64 22, !13, i64 24, !13, i64 26, !13, i64 28, !7, i64 32, !7, i64 160}
!13 = !{!"short", !7, i64 0}
!14 = !{!15, !10, i64 0}
!15 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !13, i64 24, !7, i64 26}
!16 = !{!15, !7, i64 26}
!17 = !{!15, !10, i64 8}
!18 = !{!15, !10, i64 12}
!19 = !{!15, !13, i64 24}
!20 = !{!15, !10, i64 4}
!21 = !{!13, !13, i64 0}
!22 = !{!7, !7, i64 0}
!23 = !{!12, !10, i64 16}
!24 = !{!15, !10, i64 16}
!25 = distinct !{!25, !26}
!26 = !{!"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.SFLASH_INFO = type { i32, i32, i32, i32, i32, i16, i16, i16, i16, i16, %union.SF_BUFFER, i8 }
%union.SF_BUFFER = type { [32 x i32] }

@sflash_info = external global %struct.SFLASH_INFO, align 4

; 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 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 @fs_track_crc32(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #1

declare signext i16 @_supply_voltage_check() local_unnamed_addr #2

declare signext i16 @sflash_SectorWrite(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @sflash_get_free_sector() local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local signext i16 @fs_write(ptr nocapture noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %5 = load i8, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 160), align 4, !tbaa !5
  %6 = and i8 %5, 3
  %.not = icmp eq i8 %6, 0
  br i1 %.not, label %7, label %.loopexit

7:                                                ; preds = %3
  %8 = load i32, ptr %0, align 4, !tbaa !11
  %.not52 = icmp eq i32 %8, 0
  br i1 %.not52, label %.loopexit, label %9

9:                                                ; preds = %7
  %10 = getelementptr inbounds i8, ptr %0, i64 26
  %11 = load i8, ptr %10, align 2, !tbaa !13
  %12 = zext i8 %11 to i32
  %13 = and i32 %12, 8
  %.not53 = icmp eq i32 %13, 0
  br i1 %.not53, label %19, label %14

14:                                               ; preds = %9
  %15 = getelementptr inbounds i8, ptr %0, i64 8
  %16 = load i32, ptr %15, align 4, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %0, i64 12
  %18 = load i32, ptr %17, align 4, !tbaa !15
  %.not55 = icmp eq i32 %16, %18
  br i1 %.not55, label %21, label %.loopexit

19:                                               ; preds = %9
  %20 = and i32 %12, 4
  %.not54 = icmp eq i32 %20, 0
  br i1 %.not54, label %.loopexit, label %21

21:                                               ; preds = %19, %14
  %22 = tail call signext i16 @_supply_voltage_check() #4
  %.not56 = icmp eq i16 %22, 0
  br i1 %.not56, label %.preheader, label %28

.preheader:                                       ; preds = %21
  %23 = getelementptr inbounds i8, ptr %0, i64 24
  %24 = getelementptr inbounds i8, ptr %0, i64 4
  %.not5765 = icmp eq i32 %2, 0
  br i1 %.not5765, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader
  %25 = getelementptr inbounds i8, ptr %0, i64 16
  %26 = getelementptr inbounds i8, ptr %0, i64 8
  %27 = getelementptr inbounds i8, ptr %0, i64 12
  %.pre = load i16, ptr %23, align 4, !tbaa !16
  br label %31

28:                                               ; preds = %21
  %29 = load i8, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 160), align 4, !tbaa !5
  %30 = or i8 %29, 2
  store i8 %30, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 160), align 4, !tbaa !5
  br label %.loopexit

31:                                               ; preds = %.lr.ph, %74
  %32 = phi i16 [ %.pre, %.lr.ph ], [ %69, %74 ]
  %.04567 = phi i32 [ %2, %.lr.ph ], [ %64, %74 ]
  %.04666 = phi ptr [ %1, %.lr.ph ], [ %66, %74 ]
  %33 = icmp ugt i16 %32, 4096
  br i1 %33, label %.loopexit, label %34

34:                                               ; preds = %31
  %35 = zext nneg i16 %32 to i32
  %36 = sub nuw nsw i32 4096, %35
  %.not58 = icmp eq i16 %32, 4096
  br i1 %.not58, label %37, label %51

37:                                               ; preds = %34
  %38 = call i32 @sflash_get_free_sector()
  store i32 %38, ptr %4, align 4, !tbaa !17
  %.not59 = icmp eq i32 %38, 0
  br i1 %.not59, label %.loopexit, label %39

39:                                               ; preds = %37
  %40 = load i32, ptr %24, align 4, !tbaa !18
  %41 = add i32 %40, 8
  %42 = call signext i16 @sflash_SectorWrite(i32 noundef %41, ptr noundef nonnull %4, i32 noundef 4) #4
  %.not60 = icmp eq i16 %42, 0
  br i1 %.not60, label %43, label %.loopexit

43:                                               ; preds = %39
  %44 = load i32, ptr %4, align 4, !tbaa !17
  store i32 %44, ptr %24, align 4, !tbaa !18
  store i16 12, ptr %23, align 4, !tbaa !16
  store i32 -41637, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 32), align 4, !tbaa !19
  %45 = load i32, ptr %0, align 4, !tbaa !11
  store i32 %45, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 36), align 4, !tbaa !19
  %46 = load i32, ptr %24, align 4, !tbaa !18
  %47 = call signext i16 @sflash_SectorWrite(i32 noundef %46, ptr noundef nonnull getelementptr inbounds (i8, ptr @sflash_info, i64 32), i32 noundef 8) #4
  %.not61 = icmp eq i16 %47, 0
  br i1 %.not61, label %48, label %.loopexit

48:                                               ; preds = %43
  %49 = load i32, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 16), align 4, !tbaa !20
  %50 = add i32 %49, -4096
  store i32 %50, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 16), align 4, !tbaa !20
  br label %51

51:                                               ; preds = %48, %34
  %.044 = phi i32 [ %36, %34 ], [ 4084, %48 ]
  %spec.select = call i32 @llvm.umin.i32(i32 %.04567, i32 %.044)
  %52 = load i8, ptr %10, align 2, !tbaa !13
  %53 = and i8 %52, 16
  %.not62 = icmp eq i8 %53, 0
  br i1 %.not62, label %57, label %54

54:                                               ; preds = %51
  %55 = load i32, ptr %25, align 4, !tbaa !21
  %56 = call i32 @fs_track_crc32(ptr noundef %.04666, i32 noundef %spec.select, i32 noundef %55)
  store i32 %56, ptr %25, align 4, !tbaa !21
  br label %57

57:                                               ; preds = %54, %51
  %58 = load i32, ptr %24, align 4, !tbaa !18
  %59 = load i16, ptr %23, align 4, !tbaa !16
  %60 = zext i16 %59 to i32
  %61 = add i32 %58, %60
  %62 = call signext i16 @sflash_SectorWrite(i32 noundef %61, ptr noundef %.04666, i32 noundef %spec.select) #4
  %.not63 = icmp eq i16 %62, 0
  br i1 %.not63, label %63, label %.loopexit

63:                                               ; preds = %57
  %64 = sub i32 %.04567, %spec.select
  %65 = zext nneg i32 %spec.select to i64
  %66 = getelementptr inbounds i8, ptr %.04666, i64 %65
  %67 = load i16, ptr %23, align 4, !tbaa !16
  %68 = trunc nuw nsw i32 %spec.select to i16
  %69 = add i16 %67, %68
  store i16 %69, ptr %23, align 4, !tbaa !16
  %70 = load i32, ptr %26, align 4, !tbaa !14
  %71 = add i32 %70, %spec.select
  store i32 %71, ptr %26, align 4, !tbaa !14
  %72 = load i32, ptr %27, align 4, !tbaa !15
  %.not64 = icmp eq i32 %72, -1
  br i1 %.not64, label %74, label %73

73:                                               ; preds = %63
  store i32 %71, ptr %27, align 4, !tbaa !15
  br label %74

74:                                               ; preds = %73, %63
  %.not57 = icmp eq i32 %64, 0
  br i1 %.not57, label %.loopexit, label %31, !llvm.loop !22

.loopexit:                                        ; preds = %31, %37, %39, %43, %57, %74, %.preheader, %19, %14, %7, %3, %28
  %.047 = phi i16 [ -147, %28 ], [ -148, %3 ], [ -117, %7 ], [ -130, %14 ], [ -118, %19 ], [ 0, %.preheader ], [ -112, %31 ], [ -113, %37 ], [ %42, %39 ], [ %47, %43 ], [ %62, %57 ], [ 0, %74 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  ret i16 %.047
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #3

attributes #0 = { mustprogress 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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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, !8, i64 160}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 20, !10, i64 22, !10, i64 24, !10, i64 26, !10, i64 28, !8, i64 32, !8, i64 160}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!12, !7, i64 0}
!12 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !7, i64 20, !10, i64 24, !8, i64 26}
!13 = !{!12, !8, i64 26}
!14 = !{!12, !7, i64 8}
!15 = !{!12, !7, i64 12}
!16 = !{!12, !10, i64 24}
!17 = !{!7, !7, i64 0}
!18 = !{!12, !7, i64 4}
!19 = !{!8, !8, i64 0}
!20 = !{!6, !7, i64 16}
!21 = !{!12, !7, i64 16}
!22 = distinct !{!22, !23}
!23 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass