; 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.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_disk = type { i32, i32, ptr }

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

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

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

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

26:                                               ; preds = %2
  store i32 -12, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %108

27:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  store i64 0, ptr %8, align 8, !tbaa !19
  br label %28

28:                                               ; preds = %51, %27
  %29 = load i64, ptr %8, align 8, !tbaa !19
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.lfs_emubd, ptr %30, i32 0, i32 8
  %32 = load ptr, ptr %31, align 8, !tbaa !12
  %33 = getelementptr inbounds %struct.lfs_emubd_config, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 4, !tbaa !15
  %35 = zext i32 %34 to i64
  %36 = icmp ult i64 %29, %35
  br i1 %36, label %38, label %37

37:                                               ; preds = %28
  store i32 2, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  br label %54

38:                                               ; preds = %28
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.lfs_emubd, ptr %39, i32 0, i32 0
  %41 = load ptr, ptr %40, align 8, !tbaa !18
  %42 = load i64, ptr %8, align 8, !tbaa !19
  %43 = getelementptr inbounds ptr, ptr %41, i64 %42
  %44 = load ptr, ptr %43, align 8, !tbaa !5
  %45 = call ptr @lfs_emubd_incblock(ptr noundef %44)
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.lfs_emubd, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %47, align 8, !tbaa !18
  %49 = load i64, ptr %8, align 8, !tbaa !19
  %50 = getelementptr inbounds ptr, ptr %48, i64 %49
  store ptr %45, ptr %50, align 8, !tbaa !5
  br label %51

51:                                               ; preds = %38
  %52 = load i64, ptr %8, align 8, !tbaa !19
  %53 = add i64 %52, 1
  store i64 %53, ptr %8, align 8, !tbaa !19
  br label %28, !llvm.loop !20

54:                                               ; preds = %37
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.lfs_emubd, ptr %55, i32 0, i32 1
  %57 = load i64, ptr %56, align 8, !tbaa !22
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.lfs_emubd, ptr %58, i32 0, i32 1
  store i64 %57, ptr %59, align 8, !tbaa !22
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.lfs_emubd, ptr %60, i32 0, i32 2
  %62 = load i64, ptr %61, align 8, !tbaa !23
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.lfs_emubd, ptr %63, i32 0, i32 2
  store i64 %62, ptr %64, align 8, !tbaa !23
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.lfs_emubd, ptr %65, i32 0, i32 3
  %67 = load i64, ptr %66, align 8, !tbaa !24
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.lfs_emubd, ptr %68, i32 0, i32 3
  store i64 %67, ptr %69, align 8, !tbaa !24
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.lfs_emubd, ptr %70, i32 0, i32 4
  %72 = load i32, ptr %71, align 8, !tbaa !25
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.lfs_emubd, ptr %73, i32 0, i32 4
  store i32 %72, ptr %74, align 8, !tbaa !25
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.lfs_emubd, ptr %75, i32 0, i32 5
  %77 = load i32, ptr %76, align 4, !tbaa !26
  %78 = load ptr, ptr %5, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.lfs_emubd, ptr %78, i32 0, i32 5
  store i32 %77, ptr %79, align 4, !tbaa !26
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.lfs_emubd, ptr %80, i32 0, i32 6
  %82 = load ptr, ptr %81, align 8, !tbaa !27
  %83 = call ptr @lfs_emubd_incblock(ptr noundef %82)
  %84 = load ptr, ptr %5, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.lfs_emubd, ptr %84, i32 0, i32 6
  store ptr %83, ptr %85, align 8, !tbaa !27
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.lfs_emubd, ptr %86, i32 0, i32 7
  %88 = load ptr, ptr %87, align 8, !tbaa !28
  %89 = load ptr, ptr %5, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.lfs_emubd, ptr %89, i32 0, i32 7
  store ptr %88, ptr %90, align 8, !tbaa !28
  %91 = load ptr, ptr %5, align 8, !tbaa !5
  %92 = getelementptr inbounds %struct.lfs_emubd, ptr %91, i32 0, i32 7
  %93 = load ptr, ptr %92, align 8, !tbaa !28
  %94 = icmp ne ptr %93, null
  br i1 %94, label %95, label %102

95:                                               ; preds = %54
  %96 = load ptr, ptr %5, align 8, !tbaa !5
  %97 = getelementptr inbounds %struct.lfs_emubd, ptr %96, i32 0, i32 7
  %98 = load ptr, ptr %97, align 8, !tbaa !28
  %99 = getelementptr inbounds %struct.lfs_emubd_disk, ptr %98, i32 0, i32 0
  %100 = load i32, ptr %99, align 8, !tbaa !29
  %101 = add i32 %100, 1
  store i32 %101, ptr %99, align 8, !tbaa !29
  br label %102

102:                                              ; preds = %95, %54
  %103 = load ptr, ptr %6, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.lfs_emubd, ptr %103, i32 0, i32 8
  %105 = load ptr, ptr %104, align 8, !tbaa !12
  %106 = load ptr, ptr %5, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.lfs_emubd, ptr %106, i32 0, i32 8
  store ptr %105, ptr %107, align 8, !tbaa !12
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %108

108:                                              ; preds = %102, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %109 = load i32, ptr %3, align 4
  ret i32 %109
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind allocsize(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 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nounwind }
attributes #4 = { nounwind allocsize(0) }

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


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

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -12, 1) i32 @lfs_emubd_copy(ptr nocapture noundef readonly %0, ptr nocapture noundef %1) local_unnamed_addr #1 {
  %3 = load ptr, ptr %0, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 56
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %5, i64 12
  %7 = load i32, ptr %6, align 4, !tbaa !14
  %8 = zext i32 %7 to i64
  %9 = shl nuw nsw i64 %8, 3
  %10 = tail call noalias ptr @malloc(i64 noundef %9) #2
  store ptr %10, ptr %1, align 8, !tbaa !17
  %.not = icmp eq ptr %10, null
  br i1 %.not, label %45, label %.preheader

.preheader:                                       ; preds = %2
  %.not33 = icmp eq i32 %7, 0
  br i1 %.not33, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %11 = getelementptr inbounds i8, ptr %3, i64 8
  %12 = getelementptr inbounds i8, ptr %1, i64 8
  %13 = load <2 x i64>, ptr %11, align 8, !tbaa !18
  store <2 x i64> %13, ptr %12, align 8, !tbaa !18
  %14 = getelementptr inbounds i8, ptr %3, i64 24
  %15 = load i64, ptr %14, align 8, !tbaa !19
  %16 = getelementptr inbounds i8, ptr %1, i64 24
  store i64 %15, ptr %16, align 8, !tbaa !19
  %17 = getelementptr inbounds i8, ptr %3, i64 32
  %18 = getelementptr inbounds i8, ptr %1, i64 32
  %19 = load <2 x i32>, ptr %17, align 8, !tbaa !20
  store <2 x i32> %19, ptr %18, align 8, !tbaa !20
  %20 = getelementptr inbounds i8, ptr %3, i64 40
  %21 = load ptr, ptr %20, align 8, !tbaa !21
  %22 = tail call ptr @lfs_emubd_incblock(ptr noundef %21)
  %23 = getelementptr inbounds i8, ptr %1, i64 40
  store ptr %22, ptr %23, align 8, !tbaa !21
  %24 = getelementptr inbounds i8, ptr %3, i64 48
  %25 = load ptr, ptr %24, align 8, !tbaa !22
  %26 = getelementptr inbounds i8, ptr %1, i64 48
  store ptr %25, ptr %26, align 8, !tbaa !22
  %.not31 = icmp eq ptr %25, null
  br i1 %.not31, label %42, label %39

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %.032 = phi i64 [ %33, %.lr.ph ], [ 0, %.preheader ]
  %27 = load ptr, ptr %3, align 8, !tbaa !17
  %28 = getelementptr inbounds ptr, ptr %27, i64 %.032
  %29 = load ptr, ptr %28, align 8, !tbaa !23
  %30 = tail call ptr @lfs_emubd_incblock(ptr noundef %29)
  %31 = load ptr, ptr %1, align 8, !tbaa !17
  %32 = getelementptr inbounds ptr, ptr %31, i64 %.032
  store ptr %30, ptr %32, align 8, !tbaa !23
  %33 = add nuw nsw i64 %.032, 1
  %34 = load ptr, ptr %4, align 8, !tbaa !11
  %35 = getelementptr inbounds i8, ptr %34, i64 12
  %36 = load i32, ptr %35, align 4, !tbaa !14
  %37 = zext i32 %36 to i64
  %38 = icmp ult i64 %33, %37
  br i1 %38, label %.lr.ph, label %._crit_edge, !llvm.loop !24

39:                                               ; preds = %._crit_edge
  %40 = load i32, ptr %25, align 8, !tbaa !26
  %41 = add i32 %40, 1
  store i32 %41, ptr %25, align 8, !tbaa !26
  br label %42

42:                                               ; preds = %39, %._crit_edge
  %43 = load ptr, ptr %4, align 8, !tbaa !11
  %44 = getelementptr inbounds i8, ptr %1, i64 56
  store ptr %43, ptr %44, align 8, !tbaa !11
  br label %45

45:                                               ; preds = %2, %42
  %.029 = phi i32 [ 0, %42 ], [ -12, %2 ]
  ret i32 %.029
}

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 = { nounwind allocsize(0) }

!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 = !{!12, !7, i64 0}
!18 = !{!13, !13, i64 0}
!19 = !{!12, !13, i64 24}
!20 = !{!10, !10, i64 0}
!21 = !{!12, !7, i64 40}
!22 = !{!12, !7, i64 48}
!23 = !{!7, !7, i64 0}
!24 = distinct !{!24, !25}
!25 = !{!"llvm.loop.mustprogress"}
!26 = !{!27, !10, i64 0}
!27 = !{!"lfs_emubd_disk", !10, i64 0, !10, i64 4, !7, i64 8}


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