; LLVM IR from fhanau/Efficient-Compression-Tool :: src/miniz (miniz)

; 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.mz_zip_archive_tag = type { i64, i64, i32, i32, i32, ptr, ptr }
%struct.mz_zip_internal_state_tag = type { %struct.mz_zip_array, %struct.mz_zip_array, %struct.mz_zip_array, ptr, i64, i64 }
%struct.mz_zip_array = type { ptr, i64, i64, i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @mz_zip_writer_init(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i64 %1, ptr %5, align 8, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %8, label %18

8:                                                ; preds = %2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %9, i32 0, i32 6
  %11 = load ptr, ptr %10, align 8, !tbaa !11
  %12 = icmp ne ptr %11, null
  br i1 %12, label %18, label %13

13:                                               ; preds = %8
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %14, i32 0, i32 3
  %16 = load i32, ptr %15, align 4, !tbaa !14
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %13, %8, %2
  store i32 0, ptr %3, align 4
  br label %70

19:                                               ; preds = %13
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %20, i32 0, i32 4
  %22 = load i32, ptr %21, align 8, !tbaa !15
  %23 = icmp ne i32 %22, 0
  br i1 %23, label %24, label %36

24:                                               ; preds = %19
  %25 = load ptr, ptr %4, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %25, i32 0, i32 4
  %27 = load i32, ptr %26, align 8, !tbaa !15
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %28, i32 0, i32 4
  %30 = load i32, ptr %29, align 8, !tbaa !15
  %31 = sub i32 %30, 1
  %32 = and i32 %27, %31
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %34, label %35

34:                                               ; preds = %24
  store i32 0, ptr %3, align 4
  br label %70

35:                                               ; preds = %24
  br label %36

36:                                               ; preds = %35, %19
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %37, i32 0, i32 3
  store i32 2, ptr %38, align 4, !tbaa !14
  %39 = load i64, ptr %5, align 8, !tbaa !9
  %40 = load ptr, ptr %4, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %40, i32 0, i32 0
  store i64 %39, ptr %41, align 8, !tbaa !16
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %42, i32 0, i32 1
  store i64 0, ptr %43, align 8, !tbaa !17
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %44, i32 0, i32 2
  store i32 0, ptr %45, align 8, !tbaa !18
  %46 = call noalias ptr @malloc(i64 noundef 120) #3
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %47, i32 0, i32 6
  store ptr %46, ptr %48, align 8, !tbaa !11
  %49 = icmp eq ptr null, %46
  br i1 %49, label %50, label %51

50:                                               ; preds = %36
  store i32 0, ptr %3, align 4
  br label %70

51:                                               ; preds = %36
  %52 = load ptr, ptr %4, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %52, i32 0, i32 6
  %54 = load ptr, ptr %53, align 8, !tbaa !11
  call void @llvm.memset.p0.i64(ptr align 8 %54, i8 0, i64 120, i1 false)
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %55, i32 0, i32 6
  %57 = load ptr, ptr %56, align 8, !tbaa !11
  %58 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %57, i32 0, i32 0
  %59 = getelementptr inbounds %struct.mz_zip_array, ptr %58, i32 0, i32 3
  store i32 1, ptr %59, align 8, !tbaa !19
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %60, i32 0, i32 6
  %62 = load ptr, ptr %61, align 8, !tbaa !11
  %63 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %62, i32 0, i32 1
  %64 = getelementptr inbounds %struct.mz_zip_array, ptr %63, i32 0, i32 3
  store i32 4, ptr %64, align 8, !tbaa !23
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %65, i32 0, i32 6
  %67 = load ptr, ptr %66, align 8, !tbaa !11
  %68 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %67, i32 0, i32 2
  %69 = getelementptr inbounds %struct.mz_zip_array, ptr %68, i32 0, i32 3
  store i32 4, ptr %69, align 8, !tbaa !24
  store i32 1, ptr %3, align 4
  br label %70

70:                                               ; preds = %51, %50, %34, %18
  %71 = load i32, ptr %3, align 4
  ret i32 %71
}

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #1

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

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 = { nounwind allocsize(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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { nounwind allocsize(0) }

!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 = !{!"long long", !7, i64 0}
!11 = !{!12, !6, i64 40}
!12 = !{!"mz_zip_archive_tag", !10, i64 0, !10, i64 8, !13, i64 16, !13, i64 20, !13, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 20}
!15 = !{!12, !13, i64 24}
!16 = !{!12, !10, i64 0}
!17 = !{!12, !10, i64 8}
!18 = !{!12, !13, i64 16}
!19 = !{!20, !13, i64 24}
!20 = !{!"mz_zip_internal_state_tag", !21, i64 0, !21, i64 32, !21, i64 64, !6, i64 96, !22, i64 104, !22, i64 112}
!21 = !{!"", !6, i64 0, !22, i64 8, !22, i64 16, !13, i64 24}
!22 = !{!"long", !7, i64 0}
!23 = !{!20, !13, i64 56}
!24 = !{!20, !13, i64 88}


; 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 nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: readwrite) uwtable
define dso_local range(i32 0, 2) i32 @mz_zip_writer_init(ptr noundef %0, i64 noundef %1) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %21, label %3

3:                                                ; preds = %2
  %4 = getelementptr inbounds i8, ptr %0, i64 40
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %.not19 = icmp eq ptr %5, null
  br i1 %.not19, label %6, label %21

6:                                                ; preds = %3
  %7 = getelementptr inbounds i8, ptr %0, i64 20
  %8 = load i32, ptr %7, align 4, !tbaa !12
  %.not20 = icmp eq i32 %8, 0
  br i1 %.not20, label %9, label %21

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = tail call range(i32 0, 33) i32 @llvm.ctpop.i32(i32 %11)
  %.not22 = icmp ult i32 %12, 2
  br i1 %.not22, label %13, label %21

13:                                               ; preds = %9
  store i32 2, ptr %7, align 4, !tbaa !12
  store i64 %1, ptr %0, align 8, !tbaa !14
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 0, ptr %14, align 8, !tbaa !15
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 0, ptr %15, align 8, !tbaa !16
  %calloc = tail call dereferenceable_or_null(120) ptr @calloc(i64 1, i64 120)
  store ptr %calloc, ptr %4, align 8, !tbaa !5
  %16 = icmp eq ptr %calloc, null
  br i1 %16, label %21, label %17

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %calloc, i64 24
  store i32 1, ptr %18, align 8, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %calloc, i64 56
  store i32 4, ptr %19, align 8, !tbaa !21
  %20 = getelementptr inbounds i8, ptr %calloc, i64 88
  store i32 4, ptr %20, align 8, !tbaa !22
  br label %21

21:                                               ; preds = %13, %9, %2, %3, %6, %17
  %.0 = phi i32 [ 1, %17 ], [ 0, %6 ], [ 0, %3 ], [ 0, %2 ], [ 0, %9 ], [ 0, %13 ]
  ret i32 %.0
}

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

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nofree nounwind willreturn memory(write, argmem: readwrite, inaccessiblemem: 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) }
attributes #2 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }

!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, !11, i64 40}
!6 = !{!"mz_zip_archive_tag", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !11, i64 32, !11, i64 40}
!7 = !{!"long long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !10, i64 20}
!13 = !{!6, !10, i64 24}
!14 = !{!6, !7, i64 0}
!15 = !{!6, !7, i64 8}
!16 = !{!6, !10, i64 16}
!17 = !{!18, !10, i64 24}
!18 = !{!"mz_zip_internal_state_tag", !19, i64 0, !19, i64 32, !19, i64 64, !11, i64 96, !20, i64 104, !20, i64 112}
!19 = !{!"", !11, i64 0, !20, i64 8, !20, i64 16, !10, i64 24}
!20 = !{!"long", !8, i64 0}
!21 = !{!18, !10, i64 56}
!22 = !{!18, !10, i64 88}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass