; LLVM IR from joembedded/JesFs :: jesfs_ml (sflash_interpret_id)

; 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] }

@sflash_info = external dso_local 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
define dso_local signext i16 @sflash_interpret_id(i32 noundef %0) #1 {
  %2 = alloca i16, align 2
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  store i32 0, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 1), align 4, !tbaa !9
  %6 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %6, ptr @sflash_info, align 4, !tbaa !12
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = icmp eq i32 %7, 0
  br i1 %8, label %9, label %10

9:                                                ; preds = %1
  store i16 -144, ptr %2, align 2
  store i32 1, ptr %5, align 4
  br label %35

10:                                               ; preds = %1
  %11 = load i32, ptr %3, align 4, !tbaa !5
  %12 = icmp eq i32 %11, 16777215
  br i1 %12, label %13, label %14

13:                                               ; preds = %10
  store i16 -145, ptr %2, align 2
  store i32 1, ptr %5, align 4
  br label %35

14:                                               ; preds = %10
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = lshr i32 %15, 8
  switch i32 %16, label %17 [
    i32 49704, label %18
    i32 51300, label %18
    i32 51301, label %18
  ]

17:                                               ; preds = %14
  store i16 -104, ptr %2, align 2
  store i32 1, ptr %5, align 4
  br label %35

18:                                               ; preds = %14, %14, %14
  br label %19

19:                                               ; preds = %18
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = and i32 %20, 255
  %22 = trunc i32 %21 to i8
  store i8 %22, ptr %4, align 1, !tbaa !13
  %23 = load i8, ptr %4, align 1, !tbaa !13
  %24 = zext i8 %23 to i32
  %25 = icmp slt i32 %24, 13
  br i1 %25, label %30, label %26

26:                                               ; preds = %19
  %27 = load i8, ptr %4, align 1, !tbaa !13
  %28 = zext i8 %27 to i32
  %29 = icmp sgt i32 %28, 24
  br i1 %29, label %30, label %31

30:                                               ; preds = %26, %19
  store i16 -103, ptr %2, align 2
  store i32 1, ptr %5, align 4
  br label %35

31:                                               ; preds = %26
  %32 = load i8, ptr %4, align 1, !tbaa !13
  %33 = zext i8 %32 to i32
  %34 = shl i32 1, %33
  store i32 %34, ptr getelementptr inbounds (%struct.SFLASH_INFO, ptr @sflash_info, i32 0, i32 1), align 4, !tbaa !9
  store i16 0, ptr %2, align 2
  store i32 1, ptr %5, align 4
  br label %35

35:                                               ; preds = %31, %30, %17, %13, %9
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  %36 = load i16, ptr %2, align 2
  ret i16 %36
}

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 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 4}
!10 = !{!"", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12, !6, i64 16, !11, i64 20, !11, i64 22, !11, i64 24, !11, i64 26, !11, i64 28, !7, i64 32, !7, i64 160}
!11 = !{!"short", !7, i64 0}
!12 = !{!10, !6, i64 0}
!13 = !{!7, !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"

%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 dso_local local_unnamed_addr global %struct.SFLASH_INFO, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(write, argmem: none, inaccessiblemem: none) uwtable
define dso_local signext range(i16 -145, 1) i16 @sflash_interpret_id(i32 noundef %0) local_unnamed_addr #0 {
  store i32 0, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 4), align 4, !tbaa !5
  store i32 %0, ptr @sflash_info, align 4, !tbaa !11
  switch i32 %0, label %3 [
    i32 0, label %10
    i32 16777215, label %2
  ]

2:                                                ; preds = %1
  br label %10

3:                                                ; preds = %1
  %4 = lshr i32 %0, 8
  switch i32 %4, label %10 [
    i32 49704, label %5
    i32 51300, label %5
    i32 51301, label %5
  ]

5:                                                ; preds = %3, %3, %3
  %6 = and i32 %0, 255
  %7 = add nsw i32 %6, -25
  %or.cond = icmp ult i32 %7, -12
  br i1 %or.cond, label %10, label %8

8:                                                ; preds = %5
  %9 = shl nuw nsw i32 1, %6
  store i32 %9, ptr getelementptr inbounds (i8, ptr @sflash_info, i64 4), align 4, !tbaa !5
  br label %10

10:                                               ; preds = %5, %3, %1, %8, %2
  %.0 = phi i16 [ -145, %2 ], [ 0, %8 ], [ -144, %1 ], [ -104, %3 ], [ -103, %5 ]
  ret i16 %.0
}

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

!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 4}
!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 = !{!6, !7, i64 0}


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