; 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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, 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 { 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] }

@.str.17 = external hidden unnamed_addr constant [3 x i8], align 1

; 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

declare noalias ptr @fopen(ptr noundef, ptr noundef) #2

declare i32 @fclose(ptr noundef) #2

declare i64 @fread(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

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

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

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

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

15:                                               ; preds = %2
  %16 = getelementptr inbounds [65536 x i8], ptr %9, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %16, i8 0, i64 65536, i1 false)
  call void @llvm.memset.p0.i64(ptr align 8 %10, i8 0, i64 144, i1 false)
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = call i32 @stat(ptr noundef %17, ptr noundef %10) #5
  %19 = icmp ne i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %15
  store i32 -3, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %70

21:                                               ; preds = %15
  %22 = getelementptr inbounds %struct.stat, ptr %10, i32 0, i32 3
  %23 = load i32, ptr %22, align 8, !tbaa !13
  %24 = and i32 %23, 128
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %26, label %32

26:                                               ; preds = %21
  %27 = load ptr, ptr %4, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.zip_t, ptr %27, i32 0, i32 2
  %29 = getelementptr inbounds %struct.zip_entry_t, ptr %28, i32 0, i32 11
  %30 = load i32, ptr %29, align 8, !tbaa !16
  %31 = or i32 %30, 1
  store i32 %31, ptr %29, align 8, !tbaa !16
  br label %32

32:                                               ; preds = %26, %21
  %33 = getelementptr inbounds %struct.stat, ptr %10, i32 0, i32 3
  %34 = load i32, ptr %33, align 8, !tbaa !13
  %35 = and i32 %34, 65535
  %36 = shl i32 %35, 16
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.zip_t, ptr %37, i32 0, i32 2
  %39 = getelementptr inbounds %struct.zip_entry_t, ptr %38, i32 0, i32 11
  %40 = load i32, ptr %39, align 8, !tbaa !16
  %41 = or i32 %40, %36
  store i32 %41, ptr %39, align 8, !tbaa !16
  %42 = getelementptr inbounds %struct.stat, ptr %10, i32 0, i32 12
  %43 = getelementptr inbounds %struct.timespec, ptr %42, i32 0, i32 0
  %44 = load i64, ptr %43, align 8, !tbaa !24
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.zip_t, ptr %45, i32 0, i32 2
  %47 = getelementptr inbounds %struct.zip_entry_t, ptr %46, i32 0, i32 12
  store i64 %44, ptr %47, align 8, !tbaa !25
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = call noalias ptr @fopen(ptr noundef %48, ptr noundef @.str.17)
  store ptr %49, ptr %8, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %52, label %51

51:                                               ; preds = %32
  store i32 -16, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %70

52:                                               ; preds = %32
  br label %53

53:                                               ; preds = %65, %52
  %54 = getelementptr inbounds [65536 x i8], ptr %9, i64 0, i64 0
  %55 = load ptr, ptr %8, align 8, !tbaa !5
  %56 = call i64 @fread(ptr noundef %54, i64 noundef 1, i64 noundef 65536, ptr noundef %55)
  store i64 %56, ptr %7, align 8, !tbaa !11
  %57 = icmp ugt i64 %56, 0
  br i1 %57, label %58, label %66

58:                                               ; preds = %53
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds [65536 x i8], ptr %9, i64 0, i64 0
  %61 = load i64, ptr %7, align 8, !tbaa !11
  %62 = call i32 @zip_entry_write(ptr noundef %59, ptr noundef %60, i64 noundef %61)
  %63 = icmp slt i32 %62, 0
  br i1 %63, label %64, label %65

64:                                               ; preds = %58
  store i32 -8, ptr %6, align 4, !tbaa !9
  br label %66

65:                                               ; preds = %58
  br label %53, !llvm.loop !26

66:                                               ; preds = %64, %53
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  %68 = call i32 @fclose(ptr noundef %67)
  %69 = load i32, ptr %6, align 4, !tbaa !9
  store i32 %69, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %70

70:                                               ; preds = %66, %51, %20, %14
  call void @llvm.lifetime.end.p0(i64 144, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 65536, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %71 = load i32, ptr %3, align 4
  ret i32 %71
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { "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 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 #5 = { 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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !10, i64 24}
!14 = !{!"stat", !12, i64 0, !12, i64 8, !12, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !12, i64 40, !12, i64 48, !12, i64 56, !12, i64 64, !15, i64 72, !15, i64 88, !15, i64 104, !7, i64 120}
!15 = !{!"timespec", !12, i64 0, !12, i64 8}
!16 = !{!17, !10, i64 319592}
!17 = !{!"zip_t", !18, i64 0, !10, i64 112, !20, i64 120}
!18 = !{!"", !19, i64 0, !19, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !19, 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}
!19 = !{!"long long", !7, i64 0}
!20 = !{!"zip_entry_t", !10, i64 0, !6, i64 8, !19, i64 16, !19, i64 24, !10, i64 32, !19, i64 40, !7, i64 48, !19, i64 80, !21, i64 88, !22, i64 96, !23, i64 120, !10, i64 319472, !12, i64 319480}
!21 = !{!"short", !7, i64 0}
!22 = !{!"", !6, i64 0, !19, i64 8, !19, i64 16}
!23 = !{!"", !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, !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}
!24 = !{!14, !12, i64 88}
!25 = !{!17, !12, i64 319600}
!26 = distinct !{!26, !27}
!27 = !{!"llvm.loop.mustprogress"}


; 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.stat = type { i64, i64, i64, i32, i32, i32, i32, i64, i64, i64, i64, %struct.timespec, %struct.timespec, %struct.timespec, [3 x i64] }
%struct.timespec = type { i64, i64 }

@.str.17 = external hidden unnamed_addr constant [3 x i8], align 1

; 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: nofree nounwind
declare noalias noundef ptr @fopen(ptr nocapture noundef readonly, ptr nocapture noundef readonly) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i64 @fread(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -16, 1) i32 @zip_entry_fwrite(ptr noundef %0, ptr nocapture noundef readonly %1) local_unnamed_addr #3 {
  %3 = alloca [65536 x i8], align 16
  %4 = alloca %struct.stat, align 8
  call void @llvm.lifetime.start.p0(i64 65536, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %4) #4
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %28, label %5

5:                                                ; preds = %2
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(65536) %3, i8 0, i64 65536, i1 false)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(144) %4, i8 0, i64 144, i1 false)
  %6 = call i32 @stat(ptr noundef %1, ptr noundef nonnull %4) #4
  %.not14 = icmp eq i32 %6, 0
  br i1 %.not14, label %._crit_edge, label %28

._crit_edge:                                      ; preds = %5
  %7 = getelementptr inbounds i8, ptr %4, i64 24
  %8 = load i32, ptr %7, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 319592
  %10 = load i32, ptr %9, align 8, !tbaa !12
  %11 = lshr i32 %8, 7
  %12 = and i32 %11, 1
  %13 = xor i32 %12, 1
  %14 = or i32 %10, %13
  %15 = shl i32 %8, 16
  %16 = getelementptr inbounds i8, ptr %0, i64 319592
  %17 = or i32 %14, %15
  store i32 %17, ptr %16, align 8, !tbaa !12
  %18 = getelementptr inbounds i8, ptr %4, i64 88
  %19 = load i64, ptr %18, align 8, !tbaa !21
  %20 = getelementptr inbounds i8, ptr %0, i64 319600
  store i64 %19, ptr %20, align 8, !tbaa !22
  %21 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull @.str.17)
  %.not15 = icmp eq ptr %21, null
  br i1 %.not15, label %28, label %.preheader

.preheader:                                       ; preds = %._crit_edge, %23
  %22 = call i64 @fread(ptr noundef nonnull %3, i64 noundef 1, i64 noundef 65536, ptr noundef nonnull %21)
  %.not16 = icmp eq i64 %22, 0
  br i1 %.not16, label %26, label %23

23:                                               ; preds = %.preheader
  %24 = call i32 @zip_entry_write(ptr noundef nonnull %0, ptr noundef nonnull %3, i64 noundef %22)
  %25 = icmp slt i32 %24, 0
  br i1 %25, label %26, label %.preheader, !llvm.loop !23

26:                                               ; preds = %23, %.preheader
  %.0 = phi i32 [ 0, %.preheader ], [ -8, %23 ]
  %27 = call i32 @fclose(ptr noundef nonnull %21)
  br label %28

28:                                               ; preds = %._crit_edge, %5, %2, %26
  %.011 = phi i32 [ %.0, %26 ], [ -1, %2 ], [ -3, %5 ], [ -16, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 65536, ptr nonnull %3) #4
  ret i32 %.011
}

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #3 = { 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 }

!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 24}
!6 = !{!"stat", !7, i64 0, !7, i64 8, !7, i64 16, !10, i64 24, !10, i64 28, !10, i64 32, !10, i64 36, !7, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !11, i64 72, !11, i64 88, !11, i64 104, !8, i64 120}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"timespec", !7, i64 0, !7, i64 8}
!12 = !{!13, !10, i64 319592}
!13 = !{!"zip_t", !14, i64 0, !10, i64 112, !17, i64 120}
!14 = !{!"", !15, i64 0, !15, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !15, i64 32, !16, i64 40, !16, i64 48, !16, i64 56, !16, i64 64, !16, i64 72, !16, i64 80, !16, i64 88, !16, i64 96, !16, i64 104}
!15 = !{!"long long", !8, i64 0}
!16 = !{!"any pointer", !8, i64 0}
!17 = !{!"zip_entry_t", !10, i64 0, !16, i64 8, !15, i64 16, !15, i64 24, !10, i64 32, !15, i64 40, !8, i64 48, !15, i64 80, !18, i64 88, !19, i64 96, !20, i64 120, !10, i64 319472, !7, i64 319480}
!18 = !{!"short", !8, i64 0}
!19 = !{!"", !16, i64 0, !15, i64 8, !15, i64 16}
!20 = !{!"", !16, i64 0, !16, i64 8, !10, i64 16, !8, i64 20, !10, i64 28, !10, i64 32, !10, i64 36, !10, i64 40, !10, i64 44, !16, i64 48, !16, i64 56, !16, i64 64, !16, 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, !16, i64 136, !16, i64 144, !16, i64 152, !16, i64 160, !10, i64 168, !16, 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}
!21 = !{!6, !7, i64 88}
!22 = !{!13, !7, i64 319600}
!23 = distinct !{!23, !24}
!24 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass