; LLVM IR from aap/librw :: src/lodepng/lodepng.ll (Z21lodepng_zlib_compressPPhPmPKhmPK23LodePNGCompressSettings)

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL14lodepng_mallocm(i64 noundef) #1

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL12lodepng_freePv(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z21lodepng_zlib_compressPPhPmPKhmPK23LodePNGCompressSettings(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store i64 %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  store ptr null, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #3
  store i64 0, ptr %14, align 8, !tbaa !9
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = load i64, ptr %9, align 8, !tbaa !9
  %23 = load ptr, ptr %10, align 8, !tbaa !5
  %24 = call noundef i32 @_ZL7deflatePPhPmPKhmPK23LodePNGCompressSettings(ptr noundef %13, ptr noundef %14, ptr noundef %21, i64 noundef %22, ptr noundef %23)
  store i32 %24, ptr %12, align 4, !tbaa !11
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr null, ptr %25, align 8, !tbaa !5
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 0, ptr %26, align 8, !tbaa !9
  %27 = load i32, ptr %12, align 4, !tbaa !11
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %42, label %29

29:                                               ; preds = %5
  %30 = load i64, ptr %14, align 8, !tbaa !9
  %31 = add i64 %30, 6
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %31, ptr %32, align 8, !tbaa !9
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i64, ptr %33, align 8, !tbaa !9
  %35 = call noundef ptr @_ZL14lodepng_mallocm(i64 noundef %34)
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %35, ptr %36, align 8, !tbaa !5
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !5
  %39 = icmp ne ptr %38, null
  br i1 %39, label %41, label %40

40:                                               ; preds = %29
  store i32 83, ptr %12, align 4, !tbaa !11
  br label %41

41:                                               ; preds = %40, %29
  br label %42

42:                                               ; preds = %41, %5
  %43 = load i32, ptr %12, align 4, !tbaa !11
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %101, label %45

45:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #3
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = load i64, ptr %9, align 8, !tbaa !9
  %48 = trunc i64 %47 to i32
  %49 = call noundef i32 @_ZL7adler32PKhj(ptr noundef %46, i32 noundef %48)
  store i32 %49, ptr %15, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #3
  store i32 120, ptr %16, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  store i32 0, ptr %17, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  store i32 0, ptr %18, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #3
  %50 = load i32, ptr %16, align 4, !tbaa !11
  %51 = mul i32 256, %50
  %52 = load i32, ptr %18, align 4, !tbaa !11
  %53 = mul i32 %52, 32
  %54 = add i32 %51, %53
  %55 = load i32, ptr %17, align 4, !tbaa !11
  %56 = mul i32 %55, 64
  %57 = add i32 %54, %56
  store i32 %57, ptr %19, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #3
  %58 = load i32, ptr %19, align 4, !tbaa !11
  %59 = urem i32 %58, 31
  %60 = sub i32 31, %59
  store i32 %60, ptr %20, align 4, !tbaa !11
  %61 = load i32, ptr %20, align 4, !tbaa !11
  %62 = load i32, ptr %19, align 4, !tbaa !11
  %63 = add i32 %62, %61
  store i32 %63, ptr %19, align 4, !tbaa !11
  %64 = load i32, ptr %19, align 4, !tbaa !11
  %65 = lshr i32 %64, 8
  %66 = trunc i32 %65 to i8
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = getelementptr inbounds i8, ptr %68, i64 0
  store i8 %66, ptr %69, align 1, !tbaa !13
  %70 = load i32, ptr %19, align 4, !tbaa !11
  %71 = and i32 %70, 255
  %72 = trunc i32 %71 to i8
  %73 = load ptr, ptr %6, align 8, !tbaa !5
  %74 = load ptr, ptr %73, align 8, !tbaa !5
  %75 = getelementptr inbounds i8, ptr %74, i64 1
  store i8 %72, ptr %75, align 1, !tbaa !13
  store i64 0, ptr %11, align 8, !tbaa !9
  br label %76

76:                                               ; preds = %90, %45
  %77 = load i64, ptr %11, align 8, !tbaa !9
  %78 = load i64, ptr %14, align 8, !tbaa !9
  %79 = icmp ne i64 %77, %78
  br i1 %79, label %80, label %93

80:                                               ; preds = %76
  %81 = load ptr, ptr %13, align 8, !tbaa !5
  %82 = load i64, ptr %11, align 8, !tbaa !9
  %83 = getelementptr inbounds i8, ptr %81, i64 %82
  %84 = load i8, ptr %83, align 1, !tbaa !13
  %85 = load ptr, ptr %6, align 8, !tbaa !5
  %86 = load ptr, ptr %85, align 8, !tbaa !5
  %87 = load i64, ptr %11, align 8, !tbaa !9
  %88 = add i64 %87, 2
  %89 = getelementptr inbounds i8, ptr %86, i64 %88
  store i8 %84, ptr %89, align 1, !tbaa !13
  br label %90

90:                                               ; preds = %80
  %91 = load i64, ptr %11, align 8, !tbaa !9
  %92 = add i64 %91, 1
  store i64 %92, ptr %11, align 8, !tbaa !9
  br label %76, !llvm.loop !14

93:                                               ; preds = %76
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = load ptr, ptr %94, align 8, !tbaa !5
  %96 = load ptr, ptr %7, align 8, !tbaa !5
  %97 = load i64, ptr %96, align 8, !tbaa !9
  %98 = sub i64 %97, 4
  %99 = getelementptr inbounds i8, ptr %95, i64 %98
  %100 = load i32, ptr %15, align 4, !tbaa !11
  call void @_ZL19lodepng_set32bitIntPhj(ptr noundef %99, i32 noundef %100)
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  br label %101

101:                                              ; preds = %93, %42
  %102 = load ptr, ptr %13, align 8, !tbaa !5
  call void @_ZL12lodepng_freePv(ptr noundef %102)
  %103 = load i32, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret i32 %103
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL7deflatePPhPmPKhmPK23LodePNGCompressSettings(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) #2

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL7adler32PKhj(ptr noundef, i32 noundef) #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL19lodepng_set32bitIntPhj(ptr noundef, i32 noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { mustprogress 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 #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++ 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"}


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

; Function Attrs: mustprogress nounwind uwtable
declare hidden noundef ptr @_ZL14lodepng_mallocm(i64 noundef) local_unnamed_addr #1

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

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL12lodepng_freePv(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z21lodepng_zlib_compressPPhPmPKhmPK23LodePNGCompressSettings(ptr nocapture noundef %0, ptr nocapture noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #2 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  store ptr null, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  %8 = call noundef i32 @_ZL7deflatePPhPmPKhmPK23LodePNGCompressSettings(ptr noundef nonnull %6, ptr noundef nonnull %7, ptr noundef %2, i64 noundef %3, ptr noundef %4)
  store ptr null, ptr %0, align 8, !tbaa !5
  store i64 0, ptr %1, align 8, !tbaa !9
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %9, label %.thread

9:                                                ; preds = %5
  %10 = load i64, ptr %7, align 8, !tbaa !9
  %11 = add i64 %10, 6
  store i64 %11, ptr %1, align 8, !tbaa !9
  %12 = call noundef ptr @_ZL14lodepng_mallocm(i64 noundef %11)
  store ptr %12, ptr %0, align 8, !tbaa !5
  %.not33 = icmp eq ptr %12, null
  br i1 %.not33, label %.thread, label %13

13:                                               ; preds = %9
  %14 = trunc i64 %3 to i32
  %15 = call noundef i32 @_ZL7adler32PKhj(ptr noundef %2, i32 noundef %14)
  %16 = load ptr, ptr %0, align 8, !tbaa !5
  store i8 120, ptr %16, align 1, !tbaa !11
  %17 = load ptr, ptr %0, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 1
  store i8 1, ptr %18, align 1, !tbaa !11
  %19 = load i64, ptr %7, align 8, !tbaa !9
  %.not3539 = icmp eq i64 %19, 0
  br i1 %.not3539, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %13, %.lr.ph
  %.040 = phi i64 [ %26, %.lr.ph ], [ 0, %13 ]
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds i8, ptr %20, i64 %.040
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = load ptr, ptr %0, align 8, !tbaa !5
  %24 = getelementptr i8, ptr %23, i64 %.040
  %25 = getelementptr i8, ptr %24, i64 2
  store i8 %22, ptr %25, align 1, !tbaa !11
  %26 = add i64 %.040, 1
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %.not35 = icmp eq i64 %26, %27
  br i1 %.not35, label %._crit_edge, label %.lr.ph, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph, %13
  %28 = load ptr, ptr %0, align 8, !tbaa !5
  %29 = load i64, ptr %1, align 8, !tbaa !9
  %30 = getelementptr i8, ptr %28, i64 %29
  %31 = getelementptr i8, ptr %30, i64 -4
  call void @_ZL19lodepng_set32bitIntPhj(ptr noundef %31, i32 noundef %15)
  br label %.thread

.thread:                                          ; preds = %9, %5, %._crit_edge
  %.03138 = phi i32 [ 0, %._crit_edge ], [ %8, %5 ], [ 83, %9 ]
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZL12lodepng_freePv(ptr noundef %32)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret i32 %.03138
}

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL7deflatePPhPmPKhmPK23LodePNGCompressSettings(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare hidden noundef i32 @_ZL7adler32PKhj(ptr noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare hidden void @_ZL19lodepng_set32bitIntPhj(ptr noundef, i32 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 #2 = { mustprogress 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass