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

declare i32 @fclose(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: alwaysinline nounwind uwtable
declare hidden void @mz_zip_array_clear(ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

; Function Attrs: nounwind uwtable
define dso_local i32 @mz_zip_writer_end(ptr noundef %0) #4 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  store i32 1, ptr %5, align 4, !tbaa !9
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %24

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

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

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

24:                                               ; preds = %19, %9, %1
  store i32 0, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %53

25:                                               ; preds = %19, %14
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %26, i32 0, i32 6
  %28 = load ptr, ptr %27, align 8, !tbaa !11
  store ptr %28, ptr %4, align 8, !tbaa !5
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %29, i32 0, i32 6
  store ptr null, ptr %30, align 8, !tbaa !11
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %31, i32 0, i32 0
  call void @mz_zip_array_clear(ptr noundef %32)
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %33, i32 0, i32 1
  call void @mz_zip_array_clear(ptr noundef %34)
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %35, i32 0, i32 2
  call void @mz_zip_array_clear(ptr noundef %36)
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %37, i32 0, i32 3
  %39 = load ptr, ptr %38, align 8, !tbaa !15
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %48

41:                                               ; preds = %25
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %42, i32 0, i32 3
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = call i32 @fclose(ptr noundef %44)
  %46 = load ptr, ptr %4, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %46, i32 0, i32 3
  store ptr null, ptr %47, align 8, !tbaa !15
  br label %48

48:                                               ; preds = %41, %25
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  call void @free(ptr noundef %49) #5
  %50 = load ptr, ptr %3, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %50, i32 0, i32 3
  store i32 0, ptr %51, align 4, !tbaa !14
  %52 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %52, ptr %2, align 4
  store i32 1, ptr %6, align 4
  br label %53

53:                                               ; preds = %48, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #5
  %54 = load i32, ptr %2, align 4
  ret i32 %54
}

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 = { alwaysinline 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 = { 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 #4 = { 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 #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 = !{!12, !6, i64 40}
!12 = !{!"mz_zip_archive_tag", !13, i64 0, !13, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !6, i64 32, !6, i64 40}
!13 = !{!"long long", !7, i64 0}
!14 = !{!12, !10, i64 20}
!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, !10, i64 24}
!18 = !{!"long", !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: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #0

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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @mz_zip_writer_end(ptr noundef %0) local_unnamed_addr #3 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %17, label %2

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

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 20
  %7 = load i32, ptr %6, align 4, !tbaa !12
  %8 = and i32 %7, -2
  %switch = icmp eq i32 %8, 2
  br i1 %switch, label %9, label %17

9:                                                ; preds = %5
  store ptr null, ptr %3, align 8, !tbaa !5
  tail call void @mz_zip_array_clear(ptr noundef nonnull %4)
  %10 = getelementptr inbounds i8, ptr %4, i64 32
  tail call void @mz_zip_array_clear(ptr noundef nonnull %10)
  %11 = getelementptr inbounds i8, ptr %4, i64 64
  tail call void @mz_zip_array_clear(ptr noundef nonnull %11)
  %12 = getelementptr inbounds i8, ptr %4, i64 96
  %13 = load ptr, ptr %12, align 8, !tbaa !13
  %.not21 = icmp eq ptr %13, null
  br i1 %.not21, label %16, label %14

14:                                               ; preds = %9
  %15 = tail call i32 @fclose(ptr noundef nonnull %13)
  br label %16

16:                                               ; preds = %14, %9
  tail call void @free(ptr noundef nonnull %4) #4
  store i32 0, ptr %6, align 4, !tbaa !12
  br label %17

17:                                               ; preds = %5, %1, %2, %16
  %.0 = phi i32 [ 1, %16 ], [ 0, %5 ], [ 0, %2 ], [ 0, %1 ]
  ret i32 %.0
}

attributes #0 = { 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 #1 = { alwaysinline 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { 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 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 = !{!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}


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