; 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] }
%struct.mz_zip_internal_state_tag = type { %struct.mz_zip_array, %struct.mz_zip_array, %struct.mz_zip_array, i32, i32, i32, ptr, i64, ptr, i64, i64 }
%struct.mz_zip_array = type { ptr, i64, i64, i32 }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

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

; Function Attrs: nounwind uwtable
define dso_local i64 @zip_stream_copy(ptr noundef %0, ptr noundef %1, ptr noundef %2) #2 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  %8 = load ptr, ptr %5, align 8, !tbaa !5
  %9 = icmp ne ptr %8, null
  br i1 %9, label %11, label %10

10:                                               ; preds = %3
  store i64 -1, ptr %4, align 8
  br label %45

11:                                               ; preds = %3
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.zip_t, ptr %12, i32 0, i32 0
  call void @zip_archive_finalize(ptr noundef %13)
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp ne ptr %14, null
  br i1 %15, label %16, label %22

16:                                               ; preds = %11
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.zip_t, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.mz_zip_archive, ptr %18, i32 0, i32 0
  %20 = load i64, ptr %19, align 8, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %20, ptr %21, align 8, !tbaa !19
  br label %22

22:                                               ; preds = %16, %11
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.zip_t, ptr %23, i32 0, i32 0
  %25 = getelementptr inbounds %struct.mz_zip_archive, ptr %24, i32 0, i32 0
  %26 = load i64, ptr %25, align 8, !tbaa !9
  %27 = call noalias ptr @calloc(i64 noundef 1, i64 noundef %26) #4
  %28 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %27, ptr %28, align 8, !tbaa !5
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %29, align 8, !tbaa !5
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.zip_t, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds %struct.mz_zip_archive, ptr %32, i32 0, i32 15
  %34 = load ptr, ptr %33, align 8, !tbaa !20
  %35 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %34, i32 0, i32 8
  %36 = load ptr, ptr %35, align 8, !tbaa !21
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.zip_t, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds %struct.mz_zip_archive, ptr %38, i32 0, i32 0
  %40 = load i64, ptr %39, align 8, !tbaa !9
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %30, ptr align 1 %36, i64 %40, i1 false)
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.zip_t, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds %struct.mz_zip_archive, ptr %42, i32 0, i32 0
  %44 = load i64, ptr %43, align 8, !tbaa !9
  store i64 %44, ptr %4, align 8
  br label %45

45:                                               ; preds = %22, %10
  %46 = load i64, ptr %4, align 8
  ret i64 %46
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @zip_archive_finalize(ptr noundef) #3

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { inlinehint 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 #4 = { 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, !12, i64 0}
!10 = !{!"zip_t", !11, i64 0, !13, i64 112, !14, i64 120}
!11 = !{!"", !12, i64 0, !12, i64 8, !13, i64 16, !13, i64 20, !13, i64 24, !13, i64 28, !12, 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}
!12 = !{!"long long", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"zip_entry_t", !13, i64 0, !6, i64 8, !12, i64 16, !12, i64 24, !13, i64 32, !12, i64 40, !7, i64 48, !12, i64 80, !15, i64 88, !16, i64 96, !17, i64 120, !13, i64 319472, !18, i64 319480}
!15 = !{!"short", !7, i64 0}
!16 = !{!"", !6, i64 0, !12, i64 8, !12, i64 16}
!17 = !{!"", !6, i64 0, !6, i64 8, !13, i64 16, !7, i64 20, !13, i64 28, !13, i64 32, !13, i64 36, !13, i64 40, !13, i64 44, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !13, i64 80, !13, i64 84, !13, i64 88, !13, i64 92, !13, i64 96, !13, i64 100, !13, i64 104, !13, i64 108, !13, i64 112, !13, i64 116, !13, i64 120, !13, i64 124, !13, i64 128, !13, i64 132, !6, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !13, i64 168, !6, i64 176, !18, i64 184, !18, 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}
!18 = !{!"long", !7, i64 0}
!19 = !{!18, !18, i64 0}
!20 = !{!10, !6, i64 104}
!21 = !{!22, !6, i64 128}
!22 = !{!"mz_zip_internal_state_tag", !23, i64 0, !23, i64 32, !23, i64 64, !13, i64 96, !13, i64 100, !13, i64 104, !6, i64 112, !12, i64 120, !6, i64 128, !18, i64 136, !18, i64 144}
!23 = !{!"", !6, i64 0, !18, i64 8, !18, i64 16, !13, i64 24}


; 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 nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #0

; 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 #1

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

4:                                                ; preds = %3
  tail call void @zip_archive_finalize(ptr noundef nonnull %0)
  %.not13 = icmp eq ptr %2, null
  %.pre = load i64, ptr %0, align 8, !tbaa !5
  br i1 %.not13, label %6, label %5

5:                                                ; preds = %4
  store i64 %.pre, ptr %2, align 8, !tbaa !18
  br label %6

6:                                                ; preds = %5, %4
  %7 = tail call noalias ptr @calloc(i64 noundef 1, i64 noundef %.pre) #4
  store ptr %7, ptr %1, align 8, !tbaa !19
  %8 = getelementptr inbounds i8, ptr %0, i64 104
  %9 = load ptr, ptr %8, align 8, !tbaa !20
  %10 = getelementptr inbounds i8, ptr %9, i64 128
  %11 = load ptr, ptr %10, align 8, !tbaa !21
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %7, ptr align 1 %11, i64 %.pre, i1 false)
  br label %12

12:                                               ; preds = %3, %6
  %.0 = phi i64 [ %.pre, %6 ], [ -1, %3 ]
  ret i64 %.0
}

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @zip_archive_finalize(ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { inlinehint 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 #4 = { 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, !8, i64 0}
!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 = !{!17, !17, i64 0}
!19 = !{!12, !12, i64 0}
!20 = !{!6, !12, i64 104}
!21 = !{!22, !12, i64 128}
!22 = !{!"mz_zip_internal_state_tag", !23, i64 0, !23, i64 32, !23, i64 64, !11, i64 96, !11, i64 100, !11, i64 104, !12, i64 112, !8, i64 120, !12, i64 128, !17, i64 136, !17, i64 144}
!23 = !{!"", !12, i64 0, !17, i64 8, !17, i64 16, !11, i64 24}


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