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

@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

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

declare noalias ptr @fopen(ptr noundef, ptr 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: nounwind uwtable
declare dso_local i32 @mz_zip_writer_init(ptr noundef, i64 noundef) #2

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

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

20:                                               ; preds = %3
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %75

21:                                               ; preds = %3
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = call noalias ptr @fopen(ptr noundef %22, ptr noundef @.str.1)
  store ptr %23, ptr %8, align 8, !tbaa !5
  %24 = icmp eq ptr null, %23
  br i1 %24, label %25, label %28

25:                                               ; preds = %21
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call i32 @mz_zip_writer_end(ptr noundef %26)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %75

28:                                               ; preds = %21
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %30, i32 0, i32 6
  %32 = load ptr, ptr %31, align 8, !tbaa !14
  %33 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %32, i32 0, i32 3
  store ptr %29, ptr %33, align 8, !tbaa !15
  %34 = load i64, ptr %7, align 8, !tbaa !9
  %35 = icmp ne i64 %34, 0
  br i1 %35, label %36, label %74

36:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4096, ptr %11) #4
  call void @llvm.memset.p0.i64(ptr align 16 %11, i8 0, i64 4096, i1 false)
  br label %37

37:                                               ; preds = %67, %36
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %38 = load i64, ptr %7, align 8, !tbaa !9
  %39 = icmp ult i64 4096, %38
  br i1 %39, label %40, label %41

40:                                               ; preds = %37
  br label %43

41:                                               ; preds = %37
  %42 = load i64, ptr %7, align 8, !tbaa !9
  br label %43

43:                                               ; preds = %41, %40
  %44 = phi i64 [ 4096, %40 ], [ %42, %41 ]
  store i64 %44, ptr %12, align 8, !tbaa !19
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %45, i32 0, i32 5
  %47 = load ptr, ptr %46, align 8, !tbaa !11
  %48 = load i64, ptr %10, align 8, !tbaa !9
  %49 = getelementptr inbounds [4096 x i8], ptr %11, i64 0, i64 0
  %50 = load i64, ptr %12, align 8, !tbaa !19
  %51 = call i64 @mz_zip_file_write_func(ptr noundef %47, i64 noundef %48, ptr noundef %49, i64 noundef %50)
  %52 = load i64, ptr %12, align 8, !tbaa !19
  %53 = icmp ne i64 %51, %52
  br i1 %53, label %54, label %57

54:                                               ; preds = %43
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = call i32 @mz_zip_writer_end(ptr noundef %55)
  store i32 0, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %64

57:                                               ; preds = %43
  %58 = load i64, ptr %12, align 8, !tbaa !19
  %59 = load i64, ptr %10, align 8, !tbaa !9
  %60 = add i64 %59, %58
  store i64 %60, ptr %10, align 8, !tbaa !9
  %61 = load i64, ptr %12, align 8, !tbaa !19
  %62 = load i64, ptr %7, align 8, !tbaa !9
  %63 = sub i64 %62, %61
  store i64 %63, ptr %7, align 8, !tbaa !9
  store i32 0, ptr %9, align 4
  br label %64

64:                                               ; preds = %57, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %65 = load i32, ptr %9, align 4
  switch i32 %65, label %71 [
    i32 0, label %66
  ]

66:                                               ; preds = %64
  br label %67

67:                                               ; preds = %66
  %68 = load i64, ptr %7, align 8, !tbaa !9
  %69 = icmp ne i64 %68, 0
  br i1 %69, label %37, label %70, !llvm.loop !20

70:                                               ; preds = %67
  store i32 0, ptr %9, align 4
  br label %71

71:                                               ; preds = %70, %64
  call void @llvm.lifetime.end.p0(i64 4096, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %72 = load i32, ptr %9, align 4
  switch i32 %72, label %75 [
    i32 0, label %73
  ]

73:                                               ; preds = %71
  br label %74

74:                                               ; preds = %73, %28
  store i32 1, ptr %4, align 4
  store i32 1, ptr %9, align 4
  br label %75

75:                                               ; preds = %74, %71, %25, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %76 = load i32, ptr %4, align 4
  ret i32 %76
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @mz_zip_writer_end(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i64 @mz_zip_file_write_func(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { 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 = !{!"long long", !7, i64 0}
!11 = !{!12, !6, i64 32}
!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, !6, i64 40}
!15 = !{!16, !6, i64 96}
!16 = !{!"mz_zip_internal_state_tag", !17, i64 0, !17, i64 32, !17, i64 64, !6, i64 96, !18, i64 104, !18, i64 112}
!17 = !{!"", !6, i64 0, !18, i64 8, !18, i64 16, !13, i64 24}
!18 = !{!"long", !7, i64 0}
!19 = !{!18, !18, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"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"

@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1

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

; Function Attrs: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) 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: nounwind uwtable
declare dso_local i32 @mz_zip_writer_init(ptr noundef, i64 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @mz_zip_writer_init_file(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = alloca [4096 x i8], align 16
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %0, ptr %5, align 8, !tbaa !5
  %6 = tail call i32 @mz_zip_writer_init(ptr noundef %0, i64 noundef %2)
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %26, label %7

7:                                                ; preds = %3
  %8 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.1)
  %9 = icmp eq ptr %8, null
  br i1 %9, label %10, label %12

10:                                               ; preds = %7
  %11 = tail call i32 @mz_zip_writer_end(ptr noundef nonnull %0)
  br label %26

12:                                               ; preds = %7
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = load ptr, ptr %13, align 8, !tbaa !12
  %15 = getelementptr inbounds i8, ptr %14, i64 96
  store ptr %8, ptr %15, align 8, !tbaa !13
  %.not33 = icmp eq i64 %2, 0
  br i1 %.not33, label %26, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %4) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4096) %4, i8 0, i64 4096, i1 false)
  br label %17

17:                                               ; preds = %21, %16
  %.028 = phi i64 [ %2, %16 ], [ %23, %21 ]
  %.024 = phi i64 [ 0, %16 ], [ %22, %21 ]
  %18 = call i64 @llvm.umin.i64(i64 %.028, i64 4096)
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = call i64 @mz_zip_file_write_func(ptr noundef %19, i64 noundef %.024, ptr noundef nonnull %4, i64 noundef %18)
  %.not34 = icmp eq i64 %20, %18
  br i1 %.not34, label %21, label %.critedge

21:                                               ; preds = %17
  %22 = add i64 %.024, %18
  %23 = sub i64 %.028, %18
  %.not35 = icmp eq i64 %23, 0
  br i1 %.not35, label %24, label %17, !llvm.loop !17

24:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %4) #5
  br label %26

.critedge:                                        ; preds = %17
  %25 = call i32 @mz_zip_writer_end(ptr noundef nonnull %0)
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %4) #5
  br label %26

26:                                               ; preds = %12, %24, %.critedge, %3, %10
  %.2 = phi i32 [ 0, %10 ], [ 0, %3 ], [ 0, %.critedge ], [ 1, %24 ], [ 1, %12 ]
  ret i32 %.2
}

; Function Attrs: nounwind uwtable
declare dso_local i32 @mz_zip_writer_end(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i64 @mz_zip_file_write_func(ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nofree 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 #2 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !11, i64 32}
!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, !11, i64 40}
!13 = !{!14, !11, i64 96}
!14 = !{!"mz_zip_internal_state_tag", !15, i64 0, !15, i64 32, !15, i64 64, !11, i64 96, !16, i64 104, !16, i64 112}
!15 = !{!"", !11, i64 0, !16, i64 8, !16, i64 16, !10, i64 24}
!16 = !{!"long", !8, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}


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