; LLVM IR from mncoppola/rpef :: utilities_src/squashfs4.1/squashfs-tools (lzma_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"

; Function Attrs: nounwind uwtable
define dso_local i32 @lzma_compress(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i64, align 8
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  %20 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %20, ptr %14, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #3
  %21 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %21, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  store i64 5, ptr %16, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #3
  %22 = load i32, ptr %12, align 4, !tbaa !9
  %23 = sub nsw i32 %22, 13
  %24 = sext i32 %23 to i64
  store i64 %24, ptr %17, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  %25 = load ptr, ptr %14, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 13
  %27 = load ptr, ptr %15, align 8, !tbaa !5
  %28 = load i32, ptr %11, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = load ptr, ptr %14, align 8, !tbaa !5
  %31 = load i32, ptr %12, align 4, !tbaa !9
  %32 = call i32 @LzmaCompress(ptr noundef %26, ptr noundef %17, ptr noundef %27, i64 noundef %29, ptr noundef %30, ptr noundef %16, i32 noundef 5, i32 noundef %31, i32 noundef 3, i32 noundef 0, i32 noundef 2, i32 noundef 32, i32 noundef 1)
  store i32 %32, ptr %18, align 4, !tbaa !9
  %33 = load i32, ptr %18, align 4, !tbaa !9
  %34 = icmp eq i32 %33, 7
  br i1 %34, label %35, label %36

35:                                               ; preds = %6
  store i32 0, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %77

36:                                               ; preds = %6
  %37 = load i32, ptr %18, align 4, !tbaa !9
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %42

39:                                               ; preds = %36
  %40 = load i32, ptr %18, align 4, !tbaa !9
  %41 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 %40, ptr %41, align 4, !tbaa !9
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %77

42:                                               ; preds = %36
  %43 = load i32, ptr %11, align 4, !tbaa !9
  %44 = and i32 %43, 255
  %45 = trunc i32 %44 to i8
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i64 5
  store i8 %45, ptr %47, align 1, !tbaa !13
  %48 = load i32, ptr %11, align 4, !tbaa !9
  %49 = ashr i32 %48, 8
  %50 = and i32 %49, 255
  %51 = trunc i32 %50 to i8
  %52 = load ptr, ptr %14, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 6
  store i8 %51, ptr %53, align 1, !tbaa !13
  %54 = load i32, ptr %11, align 4, !tbaa !9
  %55 = ashr i32 %54, 16
  %56 = and i32 %55, 255
  %57 = trunc i32 %56 to i8
  %58 = load ptr, ptr %14, align 8, !tbaa !5
  %59 = getelementptr inbounds i8, ptr %58, i64 7
  store i8 %57, ptr %59, align 1, !tbaa !13
  %60 = load i32, ptr %11, align 4, !tbaa !9
  %61 = ashr i32 %60, 24
  %62 = and i32 %61, 255
  %63 = trunc i32 %62 to i8
  %64 = load ptr, ptr %14, align 8, !tbaa !5
  %65 = getelementptr inbounds i8, ptr %64, i64 8
  store i8 %63, ptr %65, align 1, !tbaa !13
  %66 = load ptr, ptr %14, align 8, !tbaa !5
  %67 = getelementptr inbounds i8, ptr %66, i64 9
  store i8 0, ptr %67, align 1, !tbaa !13
  %68 = load ptr, ptr %14, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i64 10
  store i8 0, ptr %69, align 1, !tbaa !13
  %70 = load ptr, ptr %14, align 8, !tbaa !5
  %71 = getelementptr inbounds i8, ptr %70, i64 11
  store i8 0, ptr %71, align 1, !tbaa !13
  %72 = load ptr, ptr %14, align 8, !tbaa !5
  %73 = getelementptr inbounds i8, ptr %72, i64 12
  store i8 0, ptr %73, align 1, !tbaa !13
  %74 = load i64, ptr %17, align 8, !tbaa !11
  %75 = add i64 %74, 13
  %76 = trunc i64 %75 to i32
  store i32 %76, ptr %7, align 4
  store i32 1, ptr %19, align 4
  br label %77

77:                                               ; preds = %42, %39, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  %78 = load i32, ptr %7, align 4
  ret i32 %78
}

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

declare i32 @LzmaCompress(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef) #2

; 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 = { "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !7, 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: nounwind uwtable
define dso_local i32 @lzma_compress(ptr nocapture noundef readnone %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  store i64 5, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #3
  %9 = add nsw i32 %4, -13
  %10 = sext i32 %9 to i64
  store i64 %10, ptr %8, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %1, i64 13
  %12 = sext i32 %3 to i64
  %13 = call i32 @LzmaCompress(ptr noundef nonnull %11, ptr noundef nonnull %8, ptr noundef %2, i64 noundef %12, ptr noundef %1, ptr noundef nonnull %7, i32 noundef 5, i32 noundef %4, i32 noundef 3, i32 noundef 0, i32 noundef 2, i32 noundef 32, i32 noundef 1) #3
  switch i32 %13, label %14 [
    i32 7, label %31
    i32 0, label %15
  ]

14:                                               ; preds = %6
  store i32 %13, ptr %5, align 4, !tbaa !9
  br label %31

15:                                               ; preds = %6
  %16 = trunc i32 %3 to i8
  %17 = getelementptr inbounds i8, ptr %1, i64 5
  store i8 %16, ptr %17, align 1, !tbaa !11
  %18 = lshr i32 %3, 8
  %19 = trunc i32 %18 to i8
  %20 = getelementptr inbounds i8, ptr %1, i64 6
  store i8 %19, ptr %20, align 1, !tbaa !11
  %21 = lshr i32 %3, 16
  %22 = trunc i32 %21 to i8
  %23 = getelementptr inbounds i8, ptr %1, i64 7
  store i8 %22, ptr %23, align 1, !tbaa !11
  %24 = lshr i32 %3, 24
  %25 = trunc nuw i32 %24 to i8
  %26 = getelementptr inbounds i8, ptr %1, i64 8
  store i8 %25, ptr %26, align 1, !tbaa !11
  %27 = getelementptr inbounds i8, ptr %1, i64 9
  store i32 0, ptr %27, align 1
  %28 = load i64, ptr %8, align 8, !tbaa !5
  %29 = trunc i64 %28 to i32
  %30 = add i32 %29, 13
  br label %31

31:                                               ; preds = %6, %15, %14
  %.0 = phi i32 [ -1, %14 ], [ %30, %15 ], [ 0, %6 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  ret i32 %.0
}

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

declare i32 @LzmaCompress(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 noundef, i32 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) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"long", !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}


; Effective O3 passes: GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass