; LLVM IR from mncoppola/rpef :: utilities_src/squashfs2.1/lzma/C/7zip/Compress/LZMA_Alone (LzmaRamDecode)

; 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"

; Function Attrs: nounwind uwtable
define dso_local i32 @LzmaRamGetUncompressedSize(ptr noundef %0, i64 noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i64 %1, ptr %6, align 8, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %10 = load i64, ptr %6, align 8, !tbaa !9
  %11 = icmp ult i64 %10, 14
  br i1 %11, label %12, label %13

12:                                               ; preds = %3
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %56

13:                                               ; preds = %3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 0, ptr %14, align 8, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %15

15:                                               ; preds = %34, %13
  %16 = load i32, ptr %8, align 4, !tbaa !11
  %17 = zext i32 %16 to i64
  %18 = icmp ult i64 %17, 8
  br i1 %18, label %19, label %37

19:                                               ; preds = %15
  %20 = load ptr, ptr %5, align 8, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !11
  %22 = add i32 6, %21
  %23 = zext i32 %22 to i64
  %24 = getelementptr inbounds i8, ptr %20, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !13
  %26 = zext i8 %25 to i64
  %27 = load i32, ptr %8, align 4, !tbaa !11
  %28 = mul i32 8, %27
  %29 = zext i32 %28 to i64
  %30 = shl i64 %26, %29
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = add i64 %32, %30
  store i64 %33, ptr %31, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %19
  %35 = load i32, ptr %8, align 4, !tbaa !11
  %36 = add i32 %35, 1
  store i32 %36, ptr %8, align 4, !tbaa !11
  br label %15, !llvm.loop !14

37:                                               ; preds = %15
  br label %38

38:                                               ; preds = %52, %37
  %39 = load i32, ptr %8, align 4, !tbaa !11
  %40 = icmp ult i32 %39, 8
  br i1 %40, label %41, label %55

41:                                               ; preds = %38
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = load i32, ptr %8, align 4, !tbaa !11
  %44 = add i32 6, %43
  %45 = zext i32 %44 to i64
  %46 = getelementptr inbounds i8, ptr %42, i64 %45
  %47 = load i8, ptr %46, align 1, !tbaa !13
  %48 = zext i8 %47 to i32
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %41
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %56

51:                                               ; preds = %41
  br label %52

52:                                               ; preds = %51
  %53 = load i32, ptr %8, align 4, !tbaa !11
  %54 = add i32 %53, 1
  store i32 %54, ptr %8, align 4, !tbaa !11
  br label %38, !llvm.loop !16

55:                                               ; preds = %38
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %56

56:                                               ; preds = %55, %50, %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %57 = load i32, ptr %4, align 4
  ret i32 %57
}

; 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

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 = { 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


; 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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local range(i32 0, 2) i32 @LzmaRamGetUncompressedSize(ptr nocapture noundef readonly %0, i64 noundef %1, ptr nocapture noundef writeonly %2) local_unnamed_addr #0 {
  %4 = icmp ult i64 %1, 14
  br i1 %4, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %3
  store i64 0, ptr %2, align 8, !tbaa !5
  %invariant.gep = getelementptr inbounds i8, ptr %0, i64 6
  %5 = load i8, ptr %invariant.gep, align 1, !tbaa !9
  %6 = zext i8 %5 to i64
  store i64 %6, ptr %2, align 8, !tbaa !5
  %gep.1 = getelementptr inbounds i8, ptr %0, i64 7
  %7 = load i8, ptr %gep.1, align 1, !tbaa !9
  %8 = zext i8 %7 to i64
  %9 = shl nuw nsw i64 %8, 8
  %10 = or disjoint i64 %9, %6
  store i64 %10, ptr %2, align 8, !tbaa !5
  %gep.2 = getelementptr inbounds i8, ptr %0, i64 8
  %11 = load i8, ptr %gep.2, align 1, !tbaa !9
  %12 = zext i8 %11 to i64
  %13 = shl nuw nsw i64 %12, 16
  %14 = or disjoint i64 %13, %10
  store i64 %14, ptr %2, align 8, !tbaa !5
  %gep.3 = getelementptr inbounds i8, ptr %0, i64 9
  %15 = load i8, ptr %gep.3, align 1, !tbaa !9
  %16 = zext i8 %15 to i64
  %17 = shl nuw nsw i64 %16, 24
  %18 = or disjoint i64 %17, %14
  store i64 %18, ptr %2, align 8, !tbaa !5
  %gep.4 = getelementptr inbounds i8, ptr %0, i64 10
  %19 = load i8, ptr %gep.4, align 1, !tbaa !9
  %20 = zext i8 %19 to i64
  %21 = shl nuw nsw i64 %20, 32
  %22 = or disjoint i64 %21, %18
  store i64 %22, ptr %2, align 8, !tbaa !5
  %gep.5 = getelementptr inbounds i8, ptr %0, i64 11
  %23 = load i8, ptr %gep.5, align 1, !tbaa !9
  %24 = zext i8 %23 to i64
  %25 = shl nuw nsw i64 %24, 40
  %26 = or disjoint i64 %25, %22
  store i64 %26, ptr %2, align 8, !tbaa !5
  %gep.6 = getelementptr inbounds i8, ptr %0, i64 12
  %27 = load i8, ptr %gep.6, align 1, !tbaa !9
  %28 = zext i8 %27 to i64
  %29 = shl nuw nsw i64 %28, 48
  %30 = add nuw nsw i64 %29, %26
  store i64 %30, ptr %2, align 8, !tbaa !5
  %gep.7 = getelementptr inbounds i8, ptr %0, i64 13
  %31 = load i8, ptr %gep.7, align 1, !tbaa !9
  %32 = zext i8 %31 to i64
  %33 = shl nuw i64 %32, 56
  %34 = add nuw i64 %33, %30
  store i64 %34, ptr %2, align 8, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.preheader, %3
  %.012 = phi i32 [ 1, %3 ], [ 0, %.preheader ]
  ret i32 %.012
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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, !6, i64 0}
!6 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass