; 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.mz_zip_archive_file_stat = type { i32, i64, i16, i16, i16, i16, i32, i64, i64, i16, i32, i64, i32, i32, i32, i32, [512 x i8], [512 x i8], i64 }
%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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

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

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

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

13:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %70

14:                                               ; preds = %2
  call void @llvm.memset.p0.i64(ptr align 8 %9, i8 0, i64 1112, i1 false)
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.zip_t, ptr %15, i32 0, i32 0
  store ptr %16, ptr %6, align 8, !tbaa !5
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mz_zip_archive, ptr %17, i32 0, i32 3
  %19 = load i32, ptr %18, align 4, !tbaa !11
  %20 = icmp ne i32 %19, 1
  br i1 %20, label %27, label %21

21:                                               ; preds = %14
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.zip_t, ptr %22, i32 0, i32 2
  %24 = getelementptr inbounds %struct.zip_entry_t, ptr %23, i32 0, i32 0
  %25 = load i64, ptr %24, align 8, !tbaa !14
  %26 = icmp slt i64 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %21, %14
  store i32 -3, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %70

28:                                               ; preds = %21
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.zip_t, ptr %29, i32 0, i32 2
  %31 = getelementptr inbounds %struct.zip_entry_t, ptr %30, i32 0, i32 0
  %32 = load i64, ptr %31, align 8, !tbaa !14
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %7, align 4, !tbaa !9
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = call i32 @mz_zip_reader_is_file_a_directory(ptr noundef %34, i32 noundef %35)
  %37 = icmp ne i32 %36, 0
  br i1 %37, label %38, label %39

38:                                               ; preds = %28
  store i32 -17, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %70

39:                                               ; preds = %28
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !9
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = call i32 @mz_zip_reader_extract_to_file(ptr noundef %40, i32 noundef %41, ptr noundef %42, i32 noundef 0)
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %46, label %45

45:                                               ; preds = %39
  store i32 -19, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %70

46:                                               ; preds = %39
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load i32, ptr %7, align 4, !tbaa !9
  %49 = call i32 @mz_zip_reader_file_stat(ptr noundef %47, i32 noundef %48, ptr noundef %9)
  %50 = icmp ne i32 %49, 0
  br i1 %50, label %52, label %51

51:                                               ; preds = %46
  store i32 -19, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %70

52:                                               ; preds = %46
  %53 = getelementptr inbounds %struct.mz_zip_archive_file_stat, ptr %9, i32 0, i32 10
  %54 = load i32, ptr %53, align 4, !tbaa !20
  %55 = lshr i32 %54, 16
  %56 = and i32 %55, 65535
  store i32 %56, ptr %8, align 4, !tbaa !9
  %57 = load i32, ptr %8, align 4, !tbaa !9
  %58 = icmp ugt i32 %57, 0
  br i1 %58, label %59, label %69

59:                                               ; preds = %52
  %60 = load i32, ptr %8, align 4, !tbaa !9
  %61 = icmp ule i32 %60, 65535
  br i1 %61, label %62, label %69

62:                                               ; preds = %59
  %63 = load ptr, ptr %5, align 8, !tbaa !5
  %64 = load i32, ptr %8, align 4, !tbaa !9
  %65 = call i32 @chmod(ptr noundef %63, i32 noundef %64) #4
  %66 = icmp slt i32 %65, 0
  br i1 %66, label %67, label %68

67:                                               ; preds = %62
  store i32 -20, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %70

68:                                               ; preds = %62
  br label %69

69:                                               ; preds = %68, %59, %52
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %70

70:                                               ; preds = %69, %67, %51, %45, %38, %27, %13
  call void @llvm.lifetime.end.p0(i64 1112, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %71 = load i32, ptr %3, align 4
  ret i32 %71
}

; Function Attrs: nounwind
declare i32 @chmod(ptr noundef, i32 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 "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, !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, !10, i64 20}
!12 = !{!"", !13, i64 0, !13, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !13, 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}
!13 = !{!"long", !7, i64 0}
!14 = !{!15, !13, i64 120}
!15 = !{!"zip_t", !12, i64 0, !10, i64 112, !16, i64 120}
!16 = !{!"zip_entry_t", !13, i64 0, !6, i64 8, !13, i64 16, !13, i64 24, !10, i64 32, !13, i64 40, !7, i64 48, !13, i64 80, !17, i64 88, !18, i64 96, !19, i64 120, !10, i64 319472, !13, i64 319480}
!17 = !{!"short", !7, i64 0}
!18 = !{!"", !6, i64 0, !13, i64 8, !13, 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, !13, i64 184, !13, 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}
!20 = !{!21, !10, i64 52}
!21 = !{!"", !10, i64 0, !13, i64 8, !17, i64 16, !17, i64 18, !17, i64 20, !17, i64 22, !10, i64 24, !13, i64 32, !13, i64 40, !17, i64 48, !10, i64 52, !13, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !7, i64 80, !7, i64 592, !13, i64 1104}


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

%struct.mz_zip_archive_file_stat = type { i32, i64, i16, i16, i16, i16, i32, i64, i64, i16, i32, i64, i32, i32, i32, i32, [512 x i8], [512 x i8], i64 }

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

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -20, 1) i32 @zip_entry_fread(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = alloca %struct.mz_zip_archive_file_stat, align 8
  call void @llvm.lifetime.start.p0(i64 1112, ptr nonnull %3) #4
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %26, label %4

4:                                                ; preds = %2
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1112) %3, i8 0, i64 1112, i1 false)
  %5 = getelementptr inbounds i8, ptr %0, i64 20
  %6 = load i32, ptr %5, align 4, !tbaa !5
  %.not20 = icmp eq i32 %6, 1
  br i1 %.not20, label %7, label %26

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 120
  %9 = load i64, ptr %8, align 8, !tbaa !12
  %10 = icmp slt i64 %9, 0
  br i1 %10, label %26, label %11

11:                                               ; preds = %7
  %12 = trunc i64 %9 to i32
  %13 = tail call i32 @mz_zip_reader_is_file_a_directory(ptr noundef nonnull %0, i32 noundef %12)
  %.not21 = icmp eq i32 %13, 0
  br i1 %.not21, label %14, label %26

14:                                               ; preds = %11
  %15 = tail call i32 @mz_zip_reader_extract_to_file(ptr noundef nonnull %0, i32 noundef %12, ptr noundef %1, i32 noundef 0)
  %.not22 = icmp eq i32 %15, 0
  br i1 %.not22, label %26, label %16

16:                                               ; preds = %14
  %17 = call i32 @mz_zip_reader_file_stat(ptr noundef nonnull %0, i32 noundef %12, ptr noundef nonnull %3)
  %.not23 = icmp eq i32 %17, 0
  br i1 %.not23, label %26, label %18

18:                                               ; preds = %16
  %19 = getelementptr inbounds i8, ptr %3, i64 52
  %20 = load i32, ptr %19, align 4, !tbaa !18
  %.not24 = icmp ult i32 %20, 65536
  br i1 %.not24, label %25, label %21

21:                                               ; preds = %18
  %22 = lshr i32 %20, 16
  %23 = call i32 @chmod(ptr noundef %1, i32 noundef %22) #4
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %26, label %25

25:                                               ; preds = %21, %18
  br label %26

26:                                               ; preds = %21, %16, %14, %11, %4, %7, %2, %25
  %.0 = phi i32 [ 0, %25 ], [ -1, %2 ], [ -3, %7 ], [ -3, %4 ], [ -17, %11 ], [ -19, %14 ], [ -19, %16 ], [ -20, %21 ]
  call void @llvm.lifetime.end.p0(i64 1112, ptr nonnull %3) #4
  ret i32 %.0
}

; Function Attrs: nofree nounwind
declare noundef i32 @chmod(ptr nocapture noundef readonly, i32 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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 #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, !10, i64 20}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !7, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104}
!7 = !{!"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 = !{!13, !7, i64 120}
!13 = !{!"zip_t", !6, i64 0, !10, i64 112, !14, i64 120}
!14 = !{!"zip_entry_t", !7, i64 0, !11, i64 8, !7, i64 16, !7, i64 24, !10, i64 32, !7, i64 40, !8, i64 48, !7, i64 80, !15, i64 88, !16, i64 96, !17, i64 120, !10, i64 319472, !7, i64 319480}
!15 = !{!"short", !8, i64 0}
!16 = !{!"", !11, i64 0, !7, i64 8, !7, i64 16}
!17 = !{!"", !11, i64 0, !11, i64 8, !10, i64 16, !8, i64 20, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !11, i64 48, !11, i64 56, !11, i64 64, !11, 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, !11, i64 136, !11, i64 144, !11, i64 152, !11, i64 160, !10, i64 168, !11, i64 176, !7, i64 184, !7, i64 192, !8, i64 200, !8, i64 33226, !8, i64 34954, !8, i64 36682, !8, i64 37546, !8, i64 103082, !8, i64 168618, !8, i64 234154}
!18 = !{!19, !10, i64 52}
!19 = !{!"", !10, i64 0, !7, i64 8, !15, i64 16, !15, i64 18, !15, i64 20, !15, i64 22, !10, i64 24, !7, i64 32, !7, i64 40, !15, i64 48, !10, i64 52, !7, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !8, i64 80, !8, i64 592, !7, i64 1104}


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