; LLVM IR from taichi-dev/taichi :: taichi/common (miniz)

; 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.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 }

@.str.19 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [4 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: alwaysinline nounwind uwtable
declare hidden i32 @mz_zip_set_error(ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden i64 @mz_zip_file_read_func(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #4

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mz_zip_writer_init_file_v2(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) #4 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca [4096 x i8], align 16
  %14 = alloca i64, align 8
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.mz_zip_archive, ptr %15, i32 0, i32 12
  store ptr @mz_zip_file_write_func, ptr %16, align 8, !tbaa !13
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mz_zip_archive, ptr %17, i32 0, i32 13
  store ptr null, ptr %18, align 8, !tbaa !15
  %19 = load i32, ptr %9, align 4, !tbaa !11
  %20 = and i32 %19, 32768
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %25

22:                                               ; preds = %4
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.mz_zip_archive, ptr %23, i32 0, i32 11
  store ptr @mz_zip_file_read_func, ptr %24, align 8, !tbaa !16
  br label %25

25:                                               ; preds = %22, %4
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mz_zip_archive, ptr %27, i32 0, i32 14
  store ptr %26, ptr %28, align 8, !tbaa !17
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load i64, ptr %8, align 8, !tbaa !9
  %31 = load i32, ptr %9, align 4, !tbaa !11
  %32 = call i32 @mz_zip_writer_init_v2(ptr noundef %29, i64 noundef %30, i32 noundef %31)
  %33 = icmp ne i32 %32, 0
  br i1 %33, label %35, label %34

34:                                               ; preds = %25
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %104

35:                                               ; preds = %25
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = load i32, ptr %9, align 4, !tbaa !11
  %38 = and i32 %37, 32768
  %39 = icmp ne i32 %38, 0
  %40 = zext i1 %39 to i64
  %41 = select i1 %39, ptr @.str.20, ptr @.str.19
  %42 = call noalias ptr @fopen(ptr noundef %36, ptr noundef %41)
  store ptr %42, ptr %10, align 8, !tbaa !5
  %43 = icmp eq ptr null, %42
  br i1 %43, label %44, label %49

44:                                               ; preds = %35
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = call i32 @mz_zip_writer_end(ptr noundef %45)
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = call i32 @mz_zip_set_error(ptr noundef %47, i32 noundef 17)
  store i32 %48, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %104

49:                                               ; preds = %35
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = load ptr, ptr %6, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.mz_zip_archive, ptr %51, i32 0, i32 15
  %53 = load ptr, ptr %52, align 8, !tbaa !18
  %54 = getelementptr inbounds %struct.mz_zip_internal_state_tag, ptr %53, i32 0, i32 6
  store ptr %50, ptr %54, align 8, !tbaa !19
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.mz_zip_archive, ptr %55, i32 0, i32 4
  store i32 4, ptr %56, align 8, !tbaa !22
  %57 = load i64, ptr %8, align 8, !tbaa !9
  %58 = icmp ne i64 %57, 0
  br i1 %58, label %59, label %103

59:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  store i64 0, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4096, ptr %13) #5
  %60 = getelementptr inbounds [4096 x i8], ptr %13, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %60, i8 0, i64 4096, i1 false)
  br label %61

61:                                               ; preds = %96, %59
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #5
  %62 = load i64, ptr %8, align 8, !tbaa !9
  %63 = icmp ult i64 4096, %62
  br i1 %63, label %64, label %65

64:                                               ; preds = %61
  br label %67

65:                                               ; preds = %61
  %66 = load i64, ptr %8, align 8, !tbaa !9
  br label %67

67:                                               ; preds = %65, %64
  %68 = phi i64 [ 4096, %64 ], [ %66, %65 ]
  store i64 %68, ptr %14, align 8, !tbaa !9
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.mz_zip_archive, ptr %69, i32 0, i32 12
  %71 = load ptr, ptr %70, align 8, !tbaa !13
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.mz_zip_archive, ptr %72, i32 0, i32 14
  %74 = load ptr, ptr %73, align 8, !tbaa !17
  %75 = load i64, ptr %12, align 8, !tbaa !9
  %76 = getelementptr inbounds [4096 x i8], ptr %13, i64 0, i64 0
  %77 = load i64, ptr %14, align 8, !tbaa !9
  %78 = call i64 %71(ptr noundef %74, i64 noundef %75, ptr noundef %76, i64 noundef %77)
  %79 = load i64, ptr %14, align 8, !tbaa !9
  %80 = icmp ne i64 %78, %79
  br i1 %80, label %81, label %86

81:                                               ; preds = %67
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = call i32 @mz_zip_writer_end(ptr noundef %82)
  %84 = load ptr, ptr %6, align 8, !tbaa !5
  %85 = call i32 @mz_zip_set_error(ptr noundef %84, i32 noundef 19)
  store i32 %85, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %93

86:                                               ; preds = %67
  %87 = load i64, ptr %14, align 8, !tbaa !9
  %88 = load i64, ptr %12, align 8, !tbaa !9
  %89 = add i64 %88, %87
  store i64 %89, ptr %12, align 8, !tbaa !9
  %90 = load i64, ptr %14, align 8, !tbaa !9
  %91 = load i64, ptr %8, align 8, !tbaa !9
  %92 = sub i64 %91, %90
  store i64 %92, ptr %8, align 8, !tbaa !9
  store i32 0, ptr %11, align 4
  br label %93

93:                                               ; preds = %86, %81
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #5
  %94 = load i32, ptr %11, align 4
  switch i32 %94, label %100 [
    i32 0, label %95
  ]

95:                                               ; preds = %93
  br label %96

96:                                               ; preds = %95
  %97 = load i64, ptr %8, align 8, !tbaa !9
  %98 = icmp ne i64 %97, 0
  br i1 %98, label %61, label %99, !llvm.loop !23

99:                                               ; preds = %96
  store i32 0, ptr %11, align 4
  br label %100

100:                                              ; preds = %99, %93
  call void @llvm.lifetime.end.p0(i64 4096, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  %101 = load i32, ptr %11, align 4
  switch i32 %101, label %104 [
    i32 0, label %102
  ]

102:                                              ; preds = %100
  br label %103

103:                                              ; preds = %102, %49
  store i32 1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %104

104:                                              ; preds = %103, %100, %44, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %105 = load i32, ptr %5, align 4
  ret i32 %105
}

; Function Attrs: nounwind uwtable
declare hidden i64 @mz_zip_file_write_func(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #4

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { alwaysinline 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 = { "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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 80}
!14 = !{!"", !10, i64 0, !10, i64 8, !12, i64 16, !12, i64 20, !12, i64 24, !12, i64 28, !10, 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 = !{!14, !6, i64 88}
!16 = !{!14, !6, i64 72}
!17 = !{!14, !6, i64 96}
!18 = !{!14, !6, i64 104}
!19 = !{!20, !6, i64 112}
!20 = !{!"mz_zip_internal_state_tag", !21, i64 0, !21, i64 32, !21, i64 64, !12, i64 96, !12, i64 100, !12, i64 104, !6, i64 112, !10, i64 120, !6, i64 128, !10, i64 136, !10, i64 144}
!21 = !{!"", !6, i64 0, !10, i64 8, !10, i64 16, !12, i64 24}
!22 = !{!14, !12, i64 24}
!23 = distinct !{!23, !24}
!24 = !{!"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"

@.str.19 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.20 = external hidden unnamed_addr constant [4 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: alwaysinline nounwind uwtable
declare hidden i32 @mz_zip_set_error(ptr noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare hidden i64 @mz_zip_file_read_func(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #4

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mz_zip_writer_init_file_v2(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #4 {
  %5 = alloca [4096 x i8], align 16
  %6 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr @mz_zip_file_write_func, ptr %6, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 88
  store ptr null, ptr %7, align 8, !tbaa !12
  %8 = and i32 %3, 32768
  %.not = icmp eq i32 %8, 0
  br i1 %.not, label %11, label %9

9:                                                ; preds = %4
  %10 = getelementptr inbounds i8, ptr %0, i64 72
  store ptr @mz_zip_file_read_func, ptr %10, align 8, !tbaa !13
  br label %11

11:                                               ; preds = %9, %4
  %12 = getelementptr inbounds i8, ptr %0, i64 96
  store ptr %0, ptr %12, align 8, !tbaa !14
  %13 = tail call i32 @mz_zip_writer_init_v2(ptr noundef nonnull %0, i64 noundef %2, i32 noundef %3)
  %.not43 = icmp eq i32 %13, 0
  br i1 %.not43, label %38, label %14

14:                                               ; preds = %11
  %15 = select i1 %.not, ptr @.str.19, ptr @.str.20
  %16 = tail call noalias ptr @fopen(ptr noundef %1, ptr noundef nonnull %15)
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %21

18:                                               ; preds = %14
  %19 = tail call i32 @mz_zip_writer_end(ptr noundef nonnull %0)
  %20 = tail call i32 @mz_zip_set_error(ptr noundef nonnull %0, i32 noundef 17)
  br label %38

21:                                               ; preds = %14
  %22 = getelementptr inbounds i8, ptr %0, i64 104
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = getelementptr inbounds i8, ptr %23, i64 112
  store ptr %16, ptr %24, align 8, !tbaa !16
  %25 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 4, ptr %25, align 8, !tbaa !19
  %.not44 = icmp eq i64 %2, 0
  br i1 %.not44, label %38, label %26

26:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %5) #6
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4096) %5, i8 0, i64 4096, i1 false)
  br label %27

27:                                               ; preds = %32, %26
  %.038 = phi i64 [ %2, %26 ], [ %34, %32 ]
  %.034 = phi i64 [ 0, %26 ], [ %33, %32 ]
  %28 = call i64 @llvm.umin.i64(i64 %.038, i64 4096)
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = load ptr, ptr %12, align 8, !tbaa !14
  %31 = call i64 %29(ptr noundef %30, i64 noundef %.034, ptr noundef nonnull %5, i64 noundef %28) #6
  %.not45 = icmp eq i64 %31, %28
  br i1 %.not45, label %32, label %.critedge

32:                                               ; preds = %27
  %33 = add i64 %.034, %28
  %34 = sub i64 %.038, %28
  %.not46 = icmp eq i64 %34, 0
  br i1 %.not46, label %35, label %27, !llvm.loop !20

35:                                               ; preds = %32
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %5) #6
  br label %38

.critedge:                                        ; preds = %27
  %36 = call i32 @mz_zip_writer_end(ptr noundef nonnull %0)
  %37 = call i32 @mz_zip_set_error(ptr noundef nonnull %0, i32 noundef 19)
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %5) #6
  br label %38

38:                                               ; preds = %21, %35, %.critedge, %11, %18
  %.2 = phi i32 [ %20, %18 ], [ 0, %11 ], [ %37, %.critedge ], [ 1, %35 ], [ 1, %21 ]
  ret i32 %.2
}

; Function Attrs: nounwind uwtable
declare hidden i64 @mz_zip_file_write_func(ptr noundef, i64 noundef, ptr noundef, i64 noundef) #4

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #5

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { alwaysinline 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 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { 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 80}
!6 = !{!"", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, i64 28, !7, i64 32, !11, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !11, i64 88, !11, i64 96, !11, i64 104}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !11, i64 88}
!13 = !{!6, !11, i64 72}
!14 = !{!6, !11, i64 96}
!15 = !{!6, !11, i64 104}
!16 = !{!17, !11, i64 112}
!17 = !{!"mz_zip_internal_state_tag", !18, i64 0, !18, i64 32, !18, i64 64, !10, i64 96, !10, i64 100, !10, i64 104, !11, i64 112, !7, i64 120, !11, i64 128, !7, i64 136, !7, i64 144}
!18 = !{!"", !11, i64 0, !7, i64 8, !7, i64 16, !10, i64 24}
!19 = !{!6, !10, i64 24}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}


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