; 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_end(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mz_zip_writer_init_from_reader_v2(ptr noundef, ptr noundef, i32 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_cstream_openwitherror(ptr noundef %0, i32 noundef %1, i8 noundef signext %2, ptr noundef %3) #2 {
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i8 %2, ptr %8, align 1, !tbaa !11
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store ptr null, ptr %10, align 8, !tbaa !5
  %12 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 0, ptr %12, align 4, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = icmp ne ptr %13, null
  br i1 %14, label %17, label %15

15:                                               ; preds = %4
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 -19, ptr %16, align 4, !tbaa !9
  br label %97

17:                                               ; preds = %4
  %18 = load i32, ptr %7, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  store i32 6, ptr %7, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %20, %17
  %22 = load i32, ptr %7, align 4, !tbaa !9
  %23 = and i32 %22, 15
  %24 = icmp sgt i32 %23, 10
  br i1 %24, label %25, label %27

25:                                               ; preds = %21
  %26 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 -5, ptr %26, align 4, !tbaa !9
  br label %97

27:                                               ; preds = %21
  %28 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 319608) #5
  store ptr %28, ptr %10, align 8, !tbaa !5
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = icmp ne ptr %29, null
  br i1 %30, label %33, label %31

31:                                               ; preds = %27
  %32 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 -21, ptr %32, align 4, !tbaa !9
  br label %97

33:                                               ; preds = %27
  %34 = load i32, ptr %7, align 4, !tbaa !9
  %35 = load ptr, ptr %10, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.zip_t, ptr %35, i32 0, i32 1
  store i32 %34, ptr %36, align 8, !tbaa !12
  %37 = load i8, ptr %8, align 1, !tbaa !11
  %38 = sext i8 %37 to i32
  switch i32 %38, label %93 [
    i32 119, label %39
    i32 114, label %48
    i32 97, label %61
    i32 100, label %61
  ]

39:                                               ; preds = %33
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.zip_t, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = call i32 @mz_zip_writer_init_cfile(ptr noundef %41, ptr noundef %42, i32 noundef 16384)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %47, label %45

45:                                               ; preds = %39
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 -31, ptr %46, align 4, !tbaa !9
  br label %97

47:                                               ; preds = %39
  br label %95

48:                                               ; preds = %33
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.zip_t, ptr %49, i32 0, i32 0
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.zip_t, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !12
  %55 = or i32 %54, 2048
  %56 = call i32 @mz_zip_reader_init_cfile(ptr noundef %50, ptr noundef %51, i64 noundef 0, i32 noundef %55)
  %57 = icmp ne i32 %56, 0
  br i1 %57, label %60, label %58

58:                                               ; preds = %48
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 -30, ptr %59, align 4, !tbaa !9
  br label %97

60:                                               ; preds = %48
  br label %95

61:                                               ; preds = %33, %33
  %62 = load ptr, ptr %10, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.zip_t, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %6, align 8, !tbaa !5
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.zip_t, ptr %65, i32 0, i32 1
  %67 = load i32, ptr %66, align 8, !tbaa !12
  %68 = or i32 %67, 2048
  %69 = call i32 @mz_zip_reader_init_cfile(ptr noundef %63, ptr noundef %64, i64 noundef 0, i32 noundef %68)
  %70 = icmp ne i32 %69, 0
  br i1 %70, label %73, label %71

71:                                               ; preds = %61
  %72 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 -30, ptr %72, align 4, !tbaa !9
  br label %97

73:                                               ; preds = %61
  %74 = load i8, ptr %8, align 1, !tbaa !11
  %75 = sext i8 %74 to i32
  %76 = icmp eq i32 %75, 97
  br i1 %76, label %81, label %77

77:                                               ; preds = %73
  %78 = load i8, ptr %8, align 1, !tbaa !11
  %79 = sext i8 %78 to i32
  %80 = icmp eq i32 %79, 100
  br i1 %80, label %81, label %92

81:                                               ; preds = %77, %73
  %82 = load ptr, ptr %10, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.zip_t, ptr %82, i32 0, i32 0
  %84 = call i32 @mz_zip_writer_init_from_reader_v2(ptr noundef %83, ptr noundef null, i32 noundef 0)
  %85 = icmp ne i32 %84, 0
  br i1 %85, label %91, label %86

86:                                               ; preds = %81
  %87 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 -32, ptr %87, align 4, !tbaa !9
  %88 = load ptr, ptr %10, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.zip_t, ptr %88, i32 0, i32 0
  %90 = call i32 @mz_zip_reader_end(ptr noundef %89)
  br label %97

91:                                               ; preds = %81
  br label %92

92:                                               ; preds = %91, %77
  br label %95

93:                                               ; preds = %33
  %94 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 -4, ptr %94, align 4, !tbaa !9
  br label %97

95:                                               ; preds = %92, %60, %47
  %96 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %96, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %106

97:                                               ; preds = %93, %86, %71, %58, %45, %31, %25, %15
  br label %98

98:                                               ; preds = %97
  %99 = load ptr, ptr %10, align 8, !tbaa !5
  %100 = icmp ne ptr %99, null
  br i1 %100, label %101, label %103

101:                                              ; preds = %98
  %102 = load ptr, ptr %10, align 8, !tbaa !5
  call void @free(ptr noundef %102) #4
  store ptr null, ptr %10, align 8, !tbaa !5
  br label %103

103:                                              ; preds = %101, %98
  br label %104

104:                                              ; preds = %103
  br label %105

105:                                              ; preds = %104
  store ptr null, ptr %5, align 8
  store i32 1, ptr %11, align 4
  br label %106

106:                                              ; preds = %105, %95
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  %107 = load ptr, ptr %5, align 8
  ret ptr %107
}

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 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 112}
!13 = !{!"zip_t", !14, i64 0, !10, i64 112, !16, i64 120}
!14 = !{!"", !15, i64 0, !15, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !15, 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}
!15 = !{!"long", !7, i64 0}
!16 = !{!"zip_entry_t", !15, i64 0, !6, i64 8, !15, i64 16, !15, i64 24, !10, i64 32, !15, i64 40, !7, i64 48, !15, i64 80, !17, i64 88, !18, i64 96, !19, i64 120, !10, i64 319472, !15, i64 319480}
!17 = !{!"short", !7, i64 0}
!18 = !{!"", !6, i64 0, !15, i64 8, !15, i64 16}
!19 = !{!"", !6, i64 0, !6, i64 8, !10, i64 16, !7, i64 20, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !10, i64 96, !10, i64 100, !10, i64 104, !10, i64 108, !10, i64 112, !10, i64 116, !10, i64 120, !10, i64 124, !10, i64 128, !10, i64 132, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !10, i64 168, !6, i64 176, !15, i64 184, !15, 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_end(ptr noundef) local_unnamed_addr #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mz_zip_writer_init_from_reader_v2(ptr noundef, ptr noundef, i32 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_cstream_openwitherror(ptr noundef %0, i32 noundef %1, i8 noundef signext %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #1 {
  store i32 0, ptr %3, align 4, !tbaa !5
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %5, label %6

5:                                                ; preds = %4
  store i32 -19, ptr %3, align 4, !tbaa !5
  br label %34

6:                                                ; preds = %4
  %7 = icmp slt i32 %1, 0
  %spec.store.select = select i1 %7, i32 6, i32 %1
  %8 = and i32 %spec.store.select, 15
  %9 = icmp ugt i32 %8, 10
  br i1 %9, label %10, label %11

10:                                               ; preds = %6
  store i32 -5, ptr %3, align 4, !tbaa !5
  br label %34

11:                                               ; preds = %6
  %12 = tail call noalias dereferenceable_or_null(319608) ptr @calloc(i64 noundef 1, i64 noundef 319608) #3
  %.not36 = icmp eq ptr %12, null
  br i1 %.not36, label %13, label %14

13:                                               ; preds = %11
  store i32 -21, ptr %3, align 4, !tbaa !5
  br label %34

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %12, i64 112
  store i32 %spec.store.select, ptr %15, align 8, !tbaa !9
  switch i8 %2, label %32 [
    i8 119, label %16
    i8 114, label %19
    i8 97, label %23
    i8 100, label %23
  ]

16:                                               ; preds = %14
  %17 = tail call i32 @mz_zip_writer_init_cfile(ptr noundef nonnull %12, ptr noundef nonnull %0, i32 noundef 16384)
  %.not40 = icmp eq i32 %17, 0
  br i1 %.not40, label %18, label %34

18:                                               ; preds = %16
  store i32 -31, ptr %3, align 4, !tbaa !5
  br label %33

19:                                               ; preds = %14
  %20 = or i32 %spec.store.select, 2048
  %21 = tail call i32 @mz_zip_reader_init_cfile(ptr noundef nonnull %12, ptr noundef nonnull %0, i64 noundef 0, i32 noundef %20)
  %.not39 = icmp eq i32 %21, 0
  br i1 %.not39, label %22, label %34

22:                                               ; preds = %19
  store i32 -30, ptr %3, align 4, !tbaa !5
  br label %33

23:                                               ; preds = %14, %14
  %24 = or i32 %spec.store.select, 2048
  %25 = tail call i32 @mz_zip_reader_init_cfile(ptr noundef nonnull %12, ptr noundef nonnull %0, i64 noundef 0, i32 noundef %24)
  %.not37 = icmp eq i32 %25, 0
  br i1 %.not37, label %26, label %27

26:                                               ; preds = %23
  store i32 -30, ptr %3, align 4, !tbaa !5
  br label %33

27:                                               ; preds = %23
  switch i8 %2, label %34 [
    i8 100, label %28
    i8 97, label %28
  ]

28:                                               ; preds = %27, %27
  %29 = tail call i32 @mz_zip_writer_init_from_reader_v2(ptr noundef nonnull %12, ptr noundef null, i32 noundef 0)
  %.not38 = icmp eq i32 %29, 0
  br i1 %.not38, label %30, label %34

30:                                               ; preds = %28
  store i32 -32, ptr %3, align 4, !tbaa !5
  %31 = tail call i32 @mz_zip_reader_end(ptr noundef nonnull %12)
  br label %33

32:                                               ; preds = %14
  store i32 -4, ptr %3, align 4, !tbaa !5
  br label %33

33:                                               ; preds = %32, %30, %26, %22, %18
  tail call void @free(ptr noundef nonnull %12) #4
  br label %34

34:                                               ; preds = %13, %10, %5, %33, %16, %19, %28, %27
  %.033 = phi ptr [ %12, %27 ], [ %12, %28 ], [ %12, %19 ], [ %12, %16 ], [ null, %33 ], [ null, %5 ], [ null, %10 ], [ null, %13 ]
  ret ptr %.033
}

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,JumpThreadingPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass