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

; 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._CLzmaProperties = type { i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @LzmaDecodeProperties(ptr noundef %0, ptr noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i32 %2, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  %10 = load i32, ptr %7, align 4, !tbaa !9
  %11 = icmp slt i32 %10, 5
  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 %60

13:                                               ; preds = %3
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %14, i64 0
  %16 = load i8, ptr %15, align 1, !tbaa !11
  store i8 %16, ptr %8, align 1, !tbaa !11
  %17 = load i8, ptr %8, align 1, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = icmp sge i32 %18, 225
  br i1 %19, label %20, label %21

20:                                               ; preds = %13
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %60

21:                                               ; preds = %13
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct._CLzmaProperties, ptr %22, i32 0, i32 2
  store i32 0, ptr %23, align 4, !tbaa !12
  br label %24

24:                                               ; preds = %29, %21
  %25 = load i8, ptr %8, align 1, !tbaa !11
  %26 = zext i8 %25 to i32
  %27 = icmp sge i32 %26, 45
  br i1 %27, label %28, label %38

28:                                               ; preds = %24
  br label %29

29:                                               ; preds = %28
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct._CLzmaProperties, ptr %30, i32 0, i32 2
  %32 = load i32, ptr %31, align 4, !tbaa !12
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %31, align 4, !tbaa !12
  %34 = load i8, ptr %8, align 1, !tbaa !11
  %35 = zext i8 %34 to i32
  %36 = sub nsw i32 %35, 45
  %37 = trunc i32 %36 to i8
  store i8 %37, ptr %8, align 1, !tbaa !11
  br label %24, !llvm.loop !14

38:                                               ; preds = %24
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct._CLzmaProperties, ptr %39, i32 0, i32 1
  store i32 0, ptr %40, align 4, !tbaa !16
  br label %41

41:                                               ; preds = %46, %38
  %42 = load i8, ptr %8, align 1, !tbaa !11
  %43 = zext i8 %42 to i32
  %44 = icmp sge i32 %43, 9
  br i1 %44, label %45, label %55

45:                                               ; preds = %41
  br label %46

46:                                               ; preds = %45
  %47 = load ptr, ptr %5, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct._CLzmaProperties, ptr %47, i32 0, i32 1
  %49 = load i32, ptr %48, align 4, !tbaa !16
  %50 = add nsw i32 %49, 1
  store i32 %50, ptr %48, align 4, !tbaa !16
  %51 = load i8, ptr %8, align 1, !tbaa !11
  %52 = zext i8 %51 to i32
  %53 = sub nsw i32 %52, 9
  %54 = trunc i32 %53 to i8
  store i8 %54, ptr %8, align 1, !tbaa !11
  br label %41, !llvm.loop !17

55:                                               ; preds = %41
  %56 = load i8, ptr %8, align 1, !tbaa !11
  %57 = zext i8 %56 to i32
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct._CLzmaProperties, ptr %58, i32 0, i32 0
  store i32 %57, ptr %59, align 4, !tbaa !18
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %60

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

; 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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 8}
!13 = !{!"_CLzmaProperties", !10, i64 0, !10, i64 4, !10, i64 8}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!13, !10, i64 4}
!17 = distinct !{!17, !15}
!18 = !{!13, !10, 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 nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local range(i32 0, 2) i32 @LzmaDecodeProperties(ptr nocapture noundef writeonly %0, ptr nocapture noundef readonly %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp slt i32 %2, 5
  br i1 %4, label %24, label %5

5:                                                ; preds = %3
  %6 = load i8, ptr %1, align 1, !tbaa !5
  %.fr28 = freeze i8 %6
  %7 = icmp ugt i8 %.fr28, -32
  br i1 %7, label %24, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  %10 = icmp ugt i8 %.fr28, 44
  br i1 %10, label %.lr.ph, label %15

.lr.ph:                                           ; preds = %8
  %11 = add i8 %.fr28, -45
  %12 = udiv i8 %11, 45
  %13 = urem i8 %11, 45
  %narrow = add nuw nsw i8 %12, 1
  %14 = zext nneg i8 %narrow to i32
  br label %15

15:                                               ; preds = %.lr.ph, %8
  %storemerge = phi i32 [ %14, %.lr.ph ], [ 0, %8 ]
  %.0.lcssa = phi i8 [ %13, %.lr.ph ], [ %.fr28, %8 ]
  store i32 %storemerge, ptr %9, align 4, !tbaa !8
  %16 = getelementptr inbounds i8, ptr %0, i64 4
  %17 = icmp ugt i8 %.0.lcssa, 8
  br i1 %17, label %.lr.ph20, label %22

.lr.ph20:                                         ; preds = %15
  %18 = add nsw i8 %.0.lcssa, -9
  %19 = udiv i8 %18, 9
  %20 = urem i8 %18, 9
  %narrow29 = add nuw nsw i8 %19, 1
  %21 = zext nneg i8 %narrow29 to i32
  br label %22

22:                                               ; preds = %.lr.ph20, %15
  %storemerge30 = phi i32 [ %21, %.lr.ph20 ], [ 0, %15 ]
  %.1.lcssa = phi i8 [ %20, %.lr.ph20 ], [ %.0.lcssa, %15 ]
  store i32 %storemerge30, ptr %16, align 4, !tbaa !11
  %23 = zext nneg i8 %.1.lcssa to i32
  store i32 %23, ptr %0, align 4, !tbaa !12
  br label %24

24:                                               ; preds = %5, %3, %22
  %.013 = phi i32 [ 0, %22 ], [ 1, %3 ], [ 1, %5 ]
  ret i32 %.013
}

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


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