; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.1/squashfs-tools (xz_wrapper)

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

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

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

; Function Attrs: nounwind
declare void @lzma_end(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @lzma_code(ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @lzma_uncompress(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) #3 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca %struct.lzma_stream, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca [13 x i8], align 1
  %16 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 136, ptr %12) #5
  call void @llvm.memset.p0.i64(ptr align 8 %12, i8 0, i64 136, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #5
  store i32 0, ptr %13, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 13, ptr %15) #5
  %17 = call i32 @lzma_alone_decoder(ptr noundef %12, i64 noundef 33554432) #5
  store i32 %17, ptr %14, align 4, !tbaa !9
  %18 = load i32, ptr %14, align 4, !tbaa !9
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %5
  call void @lzma_end(ptr noundef %12) #5
  br label %87

21:                                               ; preds = %5
  %22 = getelementptr inbounds [13 x i8], ptr %15, i64 0, i64 0
  %23 = load ptr, ptr %8, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %22, ptr align 1 %23, i64 13, i1 false)
  %24 = getelementptr inbounds [13 x i8], ptr %15, i64 0, i64 5
  %25 = load i8, ptr %24, align 1, !tbaa !11
  %26 = zext i8 %25 to i32
  %27 = getelementptr inbounds [13 x i8], ptr %15, i64 0, i64 6
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = zext i8 %28 to i32
  %30 = shl i32 %29, 8
  %31 = or i32 %26, %30
  %32 = getelementptr inbounds [13 x i8], ptr %15, i64 0, i64 7
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = zext i8 %33 to i32
  %35 = shl i32 %34, 16
  %36 = or i32 %31, %35
  %37 = getelementptr inbounds [13 x i8], ptr %15, i64 0, i64 8
  %38 = load i8, ptr %37, align 1, !tbaa !11
  %39 = zext i8 %38 to i32
  %40 = shl i32 %39, 24
  %41 = or i32 %36, %40
  store i32 %41, ptr %13, align 4, !tbaa !9
  %42 = getelementptr inbounds [13 x i8], ptr %15, i64 0, i64 0
  %43 = getelementptr inbounds i8, ptr %42, i64 5
  call void @llvm.memset.p0.i64(ptr align 1 %43, i8 -1, i64 8, i1 false)
  %44 = load ptr, ptr %7, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.lzma_stream, ptr %12, i32 0, i32 3
  store ptr %44, ptr %45, align 8, !tbaa !12
  %46 = load i32, ptr %10, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds %struct.lzma_stream, ptr %12, i32 0, i32 4
  store i64 %47, ptr %48, align 8, !tbaa !15
  %49 = getelementptr inbounds [13 x i8], ptr %15, i64 0, i64 0
  %50 = getelementptr inbounds %struct.lzma_stream, ptr %12, i32 0, i32 0
  store ptr %49, ptr %50, align 8, !tbaa !16
  %51 = getelementptr inbounds %struct.lzma_stream, ptr %12, i32 0, i32 1
  store i64 13, ptr %51, align 8, !tbaa !17
  %52 = call i32 @lzma_code(ptr noundef %12, i32 noundef 0) #5
  store i32 %52, ptr %14, align 4, !tbaa !9
  %53 = load i32, ptr %14, align 4, !tbaa !9
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %59, label %55

55:                                               ; preds = %21
  %56 = getelementptr inbounds %struct.lzma_stream, ptr %12, i32 0, i32 1
  %57 = load i64, ptr %56, align 8, !tbaa !17
  %58 = icmp ne i64 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %55, %21
  call void @lzma_end(ptr noundef %12) #5
  br label %87

60:                                               ; preds = %55
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i64 13
  %63 = getelementptr inbounds %struct.lzma_stream, ptr %12, i32 0, i32 0
  store ptr %62, ptr %63, align 8, !tbaa !16
  %64 = load i32, ptr %9, align 4, !tbaa !9
  %65 = sub nsw i32 %64, 13
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds %struct.lzma_stream, ptr %12, i32 0, i32 1
  store i64 %66, ptr %67, align 8, !tbaa !17
  %68 = call i32 @lzma_code(ptr noundef %12, i32 noundef 3) #5
  store i32 %68, ptr %14, align 4, !tbaa !9
  call void @lzma_end(ptr noundef %12) #5
  %69 = load i32, ptr %14, align 4, !tbaa !9
  %70 = icmp eq i32 %69, 1
  br i1 %70, label %84, label %71

71:                                               ; preds = %60
  %72 = load i32, ptr %14, align 4, !tbaa !9
  %73 = icmp eq i32 %72, 0
  br i1 %73, label %74, label %86

74:                                               ; preds = %71
  %75 = getelementptr inbounds %struct.lzma_stream, ptr %12, i32 0, i32 5
  %76 = load i64, ptr %75, align 8, !tbaa !18
  %77 = load i32, ptr %13, align 4, !tbaa !9
  %78 = sext i32 %77 to i64
  %79 = icmp uge i64 %76, %78
  br i1 %79, label %80, label %86

80:                                               ; preds = %74
  %81 = getelementptr inbounds %struct.lzma_stream, ptr %12, i32 0, i32 1
  %82 = load i64, ptr %81, align 8, !tbaa !17
  %83 = icmp eq i64 %82, 0
  br i1 %83, label %84, label %86

84:                                               ; preds = %80, %60
  %85 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %85, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %90

86:                                               ; preds = %80, %74, %71
  br label %87

87:                                               ; preds = %86, %59, %20
  %88 = load i32, ptr %14, align 4, !tbaa !9
  %89 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 %88, ptr %89, align 4, !tbaa !9
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %16, align 4
  br label %90

90:                                               ; preds = %87, %84
  call void @llvm.lifetime.end.p0(i64 13, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 136, ptr %12) #5
  %91 = load i32, ptr %6, align 4
  ret i32 %91
}

; Function Attrs: nounwind
declare i32 @lzma_alone_decoder(ptr noundef, i64 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nounwind "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 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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, !6, i64 24}
!13 = !{!"", !6, i64 0, !14, i64 8, !14, i64 16, !6, i64 24, !14, i64 32, !14, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !14, i64 96, !14, i64 104, !14, i64 112, !14, i64 120, !10, i64 128, !10, i64 132}
!14 = !{!"long", !7, i64 0}
!15 = !{!13, !14, i64 32}
!16 = !{!13, !6, i64 0}
!17 = !{!13, !14, i64 8}
!18 = !{!13, !14, i64 40}


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

%struct.lzma_stream = type { ptr, i64, i64, ptr, i64, i64, ptr, ptr, ptr, ptr, ptr, ptr, i64, i64, i64, i64, i32, i32 }

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #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

; Function Attrs: nounwind
declare void @lzma_end(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind
declare i32 @lzma_code(ptr noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local i32 @lzma_uncompress(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #3 {
  %6 = alloca %struct.lzma_stream, align 8
  %7 = alloca [13 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 136, ptr nonnull %6) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(136) %6, i8 0, i64 136, i1 false)
  call void @llvm.lifetime.start.p0(i64 13, ptr nonnull %7) #5
  %8 = call i32 @lzma_alone_decoder(ptr noundef nonnull %6, i64 noundef 33554432) #5
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %.sink.split

9:                                                ; preds = %5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(13) %7, ptr noundef nonnull align 1 dereferenceable(13) %1, i64 13, i1 false)
  %10 = getelementptr inbounds i8, ptr %7, i64 5
  %11 = load i16, ptr %10, align 1
  %12 = zext i16 %11 to i32
  %13 = getelementptr inbounds i8, ptr %7, i64 7
  %14 = load i8, ptr %13, align 1, !tbaa !5
  %15 = zext i8 %14 to i32
  %16 = shl nuw nsw i32 %15, 16
  %17 = or disjoint i32 %16, %12
  %18 = getelementptr inbounds i8, ptr %7, i64 8
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = zext i8 %19 to i32
  %21 = shl nuw i32 %20, 24
  %22 = or disjoint i32 %17, %21
  store i64 -1, ptr %10, align 1
  %23 = getelementptr inbounds i8, ptr %6, i64 24
  store ptr %0, ptr %23, align 8, !tbaa !8
  %24 = sext i32 %3 to i64
  %25 = getelementptr inbounds i8, ptr %6, i64 32
  store i64 %24, ptr %25, align 8, !tbaa !13
  store ptr %7, ptr %6, align 8, !tbaa !14
  %26 = getelementptr inbounds i8, ptr %6, i64 8
  store i64 13, ptr %26, align 8, !tbaa !15
  %27 = call i32 @lzma_code(ptr noundef nonnull %6, i32 noundef 0) #5
  %28 = icmp ne i32 %27, 0
  %29 = load i64, ptr %26, align 8
  %30 = icmp ne i64 %29, 0
  %or.cond = select i1 %28, i1 true, i1 %30
  br i1 %or.cond, label %.sink.split, label %31

31:                                               ; preds = %9
  %32 = getelementptr inbounds i8, ptr %1, i64 13
  store ptr %32, ptr %6, align 8, !tbaa !14
  %33 = add nsw i32 %2, -13
  %34 = sext i32 %33 to i64
  store i64 %34, ptr %26, align 8, !tbaa !15
  %35 = call i32 @lzma_code(ptr noundef nonnull %6, i32 noundef 3) #5
  call void @lzma_end(ptr noundef nonnull %6) #5
  switch i32 %35, label %43 [
    i32 1, label %44
    i32 0, label %36
  ]

36:                                               ; preds = %31
  %37 = getelementptr inbounds i8, ptr %6, i64 40
  %38 = load i64, ptr %37, align 8, !tbaa !16
  %39 = sext i32 %22 to i64
  %40 = icmp uge i64 %38, %39
  %41 = load i64, ptr %26, align 8
  %42 = icmp eq i64 %41, 0
  %or.cond5 = select i1 %40, i1 %42, i1 false
  br i1 %or.cond5, label %44, label %43

.sink.split:                                      ; preds = %9, %5
  %.0.ph = phi i32 [ %8, %5 ], [ %27, %9 ]
  call void @lzma_end(ptr noundef nonnull %6) #5
  br label %43

43:                                               ; preds = %.sink.split, %31, %36
  %.0 = phi i32 [ 0, %36 ], [ %35, %31 ], [ %.0.ph, %.sink.split ]
  store i32 %.0, ptr %4, align 4, !tbaa !17
  br label %44

44:                                               ; preds = %36, %31, %43
  %.018 = phi i32 [ -1, %43 ], [ %22, %31 ], [ %22, %36 ]
  call void @llvm.lifetime.end.p0(i64 13, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 136, ptr nonnull %6) #5
  ret i32 %.018
}

; Function Attrs: nounwind
declare i32 @lzma_alone_decoder(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { nounwind "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 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 24}
!9 = !{!"", !10, i64 0, !11, i64 8, !11, i64 16, !10, i64 24, !11, i64 32, !11, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !11, i64 96, !11, i64 104, !11, i64 112, !11, i64 120, !12, i64 128, !12, i64 132}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"long", !6, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = !{!9, !11, i64 32}
!14 = !{!9, !10, i64 0}
!15 = !{!9, !11, i64 8}
!16 = !{!9, !11, i64 40}
!17 = !{!12, !12, i64 0}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass