; 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_file_stat = type { i32, i64, i16, i16, i16, i16, i32, i64, i64, i16, i32, i64, i32, i32, i32, i32, [512 x i8], [512 x i8], i64 }
%struct.mz_zip_archive = type { i64, i64, i32, i32, i32, i32, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; 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: alwaysinline nounwind uwtable
declare hidden i32 @mz_zip_set_error(ptr noundef, i32 noundef) #1

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

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

16:                                               ; preds = %4
  %17 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 0, ptr %17, align 8, !tbaa !11
  br label %18

18:                                               ; preds = %16, %4
  %19 = load ptr, ptr %6, align 8, !tbaa !5
  %20 = load i32, ptr %7, align 4, !tbaa !9
  %21 = call i32 @mz_zip_reader_file_stat(ptr noundef %19, i32 noundef %20, ptr noundef %10)
  %22 = icmp ne i32 %21, 0
  br i1 %22, label %24, label %23

23:                                               ; preds = %18
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %72

24:                                               ; preds = %18
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = and i32 %25, 1024
  %27 = icmp ne i32 %26, 0
  br i1 %27, label %28, label %31

28:                                               ; preds = %24
  %29 = getelementptr inbounds %struct.mz_zip_archive_file_stat, ptr %10, i32 0, i32 7
  %30 = load i64, ptr %29, align 8, !tbaa !13
  br label %34

31:                                               ; preds = %24
  %32 = getelementptr inbounds %struct.mz_zip_archive_file_stat, ptr %10, i32 0, i32 8
  %33 = load i64, ptr %32, align 8, !tbaa !16
  br label %34

34:                                               ; preds = %31, %28
  %35 = phi i64 [ %30, %28 ], [ %33, %31 ]
  store i64 %35, ptr %11, align 8, !tbaa !11
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.mz_zip_archive, ptr %36, i32 0, i32 7
  %38 = load ptr, ptr %37, align 8, !tbaa !17
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.mz_zip_archive, ptr %39, i32 0, i32 10
  %41 = load ptr, ptr %40, align 8, !tbaa !19
  %42 = load i64, ptr %11, align 8, !tbaa !11
  %43 = call ptr %38(ptr noundef %41, i64 noundef 1, i64 noundef %42)
  store ptr %43, ptr %12, align 8, !tbaa !5
  %44 = icmp eq ptr null, %43
  br i1 %44, label %45, label %48

45:                                               ; preds = %34
  %46 = load ptr, ptr %6, align 8, !tbaa !5
  %47 = call i32 @mz_zip_set_error(ptr noundef %46, i32 noundef 16)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %72

48:                                               ; preds = %34
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = load i32, ptr %7, align 4, !tbaa !9
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  %52 = load i64, ptr %11, align 8, !tbaa !11
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = call i32 @mz_zip_reader_extract_to_mem_no_alloc1(ptr noundef %49, i32 noundef %50, ptr noundef %51, i64 noundef %52, i32 noundef %53, ptr noundef null, i64 noundef 0, ptr noundef %10)
  %55 = icmp ne i32 %54, 0
  br i1 %55, label %64, label %56

56:                                               ; preds = %48
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.mz_zip_archive, ptr %57, i32 0, i32 8
  %59 = load ptr, ptr %58, align 8, !tbaa !20
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.mz_zip_archive, ptr %60, i32 0, i32 10
  %62 = load ptr, ptr %61, align 8, !tbaa !19
  %63 = load ptr, ptr %12, align 8, !tbaa !5
  call void %59(ptr noundef %62, ptr noundef %63)
  store ptr null, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %72

64:                                               ; preds = %48
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %70

67:                                               ; preds = %64
  %68 = load i64, ptr %11, align 8, !tbaa !11
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  store i64 %68, ptr %69, align 8, !tbaa !11
  br label %70

70:                                               ; preds = %67, %64
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  store ptr %71, ptr %5, align 8
  store i32 1, ptr %13, align 4
  br label %72

72:                                               ; preds = %70, %56, %45, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 1112, ptr %10) #3
  %73 = load ptr, ptr %5, align 8
  ret ptr %73
}

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

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

!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, !12, i64 32}
!14 = !{!"", !10, i64 0, !12, i64 8, !15, i64 16, !15, i64 18, !15, i64 20, !15, i64 22, !10, i64 24, !12, i64 32, !12, i64 40, !15, i64 48, !10, i64 52, !12, i64 56, !10, i64 64, !10, i64 68, !10, i64 72, !10, i64 76, !7, i64 80, !7, i64 592, !12, i64 1104}
!15 = !{!"short", !7, i64 0}
!16 = !{!14, !12, i64 40}
!17 = !{!18, !6, i64 40}
!18 = !{!"", !12, i64 0, !12, i64 8, !10, i64 16, !10, i64 20, !10, i64 24, !10, 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}
!19 = !{!18, !6, i64 64}
!20 = !{!18, !6, i64 48}


; 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_file_stat = type { i32, i64, i16, i16, i16, i16, i32, i64, i64, i16, i32, i64, i32, i32, i32, i32, [512 x i8], [512 x i8], i64 }

; 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: alwaysinline nounwind uwtable
declare hidden i32 @mz_zip_set_error(ptr noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local ptr @mz_zip_reader_extract_to_heap(ptr noundef %0, i32 noundef %1, ptr noundef writeonly %2, i32 noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.mz_zip_archive_file_stat, align 8
  call void @llvm.lifetime.start.p0(i64 1112, ptr nonnull %5) #3
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %7, label %6

6:                                                ; preds = %4
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %7

7:                                                ; preds = %6, %4
  %8 = call i32 @mz_zip_reader_file_stat(ptr noundef %0, i32 noundef %1, ptr noundef nonnull %5)
  %.not23 = icmp eq i32 %8, 0
  br i1 %.not23, label %32, label %9

9:                                                ; preds = %7
  %10 = and i32 %3, 1024
  %.not24 = icmp eq i32 %10, 0
  %11 = getelementptr inbounds i8, ptr %5, i64 32
  %12 = load i64, ptr %11, align 8
  %13 = getelementptr inbounds i8, ptr %5, i64 40
  %14 = load i64, ptr %13, align 8
  %15 = select i1 %.not24, i64 %14, i64 %12
  %16 = getelementptr inbounds i8, ptr %0, i64 40
  %17 = load ptr, ptr %16, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %0, i64 64
  %19 = load ptr, ptr %18, align 8, !tbaa !13
  %20 = call ptr %17(ptr noundef %19, i64 noundef 1, i64 noundef %15) #3
  %21 = icmp eq ptr %20, null
  br i1 %21, label %22, label %24

22:                                               ; preds = %9
  %23 = call i32 @mz_zip_set_error(ptr noundef nonnull %0, i32 noundef 16)
  br label %32

24:                                               ; preds = %9
  %25 = call i32 @mz_zip_reader_extract_to_mem_no_alloc1(ptr noundef nonnull %0, i32 noundef %1, ptr noundef nonnull %20, i64 noundef %15, i32 noundef %3, ptr noundef null, i64 noundef 0, ptr noundef nonnull %5)
  %.not25 = icmp eq i32 %25, 0
  br i1 %.not25, label %26, label %30

26:                                               ; preds = %24
  %27 = getelementptr inbounds i8, ptr %0, i64 48
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = load ptr, ptr %18, align 8, !tbaa !13
  call void %28(ptr noundef %29, ptr noundef nonnull %20) #3
  br label %32

30:                                               ; preds = %24
  br i1 %.not, label %32, label %31

31:                                               ; preds = %30
  store i64 %15, ptr %2, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %30, %31, %7, %26, %22
  %.0 = phi ptr [ null, %22 ], [ null, %26 ], [ null, %7 ], [ %20, %31 ], [ %20, %30 ]
  call void @llvm.lifetime.end.p0(i64 1112, ptr nonnull %5) #3
  ret ptr %.0
}

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

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

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !12, i64 40}
!10 = !{!"", !6, i64 0, !6, i64 8, !11, i64 16, !11, i64 20, !11, i64 24, !11, i64 28, !6, 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}
!11 = !{!"int", !7, i64 0}
!12 = !{!"any pointer", !7, i64 0}
!13 = !{!10, !12, i64 64}
!14 = !{!10, !12, i64 48}


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