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

; 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_STAT = type { [22 x i8], i32, i32, i32, i32, i8 }

@sflash_info = external global %struct.SFLASH_INFO, align 4

; 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local signext i16 @fs_info(ptr noundef %0, i16 noundef zeroext %1) #1 {
  %3 = alloca i16, align 2
  %4 = alloca ptr, align 8
  %5 = alloca i16, align 2
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i16, align 2
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i16 %1, ptr %5, align 2, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #3
  %10 = load i8, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 11), align 4, !tbaa !11
  %11 = zext i8 %10 to i32
  %12 = and i32 %11, 3
  %13 = icmp ne i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  store i16 -148, ptr %3, align 2
  store i32 1, ptr %9, align 4
  br label %79

15:                                               ; preds = %2
  %16 = load i16, ptr %5, align 2, !tbaa !9
  %17 = zext i16 %16 to i32
  %18 = mul nsw i32 %17, 4
  %19 = add nsw i32 12, %18
  store i32 %19, ptr %7, align 4, !tbaa !14
  %20 = load i32, ptr %7, align 4, !tbaa !14
  %21 = icmp ugt i32 %20, 4092
  br i1 %21, label %22, label %23

22:                                               ; preds = %15
  store i16 128, ptr %3, align 2
  store i32 1, ptr %9, align 4
  br label %79

23:                                               ; preds = %15
  %24 = load i32, ptr %7, align 4, !tbaa !14
  call void @sflash_read(i32 noundef %24, ptr noundef %6, i16 noundef zeroext 4)
  %25 = load i32, ptr %6, align 4, !tbaa !14
  %26 = icmp eq i32 %25, -1
  br i1 %26, label %27, label %28

27:                                               ; preds = %23
  store i16 0, ptr %3, align 2
  store i32 1, ptr %9, align 4
  br label %79

28:                                               ; preds = %23
  %29 = load i32, ptr %6, align 4, !tbaa !14
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %32, label %31

31:                                               ; preds = %28
  store i16 -143, ptr %3, align 2
  store i32 1, ptr %9, align 4
  br label %79

32:                                               ; preds = %28
  %33 = load i32, ptr %6, align 4, !tbaa !14
  %34 = load i32, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 1), align 4, !tbaa !15
  %35 = icmp uge i32 %33, %34
  br i1 %35, label %36, label %37

36:                                               ; preds = %32
  store i16 -115, ptr %3, align 2
  store i32 1, ptr %9, align 4
  br label %79

37:                                               ; preds = %32
  %38 = load i32, ptr %6, align 4, !tbaa !14
  call void @sflash_read(i32 noundef %38, ptr noundef getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i16 noundef zeroext 48)
  %39 = load i32, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), align 4, !tbaa !16
  switch i32 %39, label %43 [
    i32 -54982, label %40
    i32 -57040, label %41
    i32 -1, label %42
  ]

40:                                               ; preds = %37
  store i16 1, ptr %8, align 2, !tbaa !9
  br label %44

41:                                               ; preds = %37
  store i16 2, ptr %8, align 2, !tbaa !9
  br label %44

42:                                               ; preds = %37
  store i16 -126, ptr %3, align 2
  store i32 1, ptr %9, align 4
  br label %79

43:                                               ; preds = %37
  store i16 -142, ptr %3, align 2
  store i32 1, ptr %9, align 4
  br label %79

44:                                               ; preds = %41, %40
  %45 = load i32, ptr %6, align 4, !tbaa !14
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.FS_STAT, ptr %46, i32 0, i32 4
  store i32 %45, ptr %47, align 4, !tbaa !17
  %48 = load ptr, ptr %4, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.FS_STAT, ptr %48, i32 0, i32 0
  %50 = getelementptr inbounds [22 x i8], ptr %49, i64 0, i64 0
  call void @fs_strncpy(ptr noundef %50, ptr noundef getelementptr inbounds ([128 x i8], ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i64 0, i64 24), i8 noundef zeroext 21)
  %51 = load i32, ptr getelementptr inbounds ([32 x i32], ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 10), i64 0, i64 4), align 4, !tbaa !16
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.FS_STAT, ptr %52, i32 0, i32 3
  store i32 %51, ptr %53, align 4, !tbaa !19
  %54 = 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 !16
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.FS_STAT, ptr %55, i32 0, i32 1
  store i32 %54, ptr %56, align 4, !tbaa !20
  %57 = 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 !16
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.FS_STAT, ptr %58, i32 0, i32 5
  store i8 %57, ptr %59, align 4, !tbaa !21
  %60 = 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 !16
  store i32 %60, ptr %6, align 4, !tbaa !14
  %61 = load i32, ptr %6, align 4, !tbaa !14
  %62 = icmp eq i32 %61, -1
  br i1 %62, label %63, label %74

63:                                               ; preds = %44
  %64 = load i16, ptr %8, align 2, !tbaa !9
  %65 = sext i16 %64 to i32
  %66 = or i32 %65, 4
  %67 = trunc i32 %66 to i16
  store i16 %67, ptr %8, align 2, !tbaa !9
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.FS_STAT, ptr %68, i32 0, i32 5
  %70 = load i8, ptr %69, align 4, !tbaa !21
  %71 = zext i8 %70 to i32
  %72 = or i32 %71, 32
  %73 = trunc i32 %72 to i8
  store i8 %73, ptr %69, align 4, !tbaa !21
  br label %74

74:                                               ; preds = %63, %44
  %75 = load i32, ptr %6, align 4, !tbaa !14
  %76 = load ptr, ptr %4, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.FS_STAT, ptr %76, i32 0, i32 2
  store i32 %75, ptr %77, align 4, !tbaa !22
  %78 = load i16, ptr %8, align 2, !tbaa !9
  store i16 %78, ptr %3, align 2
  store i32 1, ptr %9, align 4
  br label %79

79:                                               ; preds = %74, %43, %42, %36, %31, %27, %22, %14
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %80 = load i16, ptr %3, align 2
  ret i16 %80
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 = !{!10, !10, i64 0}
!10 = !{!"short", !7, i64 0}
!11 = !{!12, !7, i64 160}
!12 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8, !13, i64 12, !13, i64 16, !10, i64 20, !10, i64 22, !10, i64 24, !10, i64 26, !10, i64 28, !7, i64 32, !7, i64 160}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 4}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !13, i64 36}
!18 = !{!"", !7, i64 0, !13, i64 24, !13, i64 28, !13, i64 32, !13, i64 36, !7, i64 40}
!19 = !{!18, !13, i64 32}
!20 = !{!18, !13, i64 24}
!21 = !{!18, !7, i64 40}
!22 = !{!18, !13, i64 28}


; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

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

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

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

6:                                                ; preds = %2
  %7 = icmp ugt i16 %1, 1020
  br i1 %7, label %35, label %8

8:                                                ; preds = %6
  %9 = shl nuw nsw i16 %1, 2
  %narrow = add nuw nsw i16 %9, 12
  %10 = zext nneg i16 %narrow to i32
  call void @sflash_read(i32 noundef %10, ptr noundef nonnull %3, i16 noundef zeroext 4) #3
  %11 = load i32, ptr %3, align 4, !tbaa !11
  switch i32 %11, label %13 [
    i32 -1, label %35
    i32 0, label %12
  ]

12:                                               ; preds = %8
  br label %35

13:                                               ; preds = %8
  %14 = load i32, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 4), align 4, !tbaa !12
  %.not16 = icmp ult i32 %11, %14
  br i1 %.not16, label %15, label %35

15:                                               ; preds = %13
  call void @sflash_read(i32 noundef %11, ptr noundef nonnull getelementptr inbounds (i8, ptr @sflash_info, i64 32), i16 noundef zeroext 48) #3
  %16 = load i32, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 32), align 4, !tbaa !13
  switch i32 %16, label %18 [
    i32 -54982, label %19
    i32 -57040, label %17
    i32 -1, label %35
  ]

17:                                               ; preds = %15
  br label %19

18:                                               ; preds = %15
  br label %35

19:                                               ; preds = %15, %17
  %.0 = phi i16 [ 2, %17 ], [ 1, %15 ]
  %20 = load i32, ptr %3, align 4, !tbaa !11
  %21 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 %20, ptr %21, align 4, !tbaa !14
  call void @fs_strncpy(ptr noundef %0, ptr noundef nonnull getelementptr inbounds (i8, ptr @sflash_info, i64 56), i8 noundef zeroext 21)
  %22 = load i32, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 48), align 4, !tbaa !13
  %23 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 %22, ptr %23, align 4, !tbaa !16
  %24 = load i32, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 52), align 4, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %24, ptr %25, align 4, !tbaa !17
  %26 = load i8, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 78), align 2, !tbaa !13
  %27 = getelementptr inbounds i8, ptr %0, i64 40
  store i8 %26, ptr %27, align 4, !tbaa !18
  %28 = load i32, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 44), align 4, !tbaa !13
  %29 = icmp eq i32 %28, -1
  br i1 %29, label %30, label %33

30:                                               ; preds = %19
  %31 = or disjoint i16 %.0, 4
  %32 = or i8 %26, 32
  store i8 %32, ptr %27, align 4, !tbaa !18
  br label %33

33:                                               ; preds = %30, %19
  %.1 = phi i16 [ %31, %30 ], [ %.0, %19 ]
  %34 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %28, ptr %34, align 4, !tbaa !19
  br label %35

35:                                               ; preds = %15, %13, %8, %6, %2, %33, %18, %12
  %.012 = phi i16 [ -142, %18 ], [ %.1, %33 ], [ -143, %12 ], [ -148, %2 ], [ 128, %6 ], [ 0, %8 ], [ -115, %13 ], [ -126, %15 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #3
  ret i16 %.012
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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, !8, i64 160}
!6 = !{!"", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12, !7, i64 16, !10, i64 20, !10, i64 22, !10, i64 24, !10, i64 26, !10, i64 28, !8, i64 32, !8, i64 160}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"short", !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 4}
!13 = !{!8, !8, i64 0}
!14 = !{!15, !7, i64 36}
!15 = !{!"", !8, i64 0, !7, i64 24, !7, i64 28, !7, i64 32, !7, i64 36, !8, i64 40}
!16 = !{!15, !7, i64 32}
!17 = !{!15, !7, i64 24}
!18 = !{!15, !8, i64 40}
!19 = !{!15, !7, i64 28}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass