; LLVM IR from SSBMTonberry/pocketlzma :: ref_spec/lzma1900/CPP/7zip/Archive/LzmaHandler.ll (ZN8NArchive5NLzma7CHeader5ParseEPKhb)

; 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.NArchive::NLzma::CHeader" = type { i64, i8, [5 x i8] }

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_ZN8NArchive5NLzma7CHeader5ParseEPKhb(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef %1, i1 noundef zeroext %2) #0 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i8, align 1
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  %9 = zext i1 %2 to i8
  store i8 %9, ptr %6, align 1, !tbaa !9
  %10 = load ptr, ptr %4, align 8
  %11 = getelementptr inbounds %"struct.NArchive::NLzma::CHeader", ptr %10, i32 0, i32 1
  store i8 0, ptr %11, align 8, !tbaa !11
  %12 = load i8, ptr %6, align 1, !tbaa !9, !range !14, !noundef !15
  %13 = trunc i8 %12 to i1
  br i1 %13, label %14, label %19

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %15, i64 0
  %17 = load i8, ptr %16, align 1, !tbaa !16
  %18 = getelementptr inbounds %"struct.NArchive::NLzma::CHeader", ptr %10, i32 0, i32 1
  store i8 %17, ptr %18, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %14, %3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i8, ptr %6, align 1, !tbaa !9, !range !14, !noundef !15
  %22 = trunc i8 %21 to i1
  %23 = zext i1 %22 to i64
  %24 = select i1 %22, i32 1, i32 0
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %20, i64 %25
  store ptr %26, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  store i32 0, ptr %8, align 4, !tbaa !17
  br label %27

27:                                               ; preds = %41, %19
  %28 = load i32, ptr %8, align 4, !tbaa !17
  %29 = icmp slt i32 %28, 5
  br i1 %29, label %31, label %30

30:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  br label %44

31:                                               ; preds = %27
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i32, ptr %8, align 4, !tbaa !17
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i8, ptr %32, i64 %34
  %36 = load i8, ptr %35, align 1, !tbaa !16
  %37 = getelementptr inbounds %"struct.NArchive::NLzma::CHeader", ptr %10, i32 0, i32 2
  %38 = load i32, ptr %8, align 4, !tbaa !17
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [5 x i8], ptr %37, i64 0, i64 %39
  store i8 %36, ptr %40, align 1, !tbaa !16
  br label %41

41:                                               ; preds = %31
  %42 = load i32, ptr %8, align 4, !tbaa !17
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %8, align 4, !tbaa !17
  br label %27, !llvm.loop !19

44:                                               ; preds = %30
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = getelementptr inbounds i8, ptr %45, i64 5
  %47 = load i64, ptr %46, align 8, !tbaa !21
  %48 = getelementptr inbounds %"struct.NArchive::NLzma::CHeader", ptr %10, i32 0, i32 0
  store i64 %47, ptr %48, align 8, !tbaa !22
  %49 = getelementptr inbounds %"struct.NArchive::NLzma::CHeader", ptr %10, i32 0, i32 2
  %50 = getelementptr inbounds [5 x i8], ptr %49, i64 0, i64 0
  %51 = load i8, ptr %50, align 1, !tbaa !16
  %52 = zext i8 %51 to i32
  %53 = icmp slt i32 %52, 225
  br i1 %53, label %54, label %70

54:                                               ; preds = %44
  %55 = getelementptr inbounds %"struct.NArchive::NLzma::CHeader", ptr %10, i32 0, i32 1
  %56 = load i8, ptr %55, align 8, !tbaa !11
  %57 = zext i8 %56 to i32
  %58 = icmp slt i32 %57, 2
  br i1 %58, label %59, label %70

59:                                               ; preds = %54
  %60 = call noundef zeroext i1 @_ZNK8NArchive5NLzma7CHeader7HasSizeEv(ptr noundef nonnull align 8 dereferenceable(16) %10)
  br i1 %60, label %61, label %65

61:                                               ; preds = %59
  %62 = getelementptr inbounds %"struct.NArchive::NLzma::CHeader", ptr %10, i32 0, i32 0
  %63 = load i64, ptr %62, align 8, !tbaa !22
  %64 = icmp ult i64 %63, 72057594037927936
  br i1 %64, label %65, label %70

65:                                               ; preds = %61, %59
  %66 = getelementptr inbounds %"struct.NArchive::NLzma::CHeader", ptr %10, i32 0, i32 2
  %67 = getelementptr inbounds [5 x i8], ptr %66, i64 0, i64 0
  %68 = getelementptr inbounds i8, ptr %67, i64 1
  %69 = call noundef zeroext i1 @_ZN8NArchive5NLzmaL12CheckDicSizeEPKh(ptr noundef %68)
  br label %70

70:                                               ; preds = %65, %61, %54, %44
  %71 = phi i1 [ false, %61 ], [ false, %54 ], [ false, %44 ], [ %69, %65 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  ret i1 %71
}

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK8NArchive5NLzma7CHeader7HasSizeEv(ptr noundef nonnull align 8 dereferenceable(16)) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN8NArchive5NLzmaL12CheckDicSizeEPKh(ptr noundef) #2

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 = { mustprogress 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 }

!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, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !7, i64 8}
!12 = !{!"_ZTSN8NArchive5NLzma7CHeaderE", !13, i64 0, !7, i64 8, !7, i64 9}
!13 = !{!"long long", !7, i64 0}
!14 = !{i8 0, i8 2}
!15 = !{}
!16 = !{!7, !7, i64 0}
!17 = !{!18, !18, i64 0}
!18 = !{!"int", !7, i64 0}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}
!21 = !{!13, !13, i64 0}
!22 = !{!12, !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: mustprogress nounwind uwtable
define dso_local noundef zeroext i1 @_ZN8NArchive5NLzma7CHeader5ParseEPKhb(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr nocapture noundef readonly %1, i1 noundef zeroext %2) local_unnamed_addr #0 align 2 {
  %4 = getelementptr inbounds i8, ptr %0, i64 8
  store i8 0, ptr %4, align 8, !tbaa !5
  br i1 %2, label %5, label %8

5:                                                ; preds = %3
  %6 = load i8, ptr %1, align 1, !tbaa !10
  store i8 %6, ptr %4, align 8, !tbaa !5
  %7 = icmp ult i8 %6, 2
  br label %8

8:                                                ; preds = %5, %3
  %9 = phi i1 [ %7, %5 ], [ true, %3 ]
  %10 = zext i1 %2 to i64
  %11 = getelementptr inbounds i8, ptr %1, i64 %10
  %12 = getelementptr inbounds i8, ptr %0, i64 9
  %13 = load i8, ptr %11, align 1, !tbaa !10
  store i8 %13, ptr %12, align 1, !tbaa !10
  %14 = getelementptr inbounds i8, ptr %11, i64 1
  %15 = load i8, ptr %14, align 1, !tbaa !10
  %16 = getelementptr inbounds i8, ptr %0, i64 10
  store i8 %15, ptr %16, align 2, !tbaa !10
  %17 = getelementptr inbounds i8, ptr %11, i64 2
  %18 = load i8, ptr %17, align 1, !tbaa !10
  %19 = getelementptr inbounds i8, ptr %0, i64 11
  store i8 %18, ptr %19, align 1, !tbaa !10
  %20 = getelementptr inbounds i8, ptr %11, i64 3
  %21 = load i8, ptr %20, align 1, !tbaa !10
  %22 = getelementptr inbounds i8, ptr %0, i64 12
  store i8 %21, ptr %22, align 4, !tbaa !10
  %23 = getelementptr inbounds i8, ptr %11, i64 4
  %24 = load i8, ptr %23, align 1, !tbaa !10
  %25 = getelementptr inbounds i8, ptr %0, i64 13
  store i8 %24, ptr %25, align 1, !tbaa !10
  %26 = getelementptr inbounds i8, ptr %11, i64 5
  %27 = load i64, ptr %26, align 8, !tbaa !11
  store i64 %27, ptr %0, align 8, !tbaa !12
  %28 = icmp ult i8 %13, -31
  %or.cond = select i1 %28, i1 %9, i1 false
  br i1 %or.cond, label %29, label %36

29:                                               ; preds = %8
  %30 = tail call noundef zeroext i1 @_ZNK8NArchive5NLzma7CHeader7HasSizeEv(ptr noundef nonnull align 8 dereferenceable(16) %0)
  %31 = load i64, ptr %0, align 8
  %32 = icmp ugt i64 %31, 72057594037927935
  %or.cond12.not = select i1 %30, i1 %32, i1 false
  br i1 %or.cond12.not, label %36, label %33

33:                                               ; preds = %29
  %34 = getelementptr inbounds i8, ptr %0, i64 10
  %35 = tail call noundef zeroext i1 @_ZN8NArchive5NLzmaL12CheckDicSizeEPKh(ptr noundef nonnull %34)
  br label %36

36:                                               ; preds = %29, %33, %8
  %37 = phi i1 [ false, %8 ], [ %35, %33 ], [ false, %29 ]
  ret i1 %37
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNK8NArchive5NLzma7CHeader7HasSizeEv(ptr noundef nonnull align 8 dereferenceable(16)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef zeroext i1 @_ZN8NArchive5NLzmaL12CheckDicSizeEPKh(ptr noundef) local_unnamed_addr #0

attributes #0 = { mustprogress 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" }

!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 8}
!6 = !{!"_ZTSN8NArchive5NLzma7CHeaderE", !7, i64 0, !8, i64 8, !8, i64 9}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!8, !8, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass