; LLVM IR from lzfse/lzfse :: src (lzfse_decode)

; 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.lzfse_decoder_state = type { ptr, ptr, ptr, ptr, ptr, ptr, i32, i32, %struct.lzfse_compressed_block_decoder_state, %struct.lzvn_compressed_block_decoder_state, %struct.uncompressed_block_decoder_state }
%struct.lzfse_compressed_block_decoder_state = type { i32, i32, ptr, i32, i32, i32, %struct.fse_in_stream64, i32, i16, i16, i16, [6 x i8], [64 x %struct.fse_value_decoder_entry], [64 x %struct.fse_value_decoder_entry], [256 x %struct.fse_value_decoder_entry], [1024 x i32], [40064 x i8] }
%struct.fse_in_stream64 = type { i64, i32 }
%struct.fse_value_decoder_entry = type { i8, i8, i16, i32 }
%struct.lzvn_compressed_block_decoder_state = type { i32, i32, i32 }
%struct.uncompressed_block_decoder_state = type { i32 }

; Function Attrs: nounwind uwtable
define dso_local i64 @lzfse_decode_buffer_with_scratch(ptr noalias noundef %0, i64 noundef %1, ptr noalias noundef %2, i64 noundef %3, ptr noalias noundef %4) #0 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %15 = load ptr, ptr %11, align 8, !tbaa !5
  store ptr %15, ptr %12, align 8, !tbaa !5
  %16 = load ptr, ptr %12, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %16, i8 0, i64 47368, i1 false)
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = load ptr, ptr %12, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.lzfse_decoder_state, ptr %18, i32 0, i32 0
  store ptr %17, ptr %19, align 8, !tbaa !11
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  %21 = load ptr, ptr %12, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.lzfse_decoder_state, ptr %21, i32 0, i32 1
  store ptr %20, ptr %22, align 8, !tbaa !19
  %23 = load ptr, ptr %12, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.lzfse_decoder_state, ptr %23, i32 0, i32 0
  %25 = load ptr, ptr %24, align 8, !tbaa !11
  %26 = load i64, ptr %10, align 8, !tbaa !9
  %27 = getelementptr inbounds i8, ptr %25, i64 %26
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.lzfse_decoder_state, ptr %28, i32 0, i32 2
  store ptr %27, ptr %29, align 8, !tbaa !20
  %30 = load ptr, ptr %7, align 8, !tbaa !5
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.lzfse_decoder_state, ptr %31, i32 0, i32 3
  store ptr %30, ptr %32, align 8, !tbaa !21
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load ptr, ptr %12, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.lzfse_decoder_state, ptr %34, i32 0, i32 4
  store ptr %33, ptr %35, align 8, !tbaa !22
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i64, ptr %8, align 8, !tbaa !9
  %38 = getelementptr inbounds i8, ptr %36, i64 %37
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.lzfse_decoder_state, ptr %39, i32 0, i32 5
  store ptr %38, ptr %40, align 8, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = call i32 @lzfse_decode(ptr noundef %41)
  store i32 %42, ptr %13, align 4, !tbaa !24
  %43 = load i32, ptr %13, align 4, !tbaa !24
  %44 = icmp eq i32 %43, -2
  br i1 %44, label %45, label %47

45:                                               ; preds = %5
  %46 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %46, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %59

47:                                               ; preds = %5
  %48 = load i32, ptr %13, align 4, !tbaa !24
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %47
  store i64 0, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %59

51:                                               ; preds = %47
  %52 = load ptr, ptr %12, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.lzfse_decoder_state, ptr %52, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !21
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = ptrtoint ptr %54 to i64
  %57 = ptrtoint ptr %55 to i64
  %58 = sub i64 %56, %57
  store i64 %58, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %59

59:                                               ; preds = %51, %50, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %60 = load i64, ptr %6, align 8
  ret i64 %60
}

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

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

declare i32 @lzfse_decode(ptr noundef) #3

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

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

!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 = !{!"long", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !13, i64 48, !13, i64 52, !14, i64 56, !17, i64 47352, !18, i64 47364}
!13 = !{!"int", !7, i64 0}
!14 = !{!"", !13, i64 0, !13, i64 4, !6, i64 8, !13, i64 16, !13, i64 20, !13, i64 24, !15, i64 32, !13, i64 48, !16, i64 52, !16, i64 54, !16, i64 56, !7, i64 64, !7, i64 576, !7, i64 1088, !7, i64 3136, !7, i64 7232}
!15 = !{!"", !10, i64 0, !13, i64 8}
!16 = !{!"short", !7, i64 0}
!17 = !{!"", !13, i64 0, !13, i64 4, !13, i64 8}
!18 = !{!"", !13, i64 0}
!19 = !{!12, !6, i64 8}
!20 = !{!12, !6, i64 16}
!21 = !{!12, !6, i64 24}
!22 = !{!12, !6, i64 32}
!23 = !{!12, !6, i64 40}
!24 = !{!13, !13, 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"

; Function Attrs: nounwind uwtable
define dso_local i64 @lzfse_decode_buffer_with_scratch(ptr noalias noundef %0, i64 noundef %1, ptr noalias noundef %2, i64 noundef %3, ptr noalias noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %4, i64 48
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(47368) %6, i8 0, i64 47320, i1 false)
  store ptr %2, ptr %4, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %4, i64 8
  store ptr %2, ptr %7, align 8, !tbaa !17
  %8 = getelementptr inbounds i8, ptr %2, i64 %3
  %9 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr %8, ptr %9, align 8, !tbaa !18
  %10 = getelementptr inbounds i8, ptr %4, i64 24
  store ptr %0, ptr %10, align 8, !tbaa !19
  %11 = getelementptr inbounds i8, ptr %4, i64 32
  store ptr %0, ptr %11, align 8, !tbaa !20
  %12 = getelementptr inbounds i8, ptr %0, i64 %1
  %13 = getelementptr inbounds i8, ptr %4, i64 40
  store ptr %12, ptr %13, align 8, !tbaa !21
  %14 = tail call i32 @lzfse_decode(ptr noundef nonnull %4) #3
  switch i32 %14, label %15 [
    i32 -2, label %21
    i32 0, label %16
  ]

15:                                               ; preds = %5
  br label %21

16:                                               ; preds = %5
  %17 = load ptr, ptr %10, align 8, !tbaa !19
  %18 = ptrtoint ptr %17 to i64
  %19 = ptrtoint ptr %0 to i64
  %20 = sub i64 %18, %19
  br label %21

21:                                               ; preds = %5, %16, %15
  %.0 = phi i64 [ 0, %15 ], [ %20, %16 ], [ %1, %5 ]
  ret i64 %.0
}

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

declare i32 @lzfse_decode(ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32, !7, i64 40, !10, i64 48, !10, i64 52, !11, i64 56, !15, i64 47352, !16, i64 47364}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"", !10, i64 0, !10, i64 4, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !12, i64 32, !10, i64 48, !14, i64 52, !14, i64 54, !14, i64 56, !8, i64 64, !8, i64 576, !8, i64 1088, !8, i64 3136, !8, i64 7232}
!12 = !{!"", !13, i64 0, !10, i64 8}
!13 = !{!"long", !8, i64 0}
!14 = !{!"short", !8, i64 0}
!15 = !{!"", !10, i64 0, !10, i64 4, !10, i64 8}
!16 = !{!"", !10, i64 0}
!17 = !{!6, !7, i64 8}
!18 = !{!6, !7, i64 16}
!19 = !{!6, !7, i64 24}
!20 = !{!6, !7, i64 32}
!21 = !{!6, !7, i64 40}


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