; 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.mz_zip_archive = type { i64, i64, i32, i32, i32, i32, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%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.1 = external hidden unnamed_addr constant [1 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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local i32 @mz_zip_writer_end(ptr noundef) #3

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @mz_zip_writer_add_file(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i16 noundef zeroext, i32 noundef, i32 noundef) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @mz_zip_writer_finalize_archive(ptr noundef) #3

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

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

17:                                               ; preds = %3
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = call i64 @strlen(ptr noundef %18) #6
  %20 = icmp ult i64 %19, 1
  br i1 %20, label %21, label %22

21:                                               ; preds = %17, %3
  store i32 -22, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %84

22:                                               ; preds = %17
  call void @llvm.memset.p0.i64(ptr align 8 %10, i8 0, i64 112, i1 false)
  %23 = icmp ne ptr %10, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %22
  store i32 -7, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %84

25:                                               ; preds = %22
  %26 = load ptr, ptr %5, align 8, !tbaa !5
  %27 = call i32 @mz_zip_writer_init_file(ptr noundef %10, ptr noundef %26, i64 noundef 0)
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  store i32 -1, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %84

30:                                               ; preds = %25
  call void @llvm.memset.p0.i64(ptr align 8 %11, i8 0, i64 144, i1 false)
  %31 = icmp ne ptr %11, null
  br i1 %31, label %33, label %32

32:                                               ; preds = %30
  store i32 -7, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %84

33:                                               ; preds = %30
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %34

34:                                               ; preds = %77, %33
  %35 = load i64, ptr %9, align 8, !tbaa !9
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = icmp ult i64 %35, %36
  br i1 %37, label %38, label %80

38:                                               ; preds = %34
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = load i64, ptr %9, align 8, !tbaa !9
  %41 = getelementptr inbounds ptr, ptr %39, i64 %40
  %42 = load ptr, ptr %41, align 8, !tbaa !5
  store ptr %42, ptr %14, align 8, !tbaa !5
  %43 = load ptr, ptr %14, align 8, !tbaa !5
  %44 = icmp ne ptr %43, null
  br i1 %44, label %46, label %45

45:                                               ; preds = %38
  store i32 -2, ptr %8, align 4, !tbaa !11
  store i32 2, ptr %13, align 4
  br label %74

46:                                               ; preds = %38
  %47 = load ptr, ptr %14, align 8, !tbaa !5
  %48 = call i32 @stat(ptr noundef %47, ptr noundef %11) #5
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %51

50:                                               ; preds = %46
  store i32 -19, ptr %8, align 4, !tbaa !11
  store i32 2, ptr %13, align 4
  br label %74

51:                                               ; preds = %46
  %52 = getelementptr inbounds %struct.stat, ptr %11, i32 0, i32 3
  %53 = load i32, ptr %52, align 8, !tbaa !13
  %54 = and i32 %53, 128
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %59

56:                                               ; preds = %51
  %57 = load i32, ptr %12, align 4, !tbaa !11
  %58 = or i32 %57, 1
  store i32 %58, ptr %12, align 4, !tbaa !11
  br label %59

59:                                               ; preds = %56, %51
  %60 = getelementptr inbounds %struct.stat, ptr %11, i32 0, i32 3
  %61 = load i32, ptr %60, align 8, !tbaa !13
  %62 = and i32 %61, 65535
  %63 = shl i32 %62, 16
  %64 = load i32, ptr %12, align 4, !tbaa !11
  %65 = or i32 %64, %63
  store i32 %65, ptr %12, align 4, !tbaa !11
  %66 = load ptr, ptr %14, align 8, !tbaa !5
  %67 = call ptr @zip_basename(ptr noundef %66)
  %68 = load ptr, ptr %14, align 8, !tbaa !5
  %69 = load i32, ptr %12, align 4, !tbaa !11
  %70 = call i32 @mz_zip_writer_add_file(ptr noundef %10, ptr noundef %67, ptr noundef %68, ptr noundef @.str.1, i16 noundef zeroext 0, i32 noundef 6, i32 noundef %69)
  %71 = icmp ne i32 %70, 0
  br i1 %71, label %73, label %72

72:                                               ; preds = %59
  store i32 -19, ptr %8, align 4, !tbaa !11
  store i32 2, ptr %13, align 4
  br label %74

73:                                               ; preds = %59
  store i32 0, ptr %13, align 4
  br label %74

74:                                               ; preds = %73, %72, %50, %45
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  %75 = load i32, ptr %13, align 4
  switch i32 %75, label %86 [
    i32 0, label %76
    i32 2, label %80
  ]

76:                                               ; preds = %74
  br label %77

77:                                               ; preds = %76
  %78 = load i64, ptr %9, align 8, !tbaa !9
  %79 = add i64 %78, 1
  store i64 %79, ptr %9, align 8, !tbaa !9
  br label %34, !llvm.loop !16

80:                                               ; preds = %74, %34
  %81 = call i32 @mz_zip_writer_finalize_archive(ptr noundef %10)
  %82 = call i32 @mz_zip_writer_end(ptr noundef %10)
  %83 = load i32, ptr %8, align 4, !tbaa !11
  store i32 %83, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %84

84:                                               ; preds = %80, %32, %29, %24, %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 144, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 112, ptr %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  %85 = load i32, ptr %4, align 4
  ret i32 %85

86:                                               ; preds = %74
  unreachable
}

; Function Attrs: nounwind uwtable
declare hidden ptr @zip_basename(ptr noundef) #3

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

!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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !12, i64 24}
!14 = !{!"stat", !10, i64 0, !10, i64 8, !10, i64 16, !12, i64 24, !12, i64 28, !12, i64 32, !12, i64 36, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !15, i64 72, !15, i64 88, !15, i64 104, !7, i64 120}
!15 = !{!"timespec", !10, i64 0, !10, i64 8}
!16 = distinct !{!16, !17}
!17 = !{!"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.mz_zip_archive = type { i64, i64, i32, i32, i32, i32, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%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.1 = external hidden unnamed_addr constant [1 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: nounwind uwtable
declare dso_local i32 @mz_zip_writer_end(ptr noundef) local_unnamed_addr #2

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -22, 1) i32 @zip_create(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #2 {
  %4 = alloca %struct.mz_zip_archive, align 8
  %5 = alloca %struct.stat, align 8
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 144, ptr nonnull %5) #4
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %29, label %6

6:                                                ; preds = %3
  %char0 = load i8, ptr %0, align 1
  %7 = icmp eq i8 %char0, 0
  br i1 %7, label %29, label %8

8:                                                ; preds = %6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(112) %4, i8 0, i64 112, i1 false)
  %9 = call i32 @mz_zip_writer_init_file(ptr noundef nonnull %4, ptr noundef nonnull %0, i64 noundef 0)
  %.not25 = icmp eq i32 %9, 0
  br i1 %.not25, label %29, label %10

10:                                               ; preds = %8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(144) %5, i8 0, i64 144, i1 false)
  %11 = getelementptr inbounds i8, ptr %5, i64 24
  %.not43 = icmp eq i64 %2, 0
  br i1 %.not43, label %.thread, label %.lr.ph

12:                                               ; preds = %18
  %13 = add nuw i64 %.01935, 1
  %exitcond.not = icmp eq i64 %13, %2
  br i1 %exitcond.not, label %.thread, label %.lr.ph, !llvm.loop !5

.lr.ph:                                           ; preds = %10, %12
  %.01836 = phi i32 [ %24, %12 ], [ 0, %10 ]
  %.01935 = phi i64 [ %13, %12 ], [ 0, %10 ]
  %14 = getelementptr inbounds ptr, ptr %1, i64 %.01935
  %15 = load ptr, ptr %14, align 8, !tbaa !7
  %.not26 = icmp eq ptr %15, null
  br i1 %.not26, label %.thread, label %16

16:                                               ; preds = %.lr.ph
  %17 = call i32 @stat(ptr noundef nonnull %15, ptr noundef nonnull %5) #4
  %.not27 = icmp eq i32 %17, 0
  br i1 %.not27, label %18, label %.thread

18:                                               ; preds = %16
  %19 = load i32, ptr %11, align 8, !tbaa !11
  %20 = lshr i32 %19, 7
  %21 = and i32 %20, 1
  %22 = xor i32 %21, 1
  %23 = shl i32 %19, 16
  %spec.select = or i32 %23, %.01836
  %24 = or i32 %spec.select, %22
  %25 = call ptr @zip_basename(ptr noundef nonnull %15)
  %26 = call i32 @mz_zip_writer_add_file(ptr noundef nonnull %4, ptr noundef %25, ptr noundef nonnull %15, ptr noundef nonnull @.str.1, i16 noundef zeroext 0, i32 noundef 6, i32 noundef %24)
  %.not28 = icmp eq i32 %26, 0
  br i1 %.not28, label %.thread, label %12

.thread:                                          ; preds = %12, %.lr.ph, %16, %18, %10
  %.222 = phi i32 [ 0, %10 ], [ -19, %18 ], [ -19, %16 ], [ -2, %.lr.ph ], [ 0, %12 ]
  %27 = call i32 @mz_zip_writer_finalize_archive(ptr noundef nonnull %4)
  %28 = call i32 @mz_zip_writer_end(ptr noundef nonnull %4)
  br label %29

29:                                               ; preds = %8, %3, %6, %.thread
  %.0 = phi i32 [ %.222, %.thread ], [ -22, %6 ], [ -22, %3 ], [ -1, %8 ]
  call void @llvm.lifetime.end.p0(i64 144, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %4) #4
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden ptr @zip_basename(ptr noundef) local_unnamed_addr #2

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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !8, i64 0}
!8 = !{!"any pointer", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!12, !14, i64 24}
!12 = !{!"stat", !13, i64 0, !13, i64 8, !13, i64 16, !14, i64 24, !14, i64 28, !14, i64 32, !14, i64 36, !13, i64 40, !13, i64 48, !13, i64 56, !13, i64 64, !15, i64 72, !15, i64 88, !15, i64 104, !9, i64 120}
!13 = !{!"long", !9, i64 0}
!14 = !{!"int", !9, i64 0}
!15 = !{!"timespec", !13, i64 0, !13, i64 8}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass