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

; 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.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_filebd = type { i32, ptr }
%struct.lfs_filebd_config = type { i32, i32, i32, i32 }

@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [32 x i8], align 1
@__PRETTY_FUNCTION__.lfs_filebd_prog = external hidden unnamed_addr constant [97 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [31 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: nounwind willreturn memory(none)
declare ptr @__errno_location() #1

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

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

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

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

28:                                               ; preds = %5
  br label %30

29:                                               ; preds = %5
  call void @__assert_fail(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 109, ptr noundef @__PRETTY_FUNCTION__.lfs_filebd_prog) #7
  unreachable

30:                                               ; preds = %28
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = load ptr, ptr %12, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.lfs_filebd, ptr %32, i32 0, i32 1
  %34 = load ptr, ptr %33, align 8, !tbaa !13
  %35 = getelementptr inbounds %struct.lfs_filebd_config, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 4, !tbaa !17
  %37 = urem i32 %31, %36
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %39, label %40

39:                                               ; preds = %30
  br label %41

40:                                               ; preds = %30
  call void @__assert_fail(ptr noundef @.str.5, ptr noundef @.str.1, i32 noundef 110, ptr noundef @__PRETTY_FUNCTION__.lfs_filebd_prog) #7
  unreachable

41:                                               ; preds = %39
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.lfs_filebd, ptr %43, i32 0, i32 1
  %45 = load ptr, ptr %44, align 8, !tbaa !13
  %46 = getelementptr inbounds %struct.lfs_filebd_config, ptr %45, i32 0, i32 1
  %47 = load i32, ptr %46, align 4, !tbaa !17
  %48 = urem i32 %42, %47
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %41
  br label %52

51:                                               ; preds = %41
  call void @__assert_fail(ptr noundef @.str.6, ptr noundef @.str.1, i32 noundef 111, ptr noundef @__PRETTY_FUNCTION__.lfs_filebd_prog) #7
  unreachable

52:                                               ; preds = %50
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = add i32 %53, %54
  %56 = load ptr, ptr %12, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.lfs_filebd, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !13
  %59 = getelementptr inbounds %struct.lfs_filebd_config, ptr %58, i32 0, i32 2
  %60 = load i32, ptr %59, align 4, !tbaa !18
  %61 = icmp ule i32 %55, %60
  br i1 %61, label %62, label %63

62:                                               ; preds = %52
  br label %64

63:                                               ; preds = %52
  call void @__assert_fail(ptr noundef @.str.4, ptr noundef @.str.1, i32 noundef 112, ptr noundef @__PRETTY_FUNCTION__.lfs_filebd_prog) #7
  unreachable

64:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %65 = load ptr, ptr %12, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.lfs_filebd, ptr %65, i32 0, i32 0
  %67 = load i32, ptr %66, align 8, !tbaa !19
  %68 = load i32, ptr %8, align 4, !tbaa !9
  %69 = zext i32 %68 to i64
  %70 = load ptr, ptr %12, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.lfs_filebd, ptr %70, i32 0, i32 1
  %72 = load ptr, ptr %71, align 8, !tbaa !13
  %73 = getelementptr inbounds %struct.lfs_filebd_config, ptr %72, i32 0, i32 2
  %74 = load i32, ptr %73, align 4, !tbaa !18
  %75 = zext i32 %74 to i64
  %76 = mul nsw i64 %69, %75
  %77 = load i32, ptr %9, align 4, !tbaa !9
  %78 = zext i32 %77 to i64
  %79 = add nsw i64 %76, %78
  %80 = call i64 @lseek(i32 noundef %67, i64 noundef %79, i32 noundef 0) #6
  store i64 %80, ptr %13, align 8, !tbaa !20
  %81 = load i64, ptr %13, align 8, !tbaa !20
  %82 = icmp slt i64 %81, 0
  br i1 %82, label %83, label %88

83:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  %84 = call ptr @__errno_location() #8
  %85 = load i32, ptr %84, align 4, !tbaa !9
  %86 = sub nsw i32 0, %85
  store i32 %86, ptr %14, align 4, !tbaa !9
  %87 = load i32, ptr %14, align 4, !tbaa !9
  store i32 %87, ptr %6, align 4
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  br label %105

88:                                               ; preds = %64
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  %89 = load ptr, ptr %12, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.lfs_filebd, ptr %89, i32 0, i32 0
  %91 = load i32, ptr %90, align 8, !tbaa !19
  %92 = load ptr, ptr %10, align 8, !tbaa !5
  %93 = load i32, ptr %11, align 4, !tbaa !9
  %94 = zext i32 %93 to i64
  %95 = call i64 @write(i32 noundef %91, ptr noundef %92, i64 noundef %94)
  store i64 %95, ptr %16, align 8, !tbaa !20
  %96 = load i64, ptr %16, align 8, !tbaa !20
  %97 = icmp slt i64 %96, 0
  br i1 %97, label %98, label %103

98:                                               ; preds = %88
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #6
  %99 = call ptr @__errno_location() #8
  %100 = load i32, ptr %99, align 4, !tbaa !9
  %101 = sub nsw i32 0, %100
  store i32 %101, ptr %17, align 4, !tbaa !9
  %102 = load i32, ptr %17, align 4, !tbaa !9
  store i32 %102, ptr %6, align 4
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #6
  br label %104

103:                                              ; preds = %88
  store i32 0, ptr %6, align 4
  store i32 1, ptr %15, align 4
  br label %104

104:                                              ; preds = %103, %98
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  br label %105

105:                                              ; preds = %104, %83
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  %106 = load i32, ptr %6, align 4
  ret i32 %106
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 #3 = { 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 = { 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 #5 = { "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 }
attributes #7 = { noreturn nounwind }
attributes #8 = { 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 8}
!14 = !{!"lfs_filebd", !10, i64 0, !6, i64 8}
!15 = !{!16, !10, i64 12}
!16 = !{!"lfs_filebd_config", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!17 = !{!16, !10, i64 4}
!18 = !{!16, !10, i64 8}
!19 = !{!14, !10, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"long", !7, i64 0}


; 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"

@.str = external hidden unnamed_addr constant [29 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [75 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [32 x i8], align 1
@__PRETTY_FUNCTION__.lfs_filebd_prog = external hidden unnamed_addr constant [97 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [31 x i8], align 1

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2147483647, -2147483648) i32 @lfs_filebd_prog(ptr nocapture noundef readonly %0, i32 noundef %1, i32 noundef %2, ptr nocapture noundef readonly %3, i32 noundef %4) local_unnamed_addr #3 {
  %6 = load ptr, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %6, i64 8
  %8 = load ptr, ptr %7, align 8, !tbaa !11
  %9 = getelementptr inbounds i8, ptr %8, i64 12
  %10 = load i32, ptr %9, align 4, !tbaa !13
  %11 = icmp ugt i32 %10, %1
  br i1 %11, label %13, label %12

12:                                               ; preds = %5
  tail call void @__assert_fail(ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i32 noundef 109, ptr noundef nonnull @__PRETTY_FUNCTION__.lfs_filebd_prog) #5
  unreachable

13:                                               ; preds = %5
  %14 = getelementptr inbounds i8, ptr %8, i64 4
  %15 = load i32, ptr %14, align 4, !tbaa !15
  %16 = urem i32 %2, %15
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %19, label %18

18:                                               ; preds = %13
  tail call void @__assert_fail(ptr noundef nonnull @.str.5, ptr noundef nonnull @.str.1, i32 noundef 110, ptr noundef nonnull @__PRETTY_FUNCTION__.lfs_filebd_prog) #5
  unreachable

19:                                               ; preds = %13
  %20 = urem i32 %4, %15
  %21 = icmp eq i32 %20, 0
  br i1 %21, label %23, label %22

22:                                               ; preds = %19
  tail call void @__assert_fail(ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.1, i32 noundef 111, ptr noundef nonnull @__PRETTY_FUNCTION__.lfs_filebd_prog) #5
  unreachable

23:                                               ; preds = %19
  %24 = add i32 %4, %2
  %25 = getelementptr inbounds i8, ptr %8, i64 8
  %26 = load i32, ptr %25, align 4, !tbaa !16
  %.not = icmp ugt i32 %24, %26
  br i1 %.not, label %27, label %28

27:                                               ; preds = %23
  tail call void @__assert_fail(ptr noundef nonnull @.str.4, ptr noundef nonnull @.str.1, i32 noundef 112, ptr noundef nonnull @__PRETTY_FUNCTION__.lfs_filebd_prog) #5
  unreachable

28:                                               ; preds = %23
  %29 = load i32, ptr %6, align 8, !tbaa !17
  %30 = zext i32 %1 to i64
  %31 = zext i32 %26 to i64
  %32 = mul nuw nsw i64 %31, %30
  %33 = zext i32 %2 to i64
  %34 = add nuw nsw i64 %32, %33
  %35 = tail call i64 @lseek(i32 noundef %29, i64 noundef %34, i32 noundef 0) #6
  %36 = icmp slt i64 %35, 0
  br i1 %36, label %.sink.split, label %37

37:                                               ; preds = %28
  %38 = load i32, ptr %6, align 8, !tbaa !17
  %39 = zext i32 %4 to i64
  %40 = tail call i64 @write(i32 noundef %38, ptr noundef %3, i64 noundef %39) #6
  %41 = icmp slt i64 %40, 0
  br i1 %41, label %.sink.split, label %45

.sink.split:                                      ; preds = %37, %28
  %42 = tail call ptr @__errno_location() #7
  %43 = load i32, ptr %42, align 4, !tbaa !18
  %44 = sub nsw i32 0, %43
  br label %45

45:                                               ; preds = %.sink.split, %37
  %.1 = phi i32 [ 0, %37 ], [ %44, %.sink.split ]
  ret i32 %.1
}

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

attributes #0 = { 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 #1 = { 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 #2 = { 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 #3 = { 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 #4 = { 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 #5 = { noreturn nounwind }
attributes #6 = { nounwind }
attributes #7 = { 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 8}
!12 = !{!"lfs_filebd", !10, i64 0, !7, i64 8}
!13 = !{!14, !10, i64 12}
!14 = !{!"lfs_filebd_config", !10, i64 0, !10, i64 4, !10, i64 8, !10, i64 12}
!15 = !{!14, !10, i64 4}
!16 = !{!14, !10, i64 8}
!17 = !{!12, !10, i64 0}
!18 = !{!10, !10, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass