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

; 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: nounwind uwtable
declare dso_local i32 @fs_strlen(ptr noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @fs_strncpy(ptr noundef, ptr noundef, i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare dso_local void @fs_memset(ptr noundef, i8 noundef zeroext, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local signext i16 @fs_strcmp(ptr noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @fs_get_secs() #0

declare signext i16 @_supply_voltage_check() #2

declare void @sflash_read(i32 noundef, ptr noundef, i16 noundef zeroext) #2

declare signext i16 @sflash_SectorErase(i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local signext i16 @fs_open(ptr noundef %0, ptr noundef %1, i8 noundef zeroext %2) #0 {
  %4 = alloca i16, align 2
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i8, align 1
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  %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 i8 %2, ptr %7, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  store i32 0, ptr %10, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !10
  %13 = load i8, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 11), align 4, !tbaa !12
  %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 %204

18:                                               ; preds = %3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.FS_DESC, ptr %19, i32 0, i32 0
  store i32 0, ptr %20, align 4, !tbaa !15
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.FS_DESC, ptr %21, i32 0, i32 4
  store i32 -1, ptr %22, align 4, !tbaa !17
  %23 = load i32, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 2), align 4, !tbaa !18
  %24 = icmp eq i32 %23, -1
  br i1 %24, label %25, label %26

25:                                               ; preds = %18
  store i16 -108, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %204

26:                                               ; preds = %18
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = load i8, ptr %27, align 1, !tbaa !9
  %29 = icmp ne i8 %28, 0
  br i1 %29, label %30, label %34

30:                                               ; preds = %26
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = call i32 @fs_strlen(ptr noundef %31)
  %33 = icmp ugt i32 %32, 21
  br i1 %33, label %34, label %35

34:                                               ; preds = %30, %26
  store i16 -110, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %204

35:                                               ; preds = %30
  store i16 0, ptr %9, align 2, !tbaa !19
  br label %36

36:                                               ; preds = %64, %35
  %37 = load i16, ptr %9, align 2, !tbaa !19
  %38 = zext i16 %37 to i32
  %39 = load i16, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 5), align 4, !tbaa !20
  %40 = zext i16 %39 to i32
  %41 = icmp slt i32 %38, %40
  br i1 %41, label %42, label %67

42:                                               ; preds = %36
  %43 = load i16, ptr %9, align 2, !tbaa !19
  %44 = zext i16 %43 to i32
  %45 = mul nsw i32 %44, 4
  %46 = add nsw i32 12, %45
  call void @sflash_read(i32 noundef %46, ptr noundef %10, i16 noundef zeroext 4)
  %47 = load i32, ptr %10, align 4, !tbaa !10
  call void @sflash_read(i32 noundef %47, ptr noundef getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i16 noundef zeroext 48)
  %48 = load i32, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), align 4, !tbaa !9
  %49 = icmp eq i32 %48, -57040
  br i1 %49, label %50, label %52

50:                                               ; preds = %42
  %51 = load i32, ptr %10, align 4, !tbaa !10
  store i32 %51, ptr %11, align 4, !tbaa !10
  br label %63

52:                                               ; preds = %42
  %53 = load i32, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), align 4, !tbaa !9
  %54 = icmp ne i32 %53, -54982
  br i1 %54, label %55, label %56

55:                                               ; preds = %52
  store i16 -114, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %204

56:                                               ; preds = %52
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = call signext i16 @fs_strcmp(ptr noundef %57, ptr noundef getelementptr inbounds ([128 x i8], ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i64 0, i64 24))
  %59 = icmp ne i16 %58, 0
  br i1 %59, label %61, label %60

60:                                               ; preds = %56
  br label %67

61:                                               ; preds = %56
  br label %62

62:                                               ; preds = %61
  br label %63

63:                                               ; preds = %62, %50
  store i32 0, ptr %10, align 4, !tbaa !10
  br label %64

64:                                               ; preds = %63
  %65 = load i16, ptr %9, align 2, !tbaa !19
  %66 = add i16 %65, 1
  store i16 %66, ptr %9, align 2, !tbaa !19
  br label %36, !llvm.loop !21

67:                                               ; preds = %60, %36
  %68 = load i8, ptr %7, align 1, !tbaa !9
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.FS_DESC, ptr %69, i32 0, i32 7
  store i8 %68, ptr %70, align 2, !tbaa !23
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.FS_DESC, ptr %71, i32 0, i32 6
  store i16 48, ptr %72, align 4, !tbaa !24
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.FS_DESC, ptr %73, i32 0, i32 2
  store i32 0, ptr %74, align 4, !tbaa !25
  %75 = load ptr, ptr %5, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.FS_DESC, ptr %75, i32 0, i32 3
  store i32 0, ptr %76, align 4, !tbaa !26
  %77 = load i32, ptr %10, align 4, !tbaa !10
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %127

79:                                               ; preds = %67
  %80 = load i32, ptr %10, align 4, !tbaa !10
  %81 = load ptr, ptr %5, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.FS_DESC, ptr %81, i32 0, i32 0
  store i32 %80, ptr %82, align 4, !tbaa !15
  %83 = load i32, ptr %10, align 4, !tbaa !10
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.FS_DESC, ptr %84, i32 0, i32 1
  store i32 %83, ptr %85, align 4, !tbaa !27
  %86 = load i8, ptr %7, align 1, !tbaa !9
  %87 = zext i8 %86 to i32
  %88 = and i32 %87, 9
  %89 = icmp ne i32 %88, 0
  br i1 %89, label %90, label %118

90:                                               ; preds = %79
  %91 = load i32, ptr getelementptr inbounds ([32 x i32], ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i64 0, i64 3), align 4, !tbaa !9
  %92 = load ptr, ptr %5, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.FS_DESC, ptr %92, i32 0, i32 3
  store i32 %91, ptr %93, align 4, !tbaa !26
  %94 = load ptr, ptr %5, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.FS_DESC, ptr %94, i32 0, i32 3
  %96 = load i32, ptr %95, align 4, !tbaa !26
  %97 = icmp eq i32 %96, -1
  br i1 %97, label %98, label %105

98:                                               ; preds = %90
  %99 = load ptr, ptr %5, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.FS_DESC, ptr %99, i32 0, i32 7
  %101 = load i8, ptr %100, align 2, !tbaa !23
  %102 = zext i8 %101 to i32
  %103 = or i32 %102, 32
  %104 = trunc i32 %103 to i8
  store i8 %104, ptr %100, align 2, !tbaa !23
  br label %105

105:                                              ; preds = %98, %90
  %106 = load i8, ptr getelementptr inbounds ([128 x i8], ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i64 0, i64 46), align 2, !tbaa !9
  %107 = zext i8 %106 to i32
  %108 = and i32 %107, 192
  %109 = load ptr, ptr %5, align 8, !tbaa !5
  %110 = getelementptr inbounds %struct.FS_DESC, ptr %109, i32 0, i32 7
  %111 = load i8, ptr %110, align 2, !tbaa !23
  %112 = zext i8 %111 to i32
  %113 = or i32 %112, %108
  %114 = trunc i32 %113 to i8
  store i8 %114, ptr %110, align 2, !tbaa !23
  %115 = load i32, ptr getelementptr inbounds ([32 x i32], ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i64 0, i64 5), align 4, !tbaa !9
  %116 = load ptr, ptr %5, align 8, !tbaa !5
  %117 = getelementptr inbounds %struct.FS_DESC, ptr %116, i32 0, i32 5
  store i32 %115, ptr %117, align 4, !tbaa !28
  store i16 0, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %204

118:                                              ; preds = %79
  %119 = load i32, ptr %10, align 4, !tbaa !10
  %120 = call signext i16 @flash_set2delete(i32 noundef %119)
  store i16 %120, ptr %8, align 2, !tbaa !19
  %121 = load i16, ptr %8, align 2, !tbaa !19
  %122 = icmp ne i16 %121, 0
  br i1 %122, label %123, label %125

123:                                              ; preds = %118
  %124 = load i16, ptr %8, align 2, !tbaa !19
  store i16 %124, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %204

125:                                              ; preds = %118
  %126 = load i32, ptr %10, align 4, !tbaa !10
  store i32 %126, ptr %11, align 4, !tbaa !10
  br label %134

127:                                              ; preds = %67
  %128 = load i8, ptr %7, align 1, !tbaa !9
  %129 = zext i8 %128 to i32
  %130 = and i32 %129, 2
  %131 = icmp ne i32 %130, 0
  br i1 %131, label %133, label %132

132:                                              ; preds = %127
  store i16 -124, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %204

133:                                              ; preds = %127
  br label %134

134:                                              ; preds = %133, %125
  %135 = call signext i16 @_supply_voltage_check()
  %136 = icmp ne i16 %135, 0
  br i1 %136, label %137, label %142

137:                                              ; preds = %134
  %138 = load i8, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 11), align 4, !tbaa !12
  %139 = zext i8 %138 to i32
  %140 = or i32 %139, 2
  %141 = trunc i32 %140 to i8
  store i8 %141, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 11), align 4, !tbaa !12
  store i16 -147, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %204

142:                                              ; preds = %134
  %143 = load i32, ptr %11, align 4, !tbaa !10
  %144 = icmp ne i32 %143, 0
  br i1 %144, label %172, label %145

145:                                              ; preds = %142
  %146 = call i32 @sflash_get_free_sector()
  store i32 %146, ptr %11, align 4, !tbaa !10
  %147 = load i32, ptr %11, align 4, !tbaa !10
  %148 = icmp ne i32 %147, 0
  br i1 %148, label %150, label %149

149:                                              ; preds = %145
  store i16 -113, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %204

150:                                              ; preds = %145
  %151 = load i16, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 5), align 4, !tbaa !20
  %152 = zext i16 %151 to i32
  %153 = mul nsw i32 %152, 4
  %154 = add nsw i32 12, %153
  %155 = icmp sge i32 %154, 4092
  br i1 %155, label %156, label %157

156:                                              ; preds = %150
  store i16 -111, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %204

157:                                              ; preds = %150
  %158 = load i16, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 5), align 4, !tbaa !20
  %159 = zext i16 %158 to i32
  %160 = mul nsw i32 %159, 4
  %161 = add nsw i32 12, %160
  %162 = call signext i16 @sflash_SectorWrite(i32 noundef %161, ptr noundef %11, i32 noundef 4)
  store i16 %162, ptr %8, align 2, !tbaa !19
  %163 = load i16, ptr %8, align 2, !tbaa !19
  %164 = icmp ne i16 %163, 0
  br i1 %164, label %165, label %167

165:                                              ; preds = %157
  %166 = load i16, ptr %8, align 2, !tbaa !19
  store i16 %166, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %204

167:                                              ; preds = %157
  %168 = load i32, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 4), align 4, !tbaa !29
  %169 = sub i32 %168, 4096
  store i32 %169, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 4), align 4, !tbaa !29
  %170 = load i16, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 5), align 4, !tbaa !20
  %171 = add i16 %170, 1
  store i16 %171, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 5), align 4, !tbaa !20
  br label %180

172:                                              ; preds = %142
  %173 = load i32, ptr %11, align 4, !tbaa !10
  %174 = call signext i16 @sflash_SectorErase(i32 noundef %173)
  store i16 %174, ptr %8, align 2, !tbaa !19
  %175 = load i16, ptr %8, align 2, !tbaa !19
  %176 = icmp ne i16 %175, 0
  br i1 %176, label %177, label %179

177:                                              ; preds = %172
  %178 = load i16, ptr %8, align 2, !tbaa !19
  store i16 %178, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %204

179:                                              ; preds = %172
  br label %180

180:                                              ; preds = %179, %167
  call void @fs_memset(ptr noundef getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i8 noundef zeroext -1, i32 noundef 48)
  store i32 -54982, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), align 4, !tbaa !9
  %181 = load ptr, ptr %6, align 8, !tbaa !5
  call void @fs_strncpy(ptr noundef getelementptr inbounds ([128 x i8], ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i64 0, i64 24), ptr noundef %181, i8 noundef zeroext 21)
  %182 = call i32 @fs_get_secs()
  %183 = load ptr, ptr %5, align 8, !tbaa !5
  %184 = getelementptr inbounds %struct.FS_DESC, ptr %183, i32 0, i32 5
  store i32 %182, ptr %184, align 4, !tbaa !28
  %185 = load ptr, ptr %5, align 8, !tbaa !5
  %186 = getelementptr inbounds %struct.FS_DESC, ptr %185, i32 0, i32 5
  %187 = load i32, ptr %186, align 4, !tbaa !28
  store i32 %187, ptr getelementptr inbounds ([32 x i32], ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i64 0, i64 5), align 4, !tbaa !9
  %188 = load i8, ptr %7, align 1, !tbaa !9
  store i8 %188, ptr getelementptr inbounds ([128 x i8], ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i64 0, i64 46), align 2, !tbaa !9
  %189 = load i32, ptr %11, align 4, !tbaa !10
  %190 = call signext i16 @sflash_SectorWrite(i32 noundef %189, ptr noundef getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i32 noundef 48)
  store i16 %190, ptr %8, align 2, !tbaa !19
  %191 = load i16, ptr %8, align 2, !tbaa !19
  %192 = icmp ne i16 %191, 0
  br i1 %192, label %193, label %195

193:                                              ; preds = %180
  %194 = load i16, ptr %8, align 2, !tbaa !19
  store i16 %194, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %204

195:                                              ; preds = %180
  %196 = load i32, ptr %11, align 4, !tbaa !10
  %197 = load ptr, ptr %5, align 8, !tbaa !5
  %198 = getelementptr inbounds %struct.FS_DESC, ptr %197, i32 0, i32 0
  store i32 %196, ptr %198, align 4, !tbaa !15
  %199 = load i32, ptr %11, align 4, !tbaa !10
  %200 = load ptr, ptr %5, align 8, !tbaa !5
  %201 = getelementptr inbounds %struct.FS_DESC, ptr %200, i32 0, i32 1
  store i32 %199, ptr %201, align 4, !tbaa !27
  %202 = load i16, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 6), align 2, !tbaa !30
  %203 = add i16 %202, 1
  store i16 %203, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 6), align 2, !tbaa !30
  store i16 0, ptr %4, align 2
  store i32 1, ptr %12, align 4
  br label %204

204:                                              ; preds = %195, %193, %177, %165, %156, %149, %137, %132, %123, %105, %55, %34, %25, %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 2, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #3
  %205 = load i16, ptr %4, align 2
  ret i16 %205
}

; Function Attrs: nounwind uwtable
declare hidden signext i16 @flash_set2delete(i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @sflash_get_free_sector() #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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !7, i64 160}
!13 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !14, i64 20, !14, i64 22, !14, i64 24, !14, i64 26, !14, i64 28, !7, i64 32, !7, i64 160}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !11, i64 0}
!16 = !{!"", !11, i64 0, !11, i64 4, !11, i64 8, !11, i64 12, !11, i64 16, !11, i64 20, !14, i64 24, !7, i64 26}
!17 = !{!16, !11, i64 16}
!18 = !{!13, !11, i64 8}
!19 = !{!14, !14, i64 0}
!20 = !{!13, !14, i64 20}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = !{!16, !7, i64 26}
!24 = !{!16, !14, i64 24}
!25 = !{!16, !11, i64 8}
!26 = !{!16, !11, i64 12}
!27 = !{!16, !11, i64 4}
!28 = !{!16, !11, i64 20}
!29 = !{!13, !11, i64 16}
!30 = !{!13, !14, i64 22}


; 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: nounwind uwtable
declare dso_local i32 @fs_strlen(ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @fs_strncpy(ptr noundef, ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @fs_memset(ptr noundef, i8 noundef zeroext, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local signext i16 @fs_strcmp(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @fs_get_secs() local_unnamed_addr #0

declare signext i16 @_supply_voltage_check() local_unnamed_addr #2

declare void @sflash_read(i32 noundef, ptr noundef, i16 noundef zeroext) local_unnamed_addr #2

declare signext i16 @sflash_SectorErase(i32 noundef) local_unnamed_addr #2

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

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

8:                                                ; preds = %3
  store i32 0, ptr %0, align 4, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 -1, ptr %9, align 4, !tbaa !14
  %10 = load i32, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 8), align 4, !tbaa !15
  %11 = icmp eq i32 %10, -1
  br i1 %11, label %.loopexit, label %12

12:                                               ; preds = %8
  %13 = load i8, ptr %1, align 1, !tbaa !16
  %.not46 = icmp eq i8 %13, 0
  br i1 %.not46, label %.loopexit, label %14

14:                                               ; preds = %12
  %15 = tail call i32 @fs_strlen(ptr noundef nonnull %1)
  %16 = icmp ugt i32 %15, 21
  br i1 %16, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %14
  %17 = load i16, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 20), align 4, !tbaa !17
  %.not61 = icmp eq i16 %17, 0
  br i1 %.not61, label %._crit_edge.thread, label %.lr.ph

.lr.ph:                                           ; preds = %.preheader, %27
  %18 = phi i32 [ %28, %27 ], [ 0, %.preheader ]
  %indvars.iv = phi i32 [ %indvars.iv.next, %27 ], [ 0, %.preheader ]
  %19 = shl nuw nsw i32 %indvars.iv, 2
  %20 = add nuw nsw i32 %19, 12
  call void @sflash_read(i32 noundef %20, ptr noundef nonnull %4, i16 noundef zeroext 4) #3
  %21 = load i32, ptr %4, align 4, !tbaa !5
  call void @sflash_read(i32 noundef %21, ptr noundef nonnull getelementptr inbounds (i8, ptr @sflash_info, i64 32), i16 noundef zeroext 48) #3
  %22 = load i32, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 32), align 4, !tbaa !16
  switch i32 %22, label %.loopexit [
    i32 -57040, label %23
    i32 -54982, label %25
  ]

23:                                               ; preds = %.lr.ph
  %24 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %24, ptr %5, align 4, !tbaa !5
  br label %27

25:                                               ; preds = %.lr.ph
  %26 = call signext i16 @fs_strcmp(ptr noundef nonnull %1, ptr noundef nonnull getelementptr inbounds (i8, ptr @sflash_info, i64 56))
  %.not48 = icmp eq i16 %26, 0
  br i1 %.not48, label %._crit_edge, label %27

27:                                               ; preds = %25, %23
  %28 = phi i32 [ %18, %25 ], [ %24, %23 ]
  store i32 0, ptr %4, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i32 %indvars.iv, 1
  %29 = load i16, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 20), align 4, !tbaa !17
  %30 = zext i16 %29 to i32
  %31 = icmp ult i32 %indvars.iv.next, %30
  br i1 %31, label %.lr.ph, label %._crit_edge.thread, !llvm.loop !18

._crit_edge.thread:                               ; preds = %27, %.preheader
  %.ph = phi i32 [ 0, %.preheader ], [ %28, %27 ]
  %32 = getelementptr inbounds i8, ptr %0, i64 26
  store i8 %2, ptr %32, align 2, !tbaa !20
  %33 = getelementptr inbounds i8, ptr %0, i64 24
  store i16 48, ptr %33, align 4, !tbaa !21
  %34 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 0, ptr %34, align 4, !tbaa !22
  %35 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 0, ptr %35, align 4, !tbaa !23
  br label %59

._crit_edge:                                      ; preds = %25
  %.pre.pre = load i32, ptr %4, align 4, !tbaa !5
  %36 = getelementptr inbounds i8, ptr %0, i64 26
  store i8 %2, ptr %36, align 2, !tbaa !20
  %37 = getelementptr inbounds i8, ptr %0, i64 24
  store i16 48, ptr %37, align 4, !tbaa !21
  %38 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 0, ptr %38, align 4, !tbaa !22
  %39 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 0, ptr %39, align 4, !tbaa !23
  %.not49 = icmp eq i32 %.pre.pre, 0
  br i1 %.not49, label %59, label %40

40:                                               ; preds = %._crit_edge
  store i32 %.pre.pre, ptr %0, align 4, !tbaa !12
  %41 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %.pre.pre, ptr %41, align 4, !tbaa !24
  %42 = and i8 %2, 9
  %.not51 = icmp eq i8 %42, 0
  br i1 %.not51, label %55, label %43

43:                                               ; preds = %40
  %44 = load i32, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 44), align 4, !tbaa !16
  store i32 %44, ptr %39, align 4, !tbaa !23
  %45 = icmp eq i32 %44, -1
  br i1 %45, label %46, label %48

46:                                               ; preds = %43
  %47 = or i8 %2, 32
  store i8 %47, ptr %36, align 2, !tbaa !20
  br label %48

48:                                               ; preds = %46, %43
  %49 = phi i8 [ %47, %46 ], [ %2, %43 ]
  %50 = load i8, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 78), align 2, !tbaa !16
  %51 = and i8 %50, -64
  %52 = or i8 %49, %51
  store i8 %52, ptr %36, align 2, !tbaa !20
  %53 = load i32, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 52), align 4, !tbaa !16
  %54 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %53, ptr %54, align 4, !tbaa !25
  br label %.loopexit

55:                                               ; preds = %40
  %56 = call signext i16 @flash_set2delete(i32 noundef %.pre.pre)
  %.not52 = icmp eq i16 %56, 0
  br i1 %.not52, label %57, label %.loopexit

57:                                               ; preds = %55
  %58 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %58, ptr %5, align 4, !tbaa !5
  br label %62

59:                                               ; preds = %._crit_edge.thread, %._crit_edge
  %60 = phi i32 [ %.ph, %._crit_edge.thread ], [ %18, %._crit_edge ]
  %61 = and i8 %2, 2
  %.not50 = icmp eq i8 %61, 0
  br i1 %.not50, label %.loopexit, label %62

62:                                               ; preds = %59, %57
  %63 = phi i32 [ %60, %59 ], [ %58, %57 ]
  %64 = call signext i16 @_supply_voltage_check() #3
  %.not53 = icmp eq i16 %64, 0
  br i1 %.not53, label %68, label %65

65:                                               ; preds = %62
  %66 = load i8, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 160), align 4, !tbaa !9
  %67 = or i8 %66, 2
  store i8 %67, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 160), align 4, !tbaa !9
  br label %.loopexit

68:                                               ; preds = %62
  %.not54 = icmp eq i32 %63, 0
  br i1 %.not54, label %69, label %83

69:                                               ; preds = %68
  %70 = call i32 @sflash_get_free_sector()
  store i32 %70, ptr %5, align 4, !tbaa !5
  %.not55 = icmp eq i32 %70, 0
  br i1 %.not55, label %.loopexit, label %71

71:                                               ; preds = %69
  %72 = load i16, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 20), align 4, !tbaa !17
  %73 = icmp ugt i16 %72, 1019
  br i1 %73, label %.loopexit, label %74

74:                                               ; preds = %71
  %75 = shl nuw nsw i16 %72, 2
  %narrow = add nuw nsw i16 %75, 12
  %76 = zext nneg i16 %narrow to i32
  %77 = call signext i16 @sflash_SectorWrite(i32 noundef %76, ptr noundef nonnull %5, i32 noundef 4) #3
  %.not56 = icmp eq i16 %77, 0
  br i1 %.not56, label %78, label %.loopexit

78:                                               ; preds = %74
  %79 = load i32, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 16), align 4, !tbaa !26
  %80 = add i32 %79, -4096
  store i32 %80, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 16), align 4, !tbaa !26
  %81 = load i16, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 20), align 4, !tbaa !17
  %82 = add i16 %81, 1
  store i16 %82, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 20), align 4, !tbaa !17
  br label %85

83:                                               ; preds = %68
  %84 = call signext i16 @sflash_SectorErase(i32 noundef %63) #3
  %.not57 = icmp eq i16 %84, 0
  br i1 %.not57, label %85, label %.loopexit

85:                                               ; preds = %83, %78
  call void @fs_memset(ptr noundef nonnull getelementptr inbounds (i8, ptr @sflash_info, i64 32), i8 noundef zeroext -1, i32 noundef 48)
  store i32 -54982, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 32), align 4, !tbaa !16
  call void @fs_strncpy(ptr noundef nonnull getelementptr inbounds (i8, ptr @sflash_info, i64 56), ptr noundef nonnull %1, i8 noundef zeroext 21)
  %86 = call i32 @fs_get_secs()
  %87 = getelementptr inbounds i8, ptr %0, i64 20
  store i32 %86, ptr %87, align 4, !tbaa !25
  store i32 %86, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 52), align 4, !tbaa !16
  store i8 %2, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 78), align 2, !tbaa !16
  %88 = load i32, ptr %5, align 4, !tbaa !5
  %89 = call signext i16 @sflash_SectorWrite(i32 noundef %88, ptr noundef nonnull getelementptr inbounds (i8, ptr @sflash_info, i64 32), i32 noundef 48) #3
  %.not58 = icmp eq i16 %89, 0
  br i1 %.not58, label %90, label %.loopexit

90:                                               ; preds = %85
  %91 = load i32, ptr %5, align 4, !tbaa !5
  store i32 %91, ptr %0, align 4, !tbaa !12
  %92 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %91, ptr %92, align 4, !tbaa !24
  %93 = load i16, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 22), align 2, !tbaa !27
  %94 = add i16 %93, 1
  store i16 %94, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 22), align 2, !tbaa !27
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph, %85, %83, %74, %71, %69, %59, %55, %12, %14, %8, %3, %90, %65, %48
  %.036 = phi i16 [ 0, %48 ], [ -147, %65 ], [ 0, %90 ], [ -148, %3 ], [ -108, %8 ], [ -110, %14 ], [ -110, %12 ], [ %56, %55 ], [ -124, %59 ], [ -113, %69 ], [ -111, %71 ], [ %77, %74 ], [ %84, %83 ], [ %89, %85 ], [ -114, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #3
  ret i16 %.036
}

; Function Attrs: nounwind uwtable
declare hidden signext i16 @flash_set2delete(i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @sflash_get_free_sector() local_unnamed_addr #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" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !7, i64 160}
!10 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !11, i64 20, !11, i64 22, !11, i64 24, !11, i64 26, !11, i64 28, !7, i64 32, !7, i64 160}
!11 = !{!"short", !7, i64 0}
!12 = !{!13, !6, i64 0}
!13 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !6, i64 20, !11, i64 24, !7, i64 26}
!14 = !{!13, !6, i64 16}
!15 = !{!10, !6, i64 8}
!16 = !{!7, !7, i64 0}
!17 = !{!10, !11, i64 20}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!13, !7, i64 26}
!21 = !{!13, !11, i64 24}
!22 = !{!13, !6, i64 8}
!23 = !{!13, !6, i64 12}
!24 = !{!13, !6, i64 4}
!25 = !{!13, !6, i64 20}
!26 = !{!10, !6, i64 16}
!27 = !{!10, !11, i64 22}


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