; LLVM IR from facebook/hermes :: external/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 { i32, 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 uwtable
declare dso_local i64 @mz_crc32(i64 noundef, ptr noundef, i64 noundef) #1

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

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

14:                                               ; preds = %3
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %94

15:                                               ; preds = %3
  %16 = load ptr, ptr %5, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.zip_t, ptr %16, i32 0, i32 0
  store ptr %17, ptr %9, align 8, !tbaa !5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %93

20:                                               ; preds = %15
  %21 = load i64, ptr %7, align 8, !tbaa !9
  %22 = icmp ugt i64 %21, 0
  br i1 %22, label %23, label %93

23:                                               ; preds = %20
  %24 = load i64, ptr %7, align 8, !tbaa !9
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.zip_t, ptr %25, i32 0, i32 2
  %27 = getelementptr inbounds %struct.zip_entry_t, ptr %26, i32 0, i32 2
  %28 = load i64, ptr %27, align 8, !tbaa !11
  %29 = add i64 %28, %24
  store i64 %29, ptr %27, align 8, !tbaa !11
  %30 = load ptr, ptr %5, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.zip_t, ptr %30, i32 0, i32 2
  %32 = getelementptr inbounds %struct.zip_entry_t, ptr %31, i32 0, i32 4
  %33 = load i32, ptr %32, align 8, !tbaa !20
  %34 = zext i32 %33 to i64
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = call i64 @mz_crc32(i64 noundef %34, ptr noundef %35, i64 noundef %36)
  %38 = trunc i64 %37 to i32
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.zip_t, ptr %39, i32 0, i32 2
  %41 = getelementptr inbounds %struct.zip_entry_t, ptr %40, i32 0, i32 4
  store i32 %38, ptr %41, align 8, !tbaa !20
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.zip_t, ptr %42, i32 0, i32 1
  %44 = load i32, ptr %43, align 8, !tbaa !21
  %45 = and i32 %44, 15
  store i32 %45, ptr %8, align 4, !tbaa !22
  %46 = load i32, ptr %8, align 4, !tbaa !22
  %47 = icmp ne i32 %46, 0
  br i1 %47, label %78, label %48

48:                                               ; preds = %23
  %49 = load ptr, ptr %9, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.mz_zip_archive, ptr %49, i32 0, i32 12
  %51 = load ptr, ptr %50, align 8, !tbaa !23
  %52 = load ptr, ptr %9, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.mz_zip_archive, ptr %52, i32 0, i32 14
  %54 = load ptr, ptr %53, align 8, !tbaa !24
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.zip_t, ptr %55, i32 0, i32 2
  %57 = getelementptr inbounds %struct.zip_entry_t, ptr %56, i32 0, i32 5
  %58 = load i64, ptr %57, align 8, !tbaa !25
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = load i64, ptr %7, align 8, !tbaa !9
  %61 = call i64 %51(ptr noundef %54, i64 noundef %58, ptr noundef %59, i64 noundef %60)
  %62 = load i64, ptr %7, align 8, !tbaa !9
  %63 = icmp ne i64 %61, %62
  br i1 %63, label %64, label %65

64:                                               ; preds = %48
  store i32 -8, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %94

65:                                               ; preds = %48
  %66 = load i64, ptr %7, align 8, !tbaa !9
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = getelementptr inbounds %struct.zip_t, ptr %67, i32 0, i32 2
  %69 = getelementptr inbounds %struct.zip_entry_t, ptr %68, i32 0, i32 5
  %70 = load i64, ptr %69, align 8, !tbaa !25
  %71 = add i64 %70, %66
  store i64 %71, ptr %69, align 8, !tbaa !25
  %72 = load i64, ptr %7, align 8, !tbaa !9
  %73 = load ptr, ptr %5, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.zip_t, ptr %73, i32 0, i32 2
  %75 = getelementptr inbounds %struct.zip_entry_t, ptr %74, i32 0, i32 3
  %76 = load i64, ptr %75, align 8, !tbaa !26
  %77 = add i64 %76, %72
  store i64 %77, ptr %75, align 8, !tbaa !26
  br label %92

78:                                               ; preds = %23
  %79 = load ptr, ptr %5, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.zip_t, ptr %79, i32 0, i32 2
  %81 = getelementptr inbounds %struct.zip_entry_t, ptr %80, i32 0, i32 10
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = load i64, ptr %7, align 8, !tbaa !9
  %84 = call i32 @tdefl_compress_buffer(ptr noundef %81, ptr noundef %82, i64 noundef %83, i32 noundef 0)
  store i32 %84, ptr %10, align 4, !tbaa !22
  %85 = load i32, ptr %10, align 4, !tbaa !22
  %86 = icmp ne i32 %85, 1
  br i1 %86, label %87, label %91

87:                                               ; preds = %78
  %88 = load i32, ptr %10, align 4, !tbaa !22
  %89 = icmp ne i32 %88, 0
  br i1 %89, label %90, label %91

90:                                               ; preds = %87
  store i32 -12, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %94

91:                                               ; preds = %87, %78
  br label %92

92:                                               ; preds = %91, %65
  br label %93

93:                                               ; preds = %92, %20, %15
  store i32 0, ptr %4, align 4
  store i32 1, ptr %11, align 4
  br label %94

94:                                               ; preds = %93, %90, %64, %14
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  %95 = load i32, ptr %4, align 4
  ret i32 %95
}

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


; 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: nounwind uwtable
declare dso_local i64 @mz_crc32(i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -12, 1) i32 @zip_entry_write(ptr noundef %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %37, label %4

4:                                                ; preds = %3
  %5 = icmp ne ptr %1, null
  %6 = icmp ne i64 %2, 0
  %or.cond = and i1 %5, %6
  br i1 %or.cond, label %7, label %36

7:                                                ; preds = %4
  %8 = getelementptr inbounds i8, ptr %0, i64 136
  %9 = load i64, ptr %8, align 8, !tbaa !5
  %10 = add i64 %9, %2
  store i64 %10, ptr %8, align 8, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 152
  %12 = load i32, ptr %11, align 8, !tbaa !18
  %13 = zext i32 %12 to i64
  %14 = tail call i64 @mz_crc32(i64 noundef %13, ptr noundef nonnull %1, i64 noundef %2)
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr %11, align 8, !tbaa !18
  %16 = getelementptr inbounds i8, ptr %0, i64 112
  %17 = load i32, ptr %16, align 8, !tbaa !19
  %18 = and i32 %17, 15
  %.not33 = icmp eq i32 %18, 0
  br i1 %.not33, label %19, label %33

19:                                               ; preds = %7
  %20 = getelementptr inbounds i8, ptr %0, i64 80
  %21 = load ptr, ptr %20, align 8, !tbaa !20
  %22 = getelementptr inbounds i8, ptr %0, i64 96
  %23 = load ptr, ptr %22, align 8, !tbaa !21
  %24 = getelementptr inbounds i8, ptr %0, i64 160
  %25 = load i64, ptr %24, align 8, !tbaa !22
  %26 = tail call i64 %21(ptr noundef %23, i64 noundef %25, ptr noundef nonnull %1, i64 noundef %2) #1
  %.not34 = icmp eq i64 %26, %2
  br i1 %.not34, label %27, label %37

27:                                               ; preds = %19
  %28 = load i64, ptr %24, align 8, !tbaa !22
  %29 = add i64 %28, %2
  store i64 %29, ptr %24, align 8, !tbaa !22
  %30 = getelementptr inbounds i8, ptr %0, i64 144
  %31 = load i64, ptr %30, align 8, !tbaa !23
  %32 = add i64 %31, %2
  store i64 %32, ptr %30, align 8, !tbaa !23
  br label %36

33:                                               ; preds = %7
  %34 = getelementptr inbounds i8, ptr %0, i64 240
  %35 = tail call i32 @tdefl_compress_buffer(ptr noundef nonnull %34, ptr noundef nonnull %1, i64 noundef %2, i32 noundef 0)
  %or.cond3 = icmp ugt i32 %35, 1
  br i1 %or.cond3, label %37, label %36

36:                                               ; preds = %27, %33, %4
  br label %37

37:                                               ; preds = %33, %19, %3, %36
  %.0 = phi i32 [ 0, %36 ], [ -1, %3 ], [ -8, %19 ], [ -12, %33 ]
  ret i32 %.0
}

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


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