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

; 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, 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
  %10 = 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
  %11 = load i32, ptr %7, align 4, !tbaa !9
  %12 = icmp slt i32 %11, 5
  br i1 %12, label %13, label %14

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

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

21:                                               ; preds = %14
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %93

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

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

29:                                               ; preds = %25
  br label %30

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

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

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

46:                                               ; preds = %42
  br label %47

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

56:                                               ; preds = %42
  %57 = load i8, ptr %8, align 1, !tbaa !11
  %58 = zext i8 %57 to i32
  %59 = load ptr, ptr %5, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct._CLzmaProperties, ptr %59, i32 0, i32 0
  store i32 %58, ptr %60, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct._CLzmaProperties, ptr %61, i32 0, i32 3
  store i32 0, ptr %62, align 4, !tbaa !19
  store i32 0, ptr %10, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %81, %56
  %64 = load i32, ptr %10, align 4, !tbaa !9
  %65 = icmp slt i32 %64, 4
  br i1 %65, label %66, label %84

66:                                               ; preds = %63
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load i32, ptr %10, align 4, !tbaa !9
  %69 = add nsw i32 1, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds i8, ptr %67, i64 %70
  %72 = load i8, ptr %71, align 1, !tbaa !11
  %73 = zext i8 %72 to i32
  %74 = load i32, ptr %10, align 4, !tbaa !9
  %75 = mul nsw i32 %74, 8
  %76 = shl i32 %73, %75
  %77 = load ptr, ptr %5, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct._CLzmaProperties, ptr %77, i32 0, i32 3
  %79 = load i32, ptr %78, align 4, !tbaa !19
  %80 = add i32 %79, %76
  store i32 %80, ptr %78, align 4, !tbaa !19
  br label %81

81:                                               ; preds = %66
  %82 = load i32, ptr %10, align 4, !tbaa !9
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %10, align 4, !tbaa !9
  br label %63, !llvm.loop !20

84:                                               ; preds = %63
  %85 = load ptr, ptr %5, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct._CLzmaProperties, ptr %85, i32 0, i32 3
  %87 = load i32, ptr %86, align 4, !tbaa !19
  %88 = icmp eq i32 %87, 0
  br i1 %88, label %89, label %92

89:                                               ; preds = %84
  %90 = load ptr, ptr %5, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct._CLzmaProperties, ptr %90, i32 0, i32 3
  store i32 1, ptr %91, align 4, !tbaa !19
  br label %92

92:                                               ; preds = %89, %84
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %93

93:                                               ; preds = %92, %21, %13
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  %94 = load i32, ptr %4, align 4
  ret i32 %94
}

; 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, !10, i64 12}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!13, !10, i64 4}
!17 = distinct !{!17, !15}
!18 = !{!13, !10, i64 0}
!19 = !{!13, !10, i64 12}
!20 = distinct !{!20, !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 @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 %43, label %5

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

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

.lr.ph:                                           ; preds = %8
  %11 = add i8 %.fr42, -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 ]
  %.022.lcssa = phi i8 [ %13, %.lr.ph ], [ %.fr42, %8 ]
  store i32 %storemerge, ptr %9, align 4, !tbaa !8
  %16 = getelementptr inbounds i8, ptr %0, i64 4
  %17 = icmp ugt i8 %.022.lcssa, 8
  br i1 %17, label %.lr.ph30, label %22

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

22:                                               ; preds = %.lr.ph30, %15
  %storemerge44 = phi i32 [ %21, %.lr.ph30 ], [ 0, %15 ]
  %.1.lcssa = phi i8 [ %20, %.lr.ph30 ], [ %.022.lcssa, %15 ]
  store i32 %storemerge44, ptr %16, align 4, !tbaa !11
  %23 = zext nneg i8 %.1.lcssa to i32
  store i32 %23, ptr %0, align 4, !tbaa !12
  %24 = getelementptr inbounds i8, ptr %0, i64 12
  store i32 0, ptr %24, align 4, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %1, i64 1
  %26 = load i8, ptr %25, align 1, !tbaa !5
  %27 = zext i8 %26 to i32
  store i32 %27, ptr %24, align 4, !tbaa !13
  %28 = getelementptr inbounds i8, ptr %1, i64 2
  %29 = load i8, ptr %28, align 1, !tbaa !5
  %30 = zext i8 %29 to i32
  %31 = shl nuw nsw i32 %30, 8
  %32 = or disjoint i32 %31, %27
  store i32 %32, ptr %24, align 4, !tbaa !13
  %33 = getelementptr inbounds i8, ptr %1, i64 3
  %34 = load i8, ptr %33, align 1, !tbaa !5
  %35 = zext i8 %34 to i32
  %36 = shl nuw nsw i32 %35, 16
  %37 = or disjoint i32 %36, %32
  store i32 %37, ptr %24, align 4, !tbaa !13
  %38 = getelementptr inbounds i8, ptr %1, i64 4
  %39 = load i8, ptr %38, align 1, !tbaa !5
  %40 = zext i8 %39 to i32
  %41 = shl nuw i32 %40, 24
  %42 = or disjoint i32 %41, %37
  %spec.store.select = tail call i32 @llvm.umax.i32(i32 %42, i32 1)
  store i32 %spec.store.select, ptr %24, align 4
  br label %43

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #1

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" }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, i64 12}
!10 = !{!"int", !6, i64 0}
!11 = !{!9, !10, i64 4}
!12 = !{!9, !10, i64 0}
!13 = !{!9, !10, i64 12}


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