; 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.2 = external hidden unnamed_addr constant [4 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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mz_zip_reader_end(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
define dso_local i32 @mz_zip_writer_init_from_reader(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %20

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

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

20:                                               ; preds = %15, %10, %2
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %70

21:                                               ; preds = %15
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 8, !tbaa !14
  %25 = icmp eq i32 %24, 65535
  br i1 %25, label %33, label %26

26:                                               ; preds = %21
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %27, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !15
  %30 = add i64 %29, 46
  %31 = add i64 %30, 30
  %32 = icmp ugt i64 %31, 4294967295
  br i1 %32, label %33, label %34

33:                                               ; preds = %26, %21
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %70

34:                                               ; preds = %26
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %35, i32 0, i32 6
  %37 = load ptr, ptr %36, align 8, !tbaa !9
  store ptr %37, ptr %6, align 8, !tbaa !5
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %38, i32 0, i32 5
  %40 = load ptr, ptr %39, align 8, !tbaa !16
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = icmp ne ptr %40, %41
  br i1 %42, label %43, label %44

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

44:                                               ; preds = %34
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %48, label %47

47:                                               ; preds = %44
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %70

48:                                               ; preds = %44
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !17
  %53 = call ptr @freopen(ptr noundef %49, ptr noundef @.str.2, ptr noundef %52)
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %54, i32 0, i32 3
  store ptr %53, ptr %55, align 8, !tbaa !17
  %56 = icmp eq ptr null, %53
  br i1 %56, label %57, label %60

57:                                               ; preds = %48
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = call i32 @mz_zip_reader_end(ptr noundef %58)
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %70

60:                                               ; preds = %48
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %61, i32 0, i32 1
  %63 = load i64, ptr %62, align 8, !tbaa !21
  %64 = load ptr, ptr %4, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %64, i32 0, i32 0
  store i64 %63, ptr %65, align 8, !tbaa !15
  %66 = load ptr, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %66, i32 0, i32 3
  store i32 2, ptr %67, align 4, !tbaa !13
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.mz_zip_archive_tag, ptr %68, i32 0, i32 1
  store i64 0, ptr %69, align 8, !tbaa !21
  store i32 1, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %70

70:                                               ; preds = %60, %57, %47, %43, %33, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %71 = load i32, ptr %3, align 4
  ret i32 %71
}

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) #2

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


; 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.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

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

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

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %0, i64 16
  %11 = load i32, ptr %10, align 8, !tbaa !13
  %12 = icmp eq i32 %11, 65535
  br i1 %12, label %30, label %13

13:                                               ; preds = %9
  %14 = load i64, ptr %0, align 8, !tbaa !14
  %15 = add i64 %14, -4294967220
  %16 = icmp ult i64 %15, -4294967296
  br i1 %16, label %30, label %17

17:                                               ; preds = %13
  %18 = getelementptr inbounds i8, ptr %0, i64 32
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %.not22 = icmp ne ptr %19, %0
  %.not23 = icmp eq ptr %1, null
  %or.cond = or i1 %.not23, %.not22
  br i1 %or.cond, label %30, label %20

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %5, i64 96
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = tail call ptr @freopen(ptr noundef nonnull %1, ptr noundef nonnull @.str.2, ptr noundef %22) #2
  store ptr %23, ptr %21, align 8, !tbaa !16
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %27

25:                                               ; preds = %20
  %26 = tail call i32 @mz_zip_reader_end(ptr noundef nonnull %0)
  br label %30

27:                                               ; preds = %20
  %28 = getelementptr inbounds i8, ptr %0, i64 8
  %29 = load i64, ptr %28, align 8, !tbaa !20
  store i64 %29, ptr %0, align 8, !tbaa !14
  store i32 2, ptr %7, align 4, !tbaa !12
  store i64 0, ptr %28, align 8, !tbaa !20
  br label %30

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

declare ptr @freopen(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #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 = { "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 }

!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 16}
!14 = !{!6, !7, i64 0}
!15 = !{!6, !11, i64 32}
!16 = !{!17, !11, i64 96}
!17 = !{!"mz_zip_internal_state_tag", !18, i64 0, !18, i64 32, !18, i64 64, !11, i64 96, !19, i64 104, !19, i64 112}
!18 = !{!"", !11, i64 0, !19, i64 8, !19, i64 16, !10, i64 24}
!19 = !{!"long", !8, i64 0}
!20 = !{!6, !7, i64 8}


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