; LLVM IR from IOsonata/IOsonata :: src/storage/stdfs_littlefs.ll (Z9StdFSInitP6DiskIO)

; 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.__FS_Device = type { ptr, %struct.lfs, [4 x %struct.__FS_FIle_Open], i32 }
%struct.lfs = type { %struct.lfs_cache, %struct.lfs_cache, [2 x i32], ptr, i32, %struct.lfs_gstate, %struct.lfs_gstate, %struct.lfs_gstate, %"struct.lfs::lfs_free", ptr, i32, i32, i32 }
%struct.lfs_cache = type { i32, i32, i32, ptr }
%struct.lfs_gstate = type { i32, [2 x i32] }
%"struct.lfs::lfs_free" = type { i32, i32, i32, i32, ptr }
%struct.__FS_FIle_Open = type { i8, %struct.lfs_file }
%struct.lfs_file = type { ptr, i16, i8, %struct.lfs_mdir, %"struct.lfs_file::lfs_ctz", i32, i32, i32, i32, %struct.lfs_cache, ptr }
%struct.lfs_mdir = type { [2 x i32], i32, i32, i32, i16, i8, i8, [2 x i32] }
%"struct.lfs_file::lfs_ctz" = type { i32, i32 }
%struct.lfs_config = type { ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, i32, i32, i32, i32 }
%struct.StdDev_t = type { [8 x i8], ptr, ptr, ptr, ptr, ptr, ptr }

@_ZL10s_FSDevice = external hidden global %struct.__FS_Device, align 8
@_ZL13s_LittelFSCfg = external hidden global %struct.lfs_config, align 8
@_ZL16s_LittleFsStdDev = external hidden global %struct.StdDev_t, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z9StdFSInitP6DiskIO(ptr noundef %0) #0 {
  %2 = alloca i1, align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %9

8:                                                ; preds = %1
  store i1 false, ptr %2, align 1
  br label %29

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %10, ptr @_ZL10s_FSDevice, align 8, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  %13 = getelementptr inbounds ptr, ptr %12, i64 2
  %14 = load ptr, ptr %13, align 8
  %15 = call noundef zeroext i16 %14(ptr noundef nonnull align 8 dereferenceable(32) %11)
  %16 = zext i16 %15 to i32
  store i32 %16, ptr getelementptr inbounds (%struct.lfs_config, ptr @_ZL13s_LittelFSCfg, i32 0, i32 7), align 8, !tbaa !18
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = load ptr, ptr %17, align 8, !tbaa !16
  %19 = getelementptr inbounds ptr, ptr %18, i64 3
  %20 = load ptr, ptr %19, align 8
  %21 = call noundef i32 %20(ptr noundef nonnull align 8 dereferenceable(32) %17)
  store i32 %21, ptr getelementptr inbounds (%struct.lfs_config, ptr @_ZL13s_LittelFSCfg, i32 0, i32 8), align 4, !tbaa !20
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %22 = call i32 @lfs_mount(ptr noundef getelementptr inbounds (%struct.__FS_Device, ptr @_ZL10s_FSDevice, i32 0, i32 1), ptr noundef @_ZL13s_LittelFSCfg)
  store i32 %22, ptr %4, align 4, !tbaa !21
  %23 = load i32, ptr %4, align 4, !tbaa !21
  %24 = icmp eq i32 %23, 0
  br i1 %24, label %25, label %27

25:                                               ; preds = %9
  call void @llvm.memset.p0.i64(ptr align 8 getelementptr inbounds (%struct.__FS_Device, ptr @_ZL10s_FSDevice, i32 0, i32 2), i8 0, i64 448, i1 false)
  %26 = call i32 @InstallBlkDev(ptr noundef @_ZL16s_LittleFsStdDev, i32 noundef 3)
  store i32 %26, ptr getelementptr inbounds (%struct.__FS_Device, ptr @_ZL10s_FSDevice, i32 0, i32 3), align 8, !tbaa !22
  store i1 true, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %28

27:                                               ; preds = %9
  store i1 false, ptr %2, align 1
  store i32 1, ptr %5, align 4
  br label %28

28:                                               ; preds = %27, %25
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %29

29:                                               ; preds = %28, %8
  %30 = load i1, ptr %2, align 1
  ret i1 %30
}

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

declare i32 @lfs_mount(ptr noundef, ptr noundef) #2

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

declare i32 @InstallBlkDev(ptr noundef, i32 noundef) #2

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

attributes #0 = { mustprogress 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !6, i64 0}
!10 = !{!"_ZTS11__FS_Device", !6, i64 0, !11, i64 8, !7, i64 160, !13, i64 608}
!11 = !{!"_ZTS3lfs", !12, i64 0, !12, i64 24, !7, i64 48, !6, i64 56, !13, i64 64, !14, i64 68, !14, i64 80, !14, i64 92, !15, i64 104, !6, i64 128, !13, i64 136, !13, i64 140, !13, i64 144}
!12 = !{!"_ZTS9lfs_cache", !13, i64 0, !13, i64 4, !13, i64 8, !6, i64 16}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_ZTS10lfs_gstate", !13, i64 0, !7, i64 4}
!15 = !{!"_ZTSN3lfs8lfs_freeE", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !6, i64 16}
!16 = !{!17, !17, i64 0}
!17 = !{!"vtable pointer", !8, i64 0}
!18 = !{!19, !13, i64 48}
!19 = !{!"_ZTS10lfs_config", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !13, i64 40, !13, i64 44, !13, i64 48, !13, i64 52, !13, i64 56, !13, i64 60, !13, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !13, i64 96, !13, i64 100, !13, i64 104, !13, i64 108}
!20 = !{!19, !13, i64 52}
!21 = !{!13, !13, i64 0}
!22 = !{!10, !13, i64 608}


; 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.__FS_Device = type { ptr, %struct.lfs, [4 x %struct.__FS_FIle_Open], i32 }
%struct.lfs = type { %struct.lfs_cache, %struct.lfs_cache, [2 x i32], ptr, i32, %struct.lfs_gstate, %struct.lfs_gstate, %struct.lfs_gstate, %"struct.lfs::lfs_free", ptr, i32, i32, i32 }
%struct.lfs_cache = type { i32, i32, i32, ptr }
%struct.lfs_gstate = type { i32, [2 x i32] }
%"struct.lfs::lfs_free" = type { i32, i32, i32, i32, ptr }
%struct.__FS_FIle_Open = type { i8, %struct.lfs_file }
%struct.lfs_file = type { ptr, i16, i8, %struct.lfs_mdir, %"struct.lfs_file::lfs_ctz", i32, i32, i32, i32, %struct.lfs_cache, ptr }
%struct.lfs_mdir = type { [2 x i32], i32, i32, i32, i16, i8, i8, [2 x i32] }
%"struct.lfs_file::lfs_ctz" = type { i32, i32 }
%struct.lfs_config = type { ptr, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, i32, i32, i32, i32 }
%struct.StdDev_t = type { [8 x i8], ptr, ptr, ptr, ptr, ptr, ptr }

@_ZL10s_FSDevice = external hidden global %struct.__FS_Device, align 8
@_ZL13s_LittelFSCfg = external hidden global %struct.lfs_config, align 8
@_ZL16s_LittleFsStdDev = external hidden global %struct.StdDev_t, align 4

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z9StdFSInitP6DiskIO(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %17, label %3

3:                                                ; preds = %1
  store ptr %0, ptr @_ZL10s_FSDevice, align 8, !tbaa !5
  %4 = load ptr, ptr %0, align 8, !tbaa !15
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  %6 = load ptr, ptr %5, align 8
  %7 = tail call noundef zeroext i16 %6(ptr noundef nonnull align 8 dereferenceable(32) %0)
  %8 = zext i16 %7 to i32
  store i32 %8, ptr getelementptr inbounds (i8, ptr @_ZL13s_LittelFSCfg, i64 48), align 8, !tbaa !17
  %9 = load ptr, ptr %0, align 8, !tbaa !15
  %10 = getelementptr inbounds i8, ptr %9, i64 24
  %11 = load ptr, ptr %10, align 8
  %12 = tail call noundef i32 %11(ptr noundef nonnull align 8 dereferenceable(32) %0)
  store i32 %12, ptr getelementptr inbounds (i8, ptr @_ZL13s_LittelFSCfg, i64 52), align 4, !tbaa !19
  %13 = tail call i32 @lfs_mount(ptr noundef nonnull getelementptr inbounds (i8, ptr @_ZL10s_FSDevice, i64 8), ptr noundef nonnull @_ZL13s_LittelFSCfg)
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %17

15:                                               ; preds = %3
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(448) getelementptr inbounds (i8, ptr @_ZL10s_FSDevice, i64 160), i8 0, i64 448, i1 false)
  %16 = tail call i32 @InstallBlkDev(ptr noundef nonnull @_ZL16s_LittleFsStdDev, i32 noundef 3)
  store i32 %16, ptr getelementptr inbounds (i8, ptr @_ZL10s_FSDevice, i64 608), align 8, !tbaa !20
  br label %17

17:                                               ; preds = %15, %3, %1
  %.1 = phi i1 [ false, %1 ], [ false, %3 ], [ true, %15 ]
  ret i1 %.1
}

declare i32 @lfs_mount(ptr noundef, ptr noundef) local_unnamed_addr #1

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

declare i32 @InstallBlkDev(ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress 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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

!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 = !{!"_ZTS11__FS_Device", !7, i64 0, !10, i64 8, !8, i64 160, !12, i64 608}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTS3lfs", !11, i64 0, !11, i64 24, !8, i64 48, !7, i64 56, !12, i64 64, !13, i64 68, !13, i64 80, !13, i64 92, !14, i64 104, !7, i64 128, !12, i64 136, !12, i64 140, !12, i64 144}
!11 = !{!"_ZTS9lfs_cache", !12, i64 0, !12, i64 4, !12, i64 8, !7, i64 16}
!12 = !{!"int", !8, i64 0}
!13 = !{!"_ZTS10lfs_gstate", !12, i64 0, !8, i64 4}
!14 = !{!"_ZTSN3lfs8lfs_freeE", !12, i64 0, !12, i64 4, !12, i64 8, !12, i64 12, !7, i64 16}
!15 = !{!16, !16, i64 0}
!16 = !{!"vtable pointer", !9, i64 0}
!17 = !{!18, !12, i64 48}
!18 = !{!"_ZTS10lfs_config", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !12, i64 40, !12, i64 44, !12, i64 48, !12, i64 52, !12, i64 56, !12, i64 60, !12, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !12, i64 96, !12, i64 100, !12, i64 104, !12, i64 108}
!19 = !{!18, !12, i64 52}
!20 = !{!6, !12, i64 608}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass