; LLVM IR from kuba--/zip :: src (zip)

; 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.zip_t = type { %struct.mz_zip_archive, i32, %struct.zip_entry_t }
%struct.mz_zip_archive = type { i64, i64, i32, i32, i32, i32, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.zip_entry_t = type { i64, ptr, i64, i64, i32, i64, [30 x i8], i64, i16, %struct.mz_zip_writer_add_state, %struct.tdefl_compressor, i32, i64 }
%struct.mz_zip_writer_add_state = type { ptr, i64, i64 }
%struct.tdefl_compressor = type { ptr, ptr, i32, [2 x i32], i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, ptr, ptr, ptr, ptr, i32, ptr, i64, i64, [33025 x i8], [3 x [288 x i16]], [3 x [288 x i16]], [3 x [288 x i8]], [65536 x i8], [32768 x i16], [32768 x i16], [85196 x i8] }

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @zip_stream_openwitherror(ptr noundef %0, i64 noundef %1, i32 noundef %2, i8 noundef signext %3, ptr noundef %4) #2 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i64 %1, ptr %8, align 8, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !11
  store i8 %3, ptr %10, align 1, !tbaa !13
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %14 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 319608) #5
  store ptr %14, ptr %12, align 8, !tbaa !5
  %15 = load ptr, ptr %12, align 8, !tbaa !5
  %16 = icmp ne ptr %15, null
  br i1 %16, label %19, label %17

17:                                               ; preds = %5
  %18 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 -21, ptr %18, align 4, !tbaa !11
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %85

19:                                               ; preds = %5
  %20 = load i32, ptr %9, align 4, !tbaa !11
  %21 = icmp slt i32 %20, 0
  br i1 %21, label %22, label %23

22:                                               ; preds = %19
  store i32 6, ptr %9, align 4, !tbaa !11
  br label %23

23:                                               ; preds = %22, %19
  %24 = load i32, ptr %9, align 4, !tbaa !11
  %25 = and i32 %24, 15
  %26 = icmp sgt i32 %25, 10
  br i1 %26, label %27, label %29

27:                                               ; preds = %23
  %28 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 -5, ptr %28, align 4, !tbaa !11
  br label %76

29:                                               ; preds = %23
  %30 = load i32, ptr %9, align 4, !tbaa !11
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.zip_t, ptr %31, i32 0, i32 1
  store i32 %30, ptr %32, align 8, !tbaa !14
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %35, label %52

35:                                               ; preds = %29
  %36 = load i64, ptr %8, align 8, !tbaa !9
  %37 = icmp ugt i64 %36, 0
  br i1 %37, label %38, label %52

38:                                               ; preds = %35
  %39 = load i8, ptr %10, align 1, !tbaa !13
  %40 = sext i8 %39 to i32
  %41 = icmp eq i32 %40, 114
  br i1 %41, label %42, label %52

42:                                               ; preds = %38
  %43 = load ptr, ptr %12, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.zip_t, ptr %43, i32 0, i32 0
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = load i64, ptr %8, align 8, !tbaa !9
  %47 = call i32 @mz_zip_reader_init_mem(ptr noundef %44, ptr noundef %45, i64 noundef %46, i32 noundef 0)
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %51, label %49

49:                                               ; preds = %42
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 -30, ptr %50, align 4, !tbaa !11
  br label %76

51:                                               ; preds = %42
  br label %73

52:                                               ; preds = %38, %35, %29
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = icmp eq ptr %53, null
  br i1 %54, label %55, label %70

55:                                               ; preds = %52
  %56 = load i64, ptr %8, align 8, !tbaa !9
  %57 = icmp eq i64 %56, 0
  br i1 %57, label %58, label %70

58:                                               ; preds = %55
  %59 = load i8, ptr %10, align 1, !tbaa !13
  %60 = sext i8 %59 to i32
  %61 = icmp eq i32 %60, 119
  br i1 %61, label %62, label %70

62:                                               ; preds = %58
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.zip_t, ptr %63, i32 0, i32 0
  %65 = call i32 @mz_zip_writer_init_heap(ptr noundef %64, i64 noundef 0, i64 noundef 1024)
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %69, label %67

67:                                               ; preds = %62
  %68 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 -31, ptr %68, align 4, !tbaa !11
  br label %76

69:                                               ; preds = %62
  br label %72

70:                                               ; preds = %58, %55, %52
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 -4, ptr %71, align 4, !tbaa !11
  br label %76

72:                                               ; preds = %69
  br label %73

73:                                               ; preds = %72, %51
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 0, ptr %74, align 4, !tbaa !11
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %75, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %85

76:                                               ; preds = %70, %67, %49, %27
  br label %77

77:                                               ; preds = %76
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = icmp ne ptr %78, null
  br i1 %79, label %80, label %82

80:                                               ; preds = %77
  %81 = load ptr, ptr %12, align 8, !tbaa !5
  call void @free(ptr noundef %81) #4
  store ptr null, ptr %12, align 8, !tbaa !5
  br label %82

82:                                               ; preds = %80, %77
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83
  store ptr null, ptr %6, align 8
  store i32 1, ptr %13, align 4
  br label %85

85:                                               ; preds = %84, %73, %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  %86 = load ptr, ptr %6, align 8
  ret ptr %86
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { nounwind allocsize(0,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 #4 = { nounwind }
attributes #5 = { nounwind allocsize(0,1) }

!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", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !12, i64 112}
!15 = !{!"zip_t", !16, i64 0, !12, i64 112, !17, i64 120}
!16 = !{!"", !10, i64 0, !10, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !10, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104}
!17 = !{!"zip_entry_t", !10, i64 0, !6, i64 8, !10, i64 16, !10, i64 24, !12, i64 32, !10, i64 40, !7, i64 48, !10, i64 80, !18, i64 88, !19, i64 96, !20, i64 120, !12, i64 319472, !10, i64 319480}
!18 = !{!"short", !7, i64 0}
!19 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16}
!20 = !{!"", !6, i64 0, !6, i64 8, !12, i64 16, !7, i64 20, !12, i64 28, !12, i64 32, !12, i64 36, !12, i64 40, !12, i64 44, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !12, i64 80, !12, i64 84, !12, i64 88, !12, i64 92, !12, i64 96, !12, i64 100, !12, i64 104, !12, i64 108, !12, i64 112, !12, i64 116, !12, i64 120, !12, i64 124, !12, i64 128, !12, i64 132, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !12, i64 168, !6, i64 176, !10, i64 184, !10, i64 192, !7, i64 200, !7, i64 33226, !7, i64 34954, !7, i64 36682, !7, i64 37546, !7, i64 103082, !7, i64 168618, !7, i64 234154}


; 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @mz_zip_reader_init_mem(ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @mz_zip_writer_init_heap(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress 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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @zip_stream_openwitherror(ptr noundef %0, i64 noundef %1, i32 noundef %2, i8 noundef signext %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #1 {
  %6 = tail call noalias dereferenceable_or_null(319608) ptr @calloc(i64 noundef 1, i64 noundef 319608) #3
  %.not = icmp eq ptr %6, null
  br i1 %.not, label %7, label %8

7:                                                ; preds = %5
  store i32 -21, ptr %4, align 4, !tbaa !5
  br label %27

8:                                                ; preds = %5
  %9 = icmp slt i32 %2, 0
  %spec.store.select = select i1 %9, i32 6, i32 %2
  %10 = and i32 %spec.store.select, 15
  %11 = icmp ugt i32 %10, 10
  br i1 %11, label %26, label %12

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %6, i64 112
  store i32 %spec.store.select, ptr %13, align 8, !tbaa !9
  %14 = icmp ne ptr %0, null
  %15 = icmp ne i64 %1, 0
  %or.cond = and i1 %14, %15
  %16 = icmp eq i8 %3, 114
  %or.cond4 = and i1 %or.cond, %16
  br i1 %or.cond4, label %17, label %19

17:                                               ; preds = %12
  %18 = tail call i32 @mz_zip_reader_init_mem(ptr noundef nonnull %6, ptr noundef nonnull %0, i64 noundef %1, i32 noundef 0)
  %.not37 = icmp eq i32 %18, 0
  br i1 %.not37, label %26, label %25

19:                                               ; preds = %12
  %20 = icmp eq ptr %0, null
  %21 = icmp eq i64 %1, 0
  %or.cond6 = and i1 %20, %21
  %22 = icmp eq i8 %3, 119
  %or.cond9 = and i1 %or.cond6, %22
  br i1 %or.cond9, label %23, label %26

23:                                               ; preds = %19
  %24 = tail call i32 @mz_zip_writer_init_heap(ptr noundef nonnull %6, i64 noundef 0, i64 noundef 1024)
  %.not36 = icmp eq i32 %24, 0
  br i1 %.not36, label %26, label %25

25:                                               ; preds = %23, %17
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %27

26:                                               ; preds = %19, %23, %17, %8
  %.sink = phi i32 [ -5, %8 ], [ -30, %17 ], [ -31, %23 ], [ -4, %19 ]
  store i32 %.sink, ptr %4, align 4, !tbaa !5
  tail call void @free(ptr noundef nonnull %6) #4
  br label %27

27:                                               ; preds = %26, %25, %7
  %.0 = phi ptr [ null, %26 ], [ %6, %25 ], [ null, %7 ]
  ret ptr %.0
}

attributes #0 = { 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 #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 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(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 allocsize(0,1) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 112}
!10 = !{!"zip_t", !11, i64 0, !6, i64 112, !14, i64 120}
!11 = !{!"", !12, i64 0, !12, i64 8, !6, i64 16, !6, i64 20, !6, i64 24, !6, i64 28, !12, i64 32, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !13, i64 80, !13, i64 88, !13, i64 96, !13, i64 104}
!12 = !{!"long", !7, i64 0}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"zip_entry_t", !12, i64 0, !13, i64 8, !12, i64 16, !12, i64 24, !6, i64 32, !12, i64 40, !7, i64 48, !12, i64 80, !15, i64 88, !16, i64 96, !17, i64 120, !6, i64 319472, !12, i64 319480}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !13, i64 0, !12, i64 8, !12, i64 16}
!17 = !{!"", !13, i64 0, !13, i64 8, !6, i64 16, !7, i64 20, !6, i64 28, !6, i64 32, !6, i64 36, !6, i64 40, !6, i64 44, !13, i64 48, !13, i64 56, !13, i64 64, !13, i64 72, !6, i64 80, !6, i64 84, !6, i64 88, !6, i64 92, !6, i64 96, !6, i64 100, !6, i64 104, !6, i64 108, !6, i64 112, !6, i64 116, !6, i64 120, !6, i64 124, !6, i64 128, !6, i64 132, !13, i64 136, !13, i64 144, !13, i64 152, !13, i64 160, !6, i64 168, !13, i64 176, !12, i64 184, !12, i64 192, !7, i64 200, !7, i64 33226, !7, i64 34954, !7, i64 36682, !7, i64 37546, !7, i64 103082, !7, i64 168618, !7, i64 234154}


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