; LLVM IR from littlefs-project/littlefs :: bd (lfs_emubd)

; 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.timespec = type { i64, i64 }
%struct.lfs_config = type { ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, i32, i32, i32, i32, i32 }
%struct.lfs_emubd = type { ptr, i64, i64, i64, i32, i32, ptr, ptr, ptr }
%struct.lfs_emubd_config = type { i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, i8, ptr, i64, i64, i64 }
%struct.lfs_emubd_block = type { i32, i32, [0 x i8] }
%struct.lfs_emubd_disk = type { i32, i32, ptr }

@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@__PRETTY_FUNCTION__.lfs_emubd_erase = external hidden unnamed_addr constant [60 x i8], align 1

; 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: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #2

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

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #3

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #4

declare i32 @nanosleep(ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden ptr @lfs_emubd_mutblock(ptr noundef, ptr noundef) #5

; Function Attrs: nounwind
declare i64 @lseek(i32 noundef, i64 noundef, i32 noundef) #6

; Function Attrs: nounwind uwtable
declare hidden i32 @lfs_emubd_powerloss(ptr noundef) #5

; Function Attrs: nounwind uwtable
define dso_local i32 @lfs_emubd_erase(ptr noundef %0, i32 noundef %1) #5 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca %struct.timespec, align 8
  %15 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %16 = load ptr, ptr %4, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.lfs_config, ptr %16, i32 0, i32 0
  %18 = load ptr, ptr %17, align 8, !tbaa !11
  store ptr %18, ptr %6, align 8, !tbaa !5
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.lfs_emubd, ptr %20, i32 0, i32 8
  %22 = load ptr, ptr %21, align 8, !tbaa !13
  %23 = getelementptr inbounds %struct.lfs_emubd_config, ptr %22, i32 0, i32 3
  %24 = load i32, ptr %23, align 4, !tbaa !16
  %25 = icmp ult i32 %19, %24
  br i1 %25, label %26, label %27

26:                                               ; preds = %2
  br label %28

27:                                               ; preds = %2
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 437, ptr noundef @__PRETTY_FUNCTION__.lfs_emubd_erase) #8
  unreachable

28:                                               ; preds = %26
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.lfs_emubd, ptr %29, i32 0, i32 8
  %31 = load ptr, ptr %30, align 8, !tbaa !13
  %32 = getelementptr inbounds %struct.lfs_emubd_config, ptr %31, i32 0, i32 8
  %33 = load i32, ptr %32, align 8, !tbaa !19
  %34 = icmp eq i32 %33, 1
  br i1 %34, label %35, label %54

35:                                               ; preds = %28
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.lfs_emubd, ptr %36, i32 0, i32 5
  %38 = load i32, ptr %37, align 4, !tbaa !20
  %39 = icmp eq i32 %38, -1
  br i1 %39, label %40, label %54

40:                                               ; preds = %35
  %41 = load i32, ptr %5, align 4, !tbaa !9
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.lfs_emubd, ptr %42, i32 0, i32 5
  store i32 %41, ptr %43, align 4, !tbaa !20
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.lfs_emubd, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %45, align 8, !tbaa !21
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = getelementptr inbounds ptr, ptr %46, i64 %48
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = call ptr @lfs_emubd_incblock(ptr noundef %50)
  %52 = load ptr, ptr %6, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.lfs_emubd, ptr %52, i32 0, i32 6
  store ptr %51, ptr %53, align 8, !tbaa !22
  br label %54

54:                                               ; preds = %40, %35, %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #7
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = load ptr, ptr %6, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.lfs_emubd, ptr %56, i32 0, i32 0
  %58 = load ptr, ptr %57, align 8, !tbaa !21
  %59 = load i32, ptr %5, align 4, !tbaa !9
  %60 = zext i32 %59 to i64
  %61 = getelementptr inbounds ptr, ptr %58, i64 %60
  %62 = call ptr @lfs_emubd_mutblock(ptr noundef %55, ptr noundef %61)
  store ptr %62, ptr %7, align 8, !tbaa !5
  %63 = load ptr, ptr %7, align 8, !tbaa !5
  %64 = icmp ne ptr %63, null
  br i1 %64, label %66, label %65

65:                                               ; preds = %54
  store i32 -12, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %259

66:                                               ; preds = %54
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.lfs_emubd, ptr %67, i32 0, i32 8
  %69 = load ptr, ptr %68, align 8, !tbaa !13
  %70 = getelementptr inbounds %struct.lfs_emubd_config, ptr %69, i32 0, i32 5
  %71 = load i32, ptr %70, align 4, !tbaa !23
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %73, label %107

73:                                               ; preds = %66
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.lfs_emubd_block, ptr %74, i32 0, i32 1
  %76 = load i32, ptr %75, align 4, !tbaa !9
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.lfs_emubd, ptr %77, i32 0, i32 8
  %79 = load ptr, ptr %78, align 8, !tbaa !13
  %80 = getelementptr inbounds %struct.lfs_emubd_config, ptr %79, i32 0, i32 5
  %81 = load i32, ptr %80, align 4, !tbaa !23
  %82 = icmp uge i32 %76, %81
  br i1 %82, label %83, label %101

83:                                               ; preds = %73
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.lfs_emubd, ptr %84, i32 0, i32 8
  %86 = load ptr, ptr %85, align 8, !tbaa !13
  %87 = getelementptr inbounds %struct.lfs_emubd_config, ptr %86, i32 0, i32 6
  %88 = load i32, ptr %87, align 8, !tbaa !24
  %89 = icmp eq i32 %88, 1
  br i1 %89, label %90, label %91

90:                                               ; preds = %83
  store i32 -84, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %259

91:                                               ; preds = %83
  %92 = load ptr, ptr %6, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.lfs_emubd, ptr %92, i32 0, i32 8
  %94 = load ptr, ptr %93, align 8, !tbaa !13
  %95 = getelementptr inbounds %struct.lfs_emubd_config, ptr %94, i32 0, i32 6
  %96 = load i32, ptr %95, align 8, !tbaa !24
  %97 = icmp eq i32 %96, 4
  br i1 %97, label %98, label %99

98:                                               ; preds = %91
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %259

99:                                               ; preds = %91
  br label %100

100:                                              ; preds = %99
  br label %106

101:                                              ; preds = %73
  %102 = load ptr, ptr %7, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.lfs_emubd_block, ptr %102, i32 0, i32 1
  %104 = load i32, ptr %103, align 4, !tbaa !9
  %105 = add i32 %104, 1
  store i32 %105, ptr %103, align 4, !tbaa !9
  br label %106

106:                                              ; preds = %101, %100
  br label %107

107:                                              ; preds = %106, %66
  %108 = load ptr, ptr %6, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.lfs_emubd, ptr %108, i32 0, i32 8
  %110 = load ptr, ptr %109, align 8, !tbaa !13
  %111 = getelementptr inbounds %struct.lfs_emubd_config, ptr %110, i32 0, i32 4
  %112 = load i32, ptr %111, align 8, !tbaa !25
  %113 = icmp ne i32 %112, -1
  br i1 %113, label %114, label %188

114:                                              ; preds = %107
  %115 = load ptr, ptr %7, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.lfs_emubd_block, ptr %115, i32 0, i32 2
  %117 = getelementptr inbounds [0 x i8], ptr %116, i64 0, i64 0
  %118 = load ptr, ptr %6, align 8, !tbaa !5
  %119 = getelementptr inbounds %struct.lfs_emubd, ptr %118, i32 0, i32 8
  %120 = load ptr, ptr %119, align 8, !tbaa !13
  %121 = getelementptr inbounds %struct.lfs_emubd_config, ptr %120, i32 0, i32 4
  %122 = load i32, ptr %121, align 8, !tbaa !25
  %123 = trunc i32 %122 to i8
  %124 = load ptr, ptr %6, align 8, !tbaa !5
  %125 = getelementptr inbounds %struct.lfs_emubd, ptr %124, i32 0, i32 8
  %126 = load ptr, ptr %125, align 8, !tbaa !13
  %127 = getelementptr inbounds %struct.lfs_emubd_config, ptr %126, i32 0, i32 2
  %128 = load i32, ptr %127, align 8, !tbaa !26
  %129 = zext i32 %128 to i64
  call void @llvm.memset.p0.i64(ptr align 4 %117, i8 %123, i64 %129, i1 false)
  %130 = load ptr, ptr %6, align 8, !tbaa !5
  %131 = getelementptr inbounds %struct.lfs_emubd, ptr %130, i32 0, i32 7
  %132 = load ptr, ptr %131, align 8, !tbaa !27
  %133 = icmp ne ptr %132, null
  br i1 %133, label %134, label %187

134:                                              ; preds = %114
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %135 = load ptr, ptr %6, align 8, !tbaa !5
  %136 = getelementptr inbounds %struct.lfs_emubd, ptr %135, i32 0, i32 7
  %137 = load ptr, ptr %136, align 8, !tbaa !27
  %138 = getelementptr inbounds %struct.lfs_emubd_disk, ptr %137, i32 0, i32 1
  %139 = load i32, ptr %138, align 4, !tbaa !28
  %140 = load i32, ptr %5, align 4, !tbaa !9
  %141 = zext i32 %140 to i64
  %142 = load ptr, ptr %6, align 8, !tbaa !5
  %143 = getelementptr inbounds %struct.lfs_emubd, ptr %142, i32 0, i32 8
  %144 = load ptr, ptr %143, align 8, !tbaa !13
  %145 = getelementptr inbounds %struct.lfs_emubd_config, ptr %144, i32 0, i32 2
  %146 = load i32, ptr %145, align 8, !tbaa !26
  %147 = zext i32 %146 to i64
  %148 = mul nsw i64 %141, %147
  %149 = call i64 @lseek(i32 noundef %139, i64 noundef %148, i32 noundef 0) #7
  store i64 %149, ptr %9, align 8, !tbaa !30
  %150 = load i64, ptr %9, align 8, !tbaa !30
  %151 = icmp slt i64 %150, 0
  br i1 %151, label %152, label %157

152:                                              ; preds = %134
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #7
  %153 = call ptr @__errno_location() #9
  %154 = load i32, ptr %153, align 4, !tbaa !9
  %155 = sub nsw i32 0, %154
  store i32 %155, ptr %10, align 4, !tbaa !9
  %156 = load i32, ptr %10, align 4, !tbaa !9
  store i32 %156, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  br label %184

157:                                              ; preds = %134
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  %158 = load ptr, ptr %6, align 8, !tbaa !5
  %159 = getelementptr inbounds %struct.lfs_emubd, ptr %158, i32 0, i32 7
  %160 = load ptr, ptr %159, align 8, !tbaa !27
  %161 = getelementptr inbounds %struct.lfs_emubd_disk, ptr %160, i32 0, i32 1
  %162 = load i32, ptr %161, align 4, !tbaa !28
  %163 = load ptr, ptr %6, align 8, !tbaa !5
  %164 = getelementptr inbounds %struct.lfs_emubd, ptr %163, i32 0, i32 7
  %165 = load ptr, ptr %164, align 8, !tbaa !27
  %166 = getelementptr inbounds %struct.lfs_emubd_disk, ptr %165, i32 0, i32 2
  %167 = load ptr, ptr %166, align 8, !tbaa !31
  %168 = load ptr, ptr %6, align 8, !tbaa !5
  %169 = getelementptr inbounds %struct.lfs_emubd, ptr %168, i32 0, i32 8
  %170 = load ptr, ptr %169, align 8, !tbaa !13
  %171 = getelementptr inbounds %struct.lfs_emubd_config, ptr %170, i32 0, i32 2
  %172 = load i32, ptr %171, align 8, !tbaa !26
  %173 = zext i32 %172 to i64
  %174 = call i64 @write(i32 noundef %162, ptr noundef %167, i64 noundef %173)
  store i64 %174, ptr %11, align 8, !tbaa !30
  %175 = load i64, ptr %11, align 8, !tbaa !30
  %176 = icmp slt i64 %175, 0
  br i1 %176, label %177, label %182

177:                                              ; preds = %157
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  %178 = call ptr @__errno_location() #9
  %179 = load i32, ptr %178, align 4, !tbaa !9
  %180 = sub nsw i32 0, %179
  store i32 %180, ptr %12, align 4, !tbaa !9
  %181 = load i32, ptr %12, align 4, !tbaa !9
  store i32 %181, ptr %3, align 4
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  br label %183

182:                                              ; preds = %157
  store i32 0, ptr %8, align 4
  br label %183

183:                                              ; preds = %182, %177
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  br label %184

184:                                              ; preds = %183, %152
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  %185 = load i32, ptr %8, align 4
  switch i32 %185, label %259 [
    i32 0, label %186
  ]

186:                                              ; preds = %184
  br label %187

187:                                              ; preds = %186, %114
  br label %188

188:                                              ; preds = %187, %107
  %189 = load ptr, ptr %6, align 8, !tbaa !5
  %190 = getelementptr inbounds %struct.lfs_emubd, ptr %189, i32 0, i32 8
  %191 = load ptr, ptr %190, align 8, !tbaa !13
  %192 = getelementptr inbounds %struct.lfs_emubd_config, ptr %191, i32 0, i32 2
  %193 = load i32, ptr %192, align 8, !tbaa !26
  %194 = zext i32 %193 to i64
  %195 = load ptr, ptr %6, align 8, !tbaa !5
  %196 = getelementptr inbounds %struct.lfs_emubd, ptr %195, i32 0, i32 3
  %197 = load i64, ptr %196, align 8, !tbaa !32
  %198 = add i64 %197, %194
  store i64 %198, ptr %196, align 8, !tbaa !32
  %199 = load ptr, ptr %6, align 8, !tbaa !5
  %200 = getelementptr inbounds %struct.lfs_emubd, ptr %199, i32 0, i32 8
  %201 = load ptr, ptr %200, align 8, !tbaa !13
  %202 = getelementptr inbounds %struct.lfs_emubd_config, ptr %201, i32 0, i32 15
  %203 = load i64, ptr %202, align 8, !tbaa !33
  %204 = icmp ne i64 %203, 0
  br i1 %204, label %205, label %232

205:                                              ; preds = %188
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  %206 = getelementptr inbounds %struct.timespec, ptr %14, i32 0, i32 0
  %207 = load ptr, ptr %6, align 8, !tbaa !5
  %208 = getelementptr inbounds %struct.lfs_emubd, ptr %207, i32 0, i32 8
  %209 = load ptr, ptr %208, align 8, !tbaa !13
  %210 = getelementptr inbounds %struct.lfs_emubd_config, ptr %209, i32 0, i32 15
  %211 = load i64, ptr %210, align 8, !tbaa !33
  %212 = udiv i64 %211, 1000000000
  store i64 %212, ptr %206, align 8, !tbaa !34
  %213 = getelementptr inbounds %struct.timespec, ptr %14, i32 0, i32 1
  %214 = load ptr, ptr %6, align 8, !tbaa !5
  %215 = getelementptr inbounds %struct.lfs_emubd, ptr %214, i32 0, i32 8
  %216 = load ptr, ptr %215, align 8, !tbaa !13
  %217 = getelementptr inbounds %struct.lfs_emubd_config, ptr %216, i32 0, i32 15
  %218 = load i64, ptr %217, align 8, !tbaa !33
  %219 = urem i64 %218, 1000000000
  store i64 %219, ptr %213, align 8, !tbaa !36
  %220 = call i32 @nanosleep(ptr noundef %14, ptr noundef null)
  store i32 %220, ptr %13, align 4, !tbaa !9
  %221 = load i32, ptr %13, align 4, !tbaa !9
  %222 = icmp ne i32 %221, 0
  br i1 %222, label %223, label %228

223:                                              ; preds = %205
  %224 = call ptr @__errno_location() #9
  %225 = load i32, ptr %224, align 4, !tbaa !9
  %226 = sub nsw i32 0, %225
  store i32 %226, ptr %13, align 4, !tbaa !9
  %227 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %227, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %229

228:                                              ; preds = %205
  store i32 0, ptr %8, align 4
  br label %229

229:                                              ; preds = %228, %223
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  %230 = load i32, ptr %8, align 4
  switch i32 %230, label %259 [
    i32 0, label %231
  ]

231:                                              ; preds = %229
  br label %232

232:                                              ; preds = %231, %188
  %233 = load ptr, ptr %6, align 8, !tbaa !5
  %234 = getelementptr inbounds %struct.lfs_emubd, ptr %233, i32 0, i32 4
  %235 = load i32, ptr %234, align 8, !tbaa !37
  %236 = icmp ugt i32 %235, 0
  br i1 %236, label %237, label %258

237:                                              ; preds = %232
  %238 = load ptr, ptr %6, align 8, !tbaa !5
  %239 = getelementptr inbounds %struct.lfs_emubd, ptr %238, i32 0, i32 4
  %240 = load i32, ptr %239, align 8, !tbaa !37
  %241 = sub i32 %240, 1
  store i32 %241, ptr %239, align 8, !tbaa !37
  %242 = load ptr, ptr %6, align 8, !tbaa !5
  %243 = getelementptr inbounds %struct.lfs_emubd, ptr %242, i32 0, i32 4
  %244 = load i32, ptr %243, align 8, !tbaa !37
  %245 = icmp eq i32 %244, 0
  br i1 %245, label %246, label %257

246:                                              ; preds = %237
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #7
  %247 = load ptr, ptr %4, align 8, !tbaa !5
  %248 = call i32 @lfs_emubd_powerloss(ptr noundef %247)
  store i32 %248, ptr %15, align 4, !tbaa !9
  %249 = load i32, ptr %15, align 4, !tbaa !9
  %250 = icmp ne i32 %249, 0
  br i1 %250, label %251, label %253

251:                                              ; preds = %246
  %252 = load i32, ptr %15, align 4, !tbaa !9
  store i32 %252, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %254

253:                                              ; preds = %246
  store i32 0, ptr %8, align 4
  br label %254

254:                                              ; preds = %253, %251
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #7
  %255 = load i32, ptr %8, align 4
  switch i32 %255, label %259 [
    i32 0, label %256
  ]

256:                                              ; preds = %254
  br label %257

257:                                              ; preds = %256, %237
  br label %258

258:                                              ; preds = %257, %232
  store i32 0, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %259

259:                                              ; preds = %258, %254, %229, %184, %98, %90, %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  %260 = load i32, ptr %3, align 4
  ret i32 %260
}

; Function Attrs: nounwind uwtable
declare hidden ptr @lfs_emubd_incblock(ptr noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nounwind willreturn memory(none) "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 = { "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 #4 = { noreturn nounwind "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 #5 = { 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 #6 = { nounwind "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 #7 = { nounwind }
attributes #8 = { noreturn nounwind }
attributes #9 = { nounwind willreturn memory(none) }

!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, !6, i64 0}
!12 = !{!"lfs_config", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !6, i64 72, !6, i64 80, !6, i64 88, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !10, i64 112}
!13 = !{!14, !6, i64 56}
!14 = !{!"lfs_emubd", !6, i64 0, !15, i64 8, !15, i64 16, !15, i64 24, !10, i64 32, !10, i64 36, !6, i64 40, !6, i64 48, !6, i64 56}
!15 = !{!"long", !7, i64 0}
!16 = !{!17, !10, i64 12}
!17 = !{!"lfs_emubd_config", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !6, i64 40, !6, i64 48, !18, i64 56, !6, i64 64, !15, i64 72, !15, i64 80, !15, i64 88}
!18 = !{!"_Bool", !7, i64 0}
!19 = !{!17, !10, i64 32}
!20 = !{!14, !10, i64 36}
!21 = !{!14, !6, i64 0}
!22 = !{!14, !6, i64 40}
!23 = !{!17, !10, i64 20}
!24 = !{!17, !10, i64 24}
!25 = !{!17, !10, i64 16}
!26 = !{!17, !10, i64 8}
!27 = !{!14, !6, i64 48}
!28 = !{!29, !10, i64 4}
!29 = !{!"lfs_emubd_disk", !10, i64 0, !10, i64 4, !6, i64 8}
!30 = !{!15, !15, i64 0}
!31 = !{!29, !6, i64 8}
!32 = !{!14, !15, i64 24}
!33 = !{!17, !15, i64 88}
!34 = !{!35, !15, i64 0}
!35 = !{!"timespec", !15, i64 0, !15, i64 8}
!36 = !{!35, !15, i64 8}
!37 = !{!14, !10, i64 32}


; 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.timespec = type { i64, i64 }

@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [74 x i8], align 1
@__PRETTY_FUNCTION__.lfs_emubd_erase = external hidden unnamed_addr constant [60 x i8], align 1

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #1

; Function Attrs: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

declare i32 @nanosleep(ptr noundef, ptr noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden ptr @lfs_emubd_mutblock(ptr noundef, ptr noundef) local_unnamed_addr #5

; Function Attrs: nounwind
declare i64 @lseek(i32 noundef, i64 noundef, i32 noundef) local_unnamed_addr #6

; Function Attrs: nounwind uwtable
declare hidden i32 @lfs_emubd_powerloss(ptr noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
define dso_local i32 @lfs_emubd_erase(ptr noundef %0, i32 noundef %1) local_unnamed_addr #5 {
  %3 = alloca %struct.timespec, align 8
  %4 = load ptr, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 56
  %6 = load ptr, ptr %5, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %6, i64 12
  %8 = load i32, ptr %7, align 4, !tbaa !14
  %9 = icmp ugt i32 %8, %1
  br i1 %9, label %11, label %10

10:                                               ; preds = %2
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 437, ptr noundef nonnull @__PRETTY_FUNCTION__.lfs_emubd_erase) #7
  unreachable

11:                                               ; preds = %2
  %12 = getelementptr inbounds i8, ptr %6, i64 32
  %13 = load i32, ptr %12, align 8, !tbaa !17
  %14 = icmp eq i32 %13, 1
  br i1 %14, label %15, label %26

15:                                               ; preds = %11
  %16 = getelementptr inbounds i8, ptr %4, i64 36
  %17 = load i32, ptr %16, align 4, !tbaa !18
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %19, label %26

19:                                               ; preds = %15
  store i32 %1, ptr %16, align 4, !tbaa !18
  %20 = load ptr, ptr %4, align 8, !tbaa !19
  %21 = zext i32 %1 to i64
  %22 = getelementptr inbounds ptr, ptr %20, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !20
  %24 = tail call ptr @lfs_emubd_incblock(ptr noundef %23)
  %25 = getelementptr inbounds i8, ptr %4, i64 40
  store ptr %24, ptr %25, align 8, !tbaa !21
  br label %26

26:                                               ; preds = %19, %15, %11
  %27 = load ptr, ptr %4, align 8, !tbaa !19
  %28 = zext i32 %1 to i64
  %29 = getelementptr inbounds ptr, ptr %27, i64 %28
  %30 = tail call ptr @lfs_emubd_mutblock(ptr noundef nonnull %0, ptr noundef %29)
  %.not = icmp eq ptr %30, null
  br i1 %.not, label %.thread, label %31

31:                                               ; preds = %26
  %32 = load ptr, ptr %5, align 8, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %32, i64 20
  %34 = load i32, ptr %33, align 4, !tbaa !22
  %.not67 = icmp eq i32 %34, 0
  br i1 %.not67, label %44, label %35

35:                                               ; preds = %31
  %36 = getelementptr inbounds i8, ptr %30, i64 4
  %37 = load i32, ptr %36, align 4, !tbaa !23
  %.not68 = icmp ult i32 %37, %34
  br i1 %.not68, label %42, label %38

38:                                               ; preds = %35
  %39 = getelementptr inbounds i8, ptr %32, i64 24
  %40 = load i32, ptr %39, align 8, !tbaa !24
  switch i32 %40, label %44 [
    i32 1, label %.thread
    i32 4, label %41
  ]

41:                                               ; preds = %38
  br label %.thread

42:                                               ; preds = %35
  %43 = add nuw i32 %37, 1
  store i32 %43, ptr %36, align 4, !tbaa !23
  br label %44

44:                                               ; preds = %38, %42, %31
  %45 = getelementptr inbounds i8, ptr %32, i64 16
  %46 = load i32, ptr %45, align 8, !tbaa !25
  %.not69 = icmp eq i32 %46, -1
  br i1 %.not69, label %84, label %47

47:                                               ; preds = %44
  %48 = getelementptr inbounds i8, ptr %30, i64 8
  %49 = trunc i32 %46 to i8
  %50 = getelementptr inbounds i8, ptr %32, i64 8
  %51 = load i32, ptr %50, align 8, !tbaa !26
  %52 = zext i32 %51 to i64
  tail call void @llvm.memset.p0.i64(ptr nonnull align 4 %48, i8 %49, i64 %52, i1 false)
  %53 = getelementptr inbounds i8, ptr %4, i64 48
  %54 = load ptr, ptr %53, align 8, !tbaa !27
  %.not70 = icmp eq ptr %54, null
  %.pre79 = load ptr, ptr %5, align 8, !tbaa !11
  br i1 %.not70, label %84, label %55

55:                                               ; preds = %47
  %56 = getelementptr inbounds i8, ptr %54, i64 4
  %57 = load i32, ptr %56, align 4, !tbaa !28
  %58 = getelementptr inbounds i8, ptr %.pre79, i64 8
  %59 = load i32, ptr %58, align 8, !tbaa !26
  %60 = zext i32 %59 to i64
  %61 = mul nuw nsw i64 %60, %28
  %62 = tail call i64 @lseek(i32 noundef %57, i64 noundef %61, i32 noundef 0) #8
  %63 = icmp slt i64 %62, 0
  br i1 %63, label %64, label %68

64:                                               ; preds = %55
  %65 = tail call ptr @__errno_location() #9
  %66 = load i32, ptr %65, align 4, !tbaa !23
  %67 = sub nsw i32 0, %66
  br label %.thread

68:                                               ; preds = %55
  %69 = load ptr, ptr %53, align 8, !tbaa !27
  %70 = getelementptr inbounds i8, ptr %69, i64 4
  %71 = load i32, ptr %70, align 4, !tbaa !28
  %72 = getelementptr inbounds i8, ptr %69, i64 8
  %73 = load ptr, ptr %72, align 8, !tbaa !30
  %74 = load ptr, ptr %5, align 8, !tbaa !11
  %75 = getelementptr inbounds i8, ptr %74, i64 8
  %76 = load i32, ptr %75, align 8, !tbaa !26
  %77 = zext i32 %76 to i64
  %78 = tail call i64 @write(i32 noundef %71, ptr noundef %73, i64 noundef %77) #8
  %79 = icmp sgt i64 %78, -1
  br i1 %79, label %._crit_edge, label %80

._crit_edge:                                      ; preds = %68
  %.pre = load ptr, ptr %5, align 8, !tbaa !11
  br label %84

80:                                               ; preds = %68
  %81 = tail call ptr @__errno_location() #9
  %82 = load i32, ptr %81, align 4, !tbaa !23
  %83 = sub nsw i32 0, %82
  br label %.thread

84:                                               ; preds = %._crit_edge, %47, %44
  %85 = phi ptr [ %.pre, %._crit_edge ], [ %.pre79, %47 ], [ %32, %44 ]
  %86 = getelementptr inbounds i8, ptr %85, i64 8
  %87 = load i32, ptr %86, align 8, !tbaa !26
  %88 = zext i32 %87 to i64
  %89 = getelementptr inbounds i8, ptr %4, i64 24
  %90 = load i64, ptr %89, align 8, !tbaa !31
  %91 = add i64 %90, %88
  store i64 %91, ptr %89, align 8, !tbaa !31
  %92 = getelementptr inbounds i8, ptr %85, i64 88
  %93 = load i64, ptr %92, align 8, !tbaa !32
  %.not71 = icmp eq i64 %93, 0
  br i1 %.not71, label %.thread77, label %94

94:                                               ; preds = %84
  %95 = udiv i64 %93, 1000000000
  store i64 %95, ptr %3, align 8, !tbaa !33
  %96 = getelementptr inbounds i8, ptr %3, i64 8
  %97 = urem i64 %93, 1000000000
  store i64 %97, ptr %96, align 8, !tbaa !35
  %98 = call i32 @nanosleep(ptr noundef nonnull %3, ptr noundef null) #8
  %.not72 = icmp eq i32 %98, 0
  br i1 %.not72, label %.thread77, label %99

99:                                               ; preds = %94
  %100 = tail call ptr @__errno_location() #9
  %101 = load i32, ptr %100, align 4, !tbaa !23
  %102 = sub nsw i32 0, %101
  br label %.thread

.thread77:                                        ; preds = %94, %84
  %103 = getelementptr inbounds i8, ptr %4, i64 32
  %104 = load i32, ptr %103, align 8, !tbaa !36
  %.not73 = icmp eq i32 %104, 0
  br i1 %.not73, label %110, label %105

105:                                              ; preds = %.thread77
  %106 = add i32 %104, -1
  store i32 %106, ptr %103, align 8, !tbaa !36
  %107 = icmp eq i32 %106, 0
  br i1 %107, label %108, label %110

108:                                              ; preds = %105
  %109 = call i32 @lfs_emubd_powerloss(ptr noundef nonnull %0)
  %.not74 = icmp eq i32 %109, 0
  br i1 %.not74, label %110, label %.thread

110:                                              ; preds = %105, %108, %.thread77
  br label %.thread

.thread:                                          ; preds = %80, %64, %99, %38, %26, %108, %110, %41
  %.6 = phi i32 [ 0, %41 ], [ 0, %110 ], [ %109, %108 ], [ %102, %99 ], [ -12, %26 ], [ -84, %38 ], [ %83, %80 ], [ %67, %64 ]
  ret i32 %.6
}

; Function Attrs: nounwind uwtable
declare hidden ptr @lfs_emubd_incblock(ptr noundef) local_unnamed_addr #5

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { nofree "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 = { noreturn nounwind "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 #4 = { "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 #5 = { 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 #6 = { nounwind "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 #7 = { noreturn nounwind }
attributes #8 = { nounwind }
attributes #9 = { nounwind willreturn memory(none) }

!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, !7, i64 0}
!6 = !{!"lfs_config", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !10, i64 40, !10, i64 44, !10, i64 48, !10, i64 52, !10, i64 56, !10, i64 60, !10, i64 64, !10, i64 68, !7, i64 72, !7, i64 80, !7, i64 88, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !10, i64 112}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 56}
!12 = !{!"lfs_emubd", !7, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !10, i64 32, !10, i64 36, !7, i64 40, !7, i64 48, !7, i64 56}
!13 = !{!"long", !8, i64 0}
!14 = !{!15, !10, i64 12}
!15 = !{!"lfs_emubd_config", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !10, i64 32, !7, i64 40, !7, i64 48, !16, i64 56, !7, i64 64, !13, i64 72, !13, i64 80, !13, i64 88}
!16 = !{!"_Bool", !8, i64 0}
!17 = !{!15, !10, i64 32}
!18 = !{!12, !10, i64 36}
!19 = !{!12, !7, i64 0}
!20 = !{!7, !7, i64 0}
!21 = !{!12, !7, i64 40}
!22 = !{!15, !10, i64 20}
!23 = !{!10, !10, i64 0}
!24 = !{!15, !10, i64 24}
!25 = !{!15, !10, i64 16}
!26 = !{!15, !10, i64 8}
!27 = !{!12, !7, i64 48}
!28 = !{!29, !10, i64 4}
!29 = !{!"lfs_emubd_disk", !10, i64 0, !10, i64 4, !7, i64 8}
!30 = !{!29, !7, i64 8}
!31 = !{!12, !13, i64 24}
!32 = !{!15, !13, i64 88}
!33 = !{!34, !13, i64 0}
!34 = !{!"timespec", !13, i64 0, !13, i64 8}
!35 = !{!34, !13, i64 8}
!36 = !{!12, !10, i64 32}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass