; 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
declare void @free(ptr noundef) #1

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

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

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

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

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

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

12:                                               ; preds = %3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = call i64 @strlen(ptr noundef %13) #6
  %15 = icmp ult i64 %14, 1
  br i1 %15, label %16, label %17

16:                                               ; preds = %12, %3
  br label %78

17:                                               ; preds = %12
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17
  store i32 6, ptr %6, align 4, !tbaa !9
  br label %21

21:                                               ; preds = %20, %17
  %22 = load i32, ptr %6, align 4, !tbaa !9
  %23 = and i32 %22, 15
  %24 = icmp sgt i32 %23, 10
  br i1 %24, label %25, label %26

25:                                               ; preds = %21
  br label %78

26:                                               ; preds = %21
  %27 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 319608) #7
  store ptr %27, ptr %8, align 8, !tbaa !5
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = icmp ne ptr %28, null
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  br label %78

31:                                               ; preds = %26
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = load ptr, ptr %8, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.zip_t, ptr %33, i32 0, i32 1
  store i32 %32, ptr %34, align 8, !tbaa !12
  %35 = load i8, ptr %7, align 1, !tbaa !11
  %36 = sext i8 %35 to i32
  switch i32 %36, label %75 [
    i32 119, label %37
    i32 114, label %45
    i32 97, label %45
    i32 100, label %45
  ]

37:                                               ; preds = %31
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.zip_t, ptr %38, i32 0, i32 0
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = call i32 @mz_zip_writer_init_file(ptr noundef %39, ptr noundef %40, i64 noundef 0)
  %42 = icmp ne i32 %41, 0
  br i1 %42, label %44, label %43

43:                                               ; preds = %37
  br label %78

44:                                               ; preds = %37
  br label %76

45:                                               ; preds = %31, %31, %31
  %46 = load ptr, ptr %8, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.zip_t, ptr %46, i32 0, i32 0
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.zip_t, ptr %49, i32 0, i32 1
  %51 = load i32, ptr %50, align 8, !tbaa !12
  %52 = or i32 %51, 2048
  %53 = call i32 @mz_zip_reader_init_file(ptr noundef %47, ptr noundef %48, i32 noundef %52)
  %54 = icmp ne i32 %53, 0
  br i1 %54, label %56, label %55

55:                                               ; preds = %45
  br label %78

56:                                               ; preds = %45
  %57 = load i8, ptr %7, align 1, !tbaa !11
  %58 = sext i8 %57 to i32
  %59 = icmp eq i32 %58, 97
  br i1 %59, label %64, label %60

60:                                               ; preds = %56
  %61 = load i8, ptr %7, align 1, !tbaa !11
  %62 = sext i8 %61 to i32
  %63 = icmp eq i32 %62, 100
  br i1 %63, label %64, label %74

64:                                               ; preds = %60, %56
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.zip_t, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %5, align 8, !tbaa !5
  %68 = call i32 @mz_zip_writer_init_from_reader(ptr noundef %66, ptr noundef %67)
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %74, label %70

70:                                               ; preds = %64
  %71 = load ptr, ptr %8, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.zip_t, ptr %71, i32 0, i32 0
  %73 = call i32 @mz_zip_reader_end(ptr noundef %72)
  br label %78

74:                                               ; preds = %64, %60
  br label %76

75:                                               ; preds = %31
  br label %78

76:                                               ; preds = %74, %44
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %77, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %87

78:                                               ; preds = %75, %70, %55, %43, %30, %25, %16
  br label %79

79:                                               ; preds = %78
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = icmp ne ptr %80, null
  br i1 %81, label %82, label %84

82:                                               ; preds = %79
  %83 = load ptr, ptr %8, align 8, !tbaa !5
  call void @free(ptr noundef %83) #5
  store ptr null, ptr %8, align 8, !tbaa !5
  br label %84

84:                                               ; preds = %82, %79
  br label %85

85:                                               ; preds = %84
  br label %86

86:                                               ; preds = %85
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %87

87:                                               ; preds = %86, %76
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #5
  %88 = load ptr, ptr %4, align 8
  ret ptr %88
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind willreturn memory(read) }
attributes #7 = { 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !10, i64 112}
!13 = !{!"zip_t", !14, i64 0, !10, i64 112, !16, i64 120}
!14 = !{!"", !15, i64 0, !15, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !15, 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}
!15 = !{!"long long", !7, i64 0}
!16 = !{!"zip_entry_t", !10, i64 0, !6, i64 8, !15, i64 16, !15, i64 24, !10, i64 32, !15, i64 40, !7, i64 48, !15, i64 80, !17, i64 88, !18, i64 96, !19, i64 120, !10, i64 319472, !20, i64 319480}
!17 = !{!"short", !7, i64 0}
!18 = !{!"", !6, i64 0, !15, i64 8, !15, 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, !20, i64 184, !20, 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 = !{!"long", !7, i64 0}


; 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 nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #0

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @zip_open(ptr noundef %0, i32 noundef %1, i8 noundef signext %2) local_unnamed_addr #1 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.thread, label %4

4:                                                ; preds = %3
  %char0 = load i8, ptr %0, align 1
  %5 = icmp eq i8 %char0, 0
  br i1 %5, label %.thread, label %6

6:                                                ; preds = %4
  %7 = icmp slt i32 %1, 0
  %spec.store.select = select i1 %7, i32 6, i32 %1
  %8 = and i32 %spec.store.select, 15
  %9 = icmp ugt i32 %8, 10
  br i1 %9, label %.thread, label %10

10:                                               ; preds = %6
  %11 = tail call noalias dereferenceable_or_null(319608) ptr @calloc(i64 noundef 1, i64 noundef 319608) #3
  %.not26 = icmp eq ptr %11, null
  br i1 %.not26, label %.thread, label %12

12:                                               ; preds = %10
  %13 = getelementptr inbounds i8, ptr %11, i64 112
  store i32 %spec.store.select, ptr %13, align 8, !tbaa !5
  switch i8 %2, label %24 [
    i8 119, label %14
    i8 114, label %16
    i8 97, label %16
    i8 100, label %16
  ]

14:                                               ; preds = %12
  %15 = tail call i32 @mz_zip_writer_init_file(ptr noundef nonnull %11, ptr noundef nonnull %0, i64 noundef 0)
  %.not29 = icmp eq i32 %15, 0
  br i1 %.not29, label %24, label %.thread

16:                                               ; preds = %12, %12, %12
  %17 = or i32 %spec.store.select, 2048
  %18 = tail call i32 @mz_zip_reader_init_file(ptr noundef nonnull %11, ptr noundef nonnull %0, i32 noundef %17)
  %.not27 = icmp eq i32 %18, 0
  br i1 %.not27, label %24, label %19

19:                                               ; preds = %16
  switch i8 %2, label %.thread [
    i8 100, label %20
    i8 97, label %20
  ]

20:                                               ; preds = %19, %19
  %21 = tail call i32 @mz_zip_writer_init_from_reader(ptr noundef nonnull %11, ptr noundef nonnull %0)
  %.not28 = icmp eq i32 %21, 0
  br i1 %.not28, label %22, label %.thread

22:                                               ; preds = %20
  %23 = tail call i32 @mz_zip_reader_end(ptr noundef nonnull %11)
  br label %24

24:                                               ; preds = %12, %16, %14, %22
  tail call void @free(ptr noundef nonnull %11) #4
  br label %.thread

.thread:                                          ; preds = %3, %10, %6, %4, %24, %14, %20, %19
  %.023 = phi ptr [ %11, %19 ], [ %11, %20 ], [ %11, %14 ], [ null, %24 ], [ null, %4 ], [ null, %6 ], [ null, %10 ], [ null, %3 ]
  ret ptr %.023
}

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

attributes #0 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, 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 #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 = { 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 #3 = { nounwind allocsize(0,1) }
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, !11, i64 112}
!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}


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