; 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_stream_s = type { ptr, i32, i64, ptr, i32, i64, ptr, ptr, ptr, ptr, ptr, i32, i64, i64 }

; 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 uwtable
declare dso_local i32 @mz_inflateInit(ptr noundef) #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mz_uncompress2(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #2 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.mz_stream_s, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 112, ptr %10) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  call void @llvm.memset.p0.i64(ptr align 8 %10, i8 0, i64 112, i1 false)
  %13 = load ptr, ptr %9, align 8, !tbaa !5
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = load i64, ptr %15, align 8, !tbaa !9
  %17 = or i64 %14, %16
  %18 = icmp ugt i64 %17, 4294967295
  br i1 %18, label %19, label %20

19:                                               ; preds = %4
  store i32 -10000, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %67

20:                                               ; preds = %4
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.mz_stream_s, ptr %10, i32 0, i32 0
  store ptr %21, ptr %22, align 8, !tbaa !11
  %23 = load ptr, ptr %9, align 8, !tbaa !5
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = trunc i64 %24 to i32
  %26 = getelementptr inbounds %struct.mz_stream_s, ptr %10, i32 0, i32 1
  store i32 %25, ptr %26, align 8, !tbaa !14
  %27 = load ptr, ptr %6, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mz_stream_s, ptr %10, i32 0, i32 3
  store ptr %27, ptr %28, align 8, !tbaa !15
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = load i64, ptr %29, align 8, !tbaa !9
  %31 = trunc i64 %30 to i32
  %32 = getelementptr inbounds %struct.mz_stream_s, ptr %10, i32 0, i32 4
  store i32 %31, ptr %32, align 8, !tbaa !16
  %33 = call i32 @mz_inflateInit(ptr noundef %10)
  store i32 %33, ptr %11, align 4, !tbaa !17
  %34 = load i32, ptr %11, align 4, !tbaa !17
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %20
  %37 = load i32, ptr %11, align 4, !tbaa !17
  store i32 %37, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %67

38:                                               ; preds = %20
  %39 = call i32 @mz_inflate(ptr noundef %10, i32 noundef 4)
  store i32 %39, ptr %11, align 4, !tbaa !17
  %40 = load ptr, ptr %9, align 8, !tbaa !5
  %41 = load i64, ptr %40, align 8, !tbaa !9
  %42 = getelementptr inbounds %struct.mz_stream_s, ptr %10, i32 0, i32 1
  %43 = load i32, ptr %42, align 8, !tbaa !14
  %44 = zext i32 %43 to i64
  %45 = sub i64 %41, %44
  %46 = load ptr, ptr %9, align 8, !tbaa !5
  store i64 %45, ptr %46, align 8, !tbaa !9
  %47 = load i32, ptr %11, align 4, !tbaa !17
  %48 = icmp ne i32 %47, 1
  br i1 %48, label %49, label %62

49:                                               ; preds = %38
  %50 = call i32 @mz_inflateEnd(ptr noundef %10)
  %51 = load i32, ptr %11, align 4, !tbaa !17
  %52 = icmp eq i32 %51, -5
  br i1 %52, label %53, label %58

53:                                               ; preds = %49
  %54 = getelementptr inbounds %struct.mz_stream_s, ptr %10, i32 0, i32 1
  %55 = load i32, ptr %54, align 8, !tbaa !14
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %58, label %57

57:                                               ; preds = %53
  br label %60

58:                                               ; preds = %53, %49
  %59 = load i32, ptr %11, align 4, !tbaa !17
  br label %60

60:                                               ; preds = %58, %57
  %61 = phi i32 [ -3, %57 ], [ %59, %58 ]
  store i32 %61, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %67

62:                                               ; preds = %38
  %63 = getelementptr inbounds %struct.mz_stream_s, ptr %10, i32 0, i32 5
  %64 = load i64, ptr %63, align 8, !tbaa !18
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %64, ptr %65, align 8, !tbaa !9
  %66 = call i32 @mz_inflateEnd(ptr noundef %10)
  store i32 %66, ptr %5, align 4
  store i32 1, ptr %12, align 4
  br label %67

67:                                               ; preds = %62, %60, %36, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 112, ptr %10) #3
  %68 = load i32, ptr %5, align 4
  ret i32 %68
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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, !6, i64 0}
!12 = !{!"mz_stream_s", !6, i64 0, !13, i64 8, !10, i64 16, !6, i64 24, !13, i64 32, !10, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !13, i64 88, !10, i64 96, !10, i64 104}
!13 = !{!"int", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!12, !6, i64 24}
!16 = !{!12, !13, i64 32}
!17 = !{!13, !13, i64 0}
!18 = !{!12, !10, i64 40}


; 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_stream_s = type { ptr, i32, i64, ptr, i32, i64, ptr, ptr, ptr, ptr, ptr, i32, i64, 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: 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_inflateInit(ptr noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mz_uncompress2(ptr noundef %0, ptr nocapture noundef %1, ptr noundef %2, ptr nocapture noundef %3) local_unnamed_addr #2 {
  %5 = alloca %struct.mz_stream_s, align 8
  call void @llvm.lifetime.start.p0(i64 112, ptr nonnull %5) #3
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(112) %6, i8 0, i64 104, i1 false)
  %7 = load i64, ptr %3, align 8, !tbaa !5
  %8 = load i64, ptr %1, align 8, !tbaa !5
  %9 = or i64 %8, %7
  %10 = icmp ugt i64 %9, 4294967295
  br i1 %10, label %34, label %11

11:                                               ; preds = %4
  store ptr %2, ptr %5, align 8, !tbaa !9
  %12 = trunc nuw i64 %7 to i32
  %13 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 %12, ptr %13, align 8, !tbaa !13
  %14 = getelementptr inbounds i8, ptr %5, i64 24
  store ptr %0, ptr %14, align 8, !tbaa !14
  %15 = trunc nuw i64 %8 to i32
  %16 = getelementptr inbounds i8, ptr %5, i64 32
  store i32 %15, ptr %16, align 8, !tbaa !15
  %17 = call i32 @mz_inflateInit(ptr noundef nonnull %5)
  %.not = icmp eq i32 %17, 0
  br i1 %.not, label %18, label %34

18:                                               ; preds = %11
  %19 = call i32 @mz_inflate(ptr noundef nonnull %5, i32 noundef 4)
  %20 = load i64, ptr %3, align 8, !tbaa !5
  %21 = load i32, ptr %13, align 8, !tbaa !13
  %22 = zext i32 %21 to i64
  %23 = sub i64 %20, %22
  store i64 %23, ptr %3, align 8, !tbaa !5
  %.not18 = icmp eq i32 %19, 1
  br i1 %.not18, label %30, label %24

24:                                               ; preds = %18
  %25 = call i32 @mz_inflateEnd(ptr noundef nonnull %5)
  %26 = icmp ne i32 %19, -5
  %27 = load i32, ptr %13, align 8
  %28 = icmp ne i32 %27, 0
  %or.cond = select i1 %26, i1 true, i1 %28
  %29 = select i1 %or.cond, i32 %19, i32 -3
  br label %34

30:                                               ; preds = %18
  %31 = getelementptr inbounds i8, ptr %5, i64 40
  %32 = load i64, ptr %31, align 8, !tbaa !16
  store i64 %32, ptr %1, align 8, !tbaa !5
  %33 = call i32 @mz_inflateEnd(ptr noundef nonnull %5)
  br label %34

34:                                               ; preds = %11, %4, %30, %24
  %.0 = phi i32 [ %29, %24 ], [ %33, %30 ], [ -10000, %4 ], [ %17, %11 ]
  call void @llvm.lifetime.end.p0(i64 112, ptr nonnull %5) #3
  ret i32 %.0
}

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 = { 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, !11, i64 0}
!10 = !{!"mz_stream_s", !11, i64 0, !12, i64 8, !6, i64 16, !11, i64 24, !12, i64 32, !6, i64 40, !11, i64 48, !11, i64 56, !11, i64 64, !11, i64 72, !11, i64 80, !12, i64 88, !6, i64 96, !6, i64 104}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 8}
!14 = !{!10, !11, i64 24}
!15 = !{!10, !12, i64 32}
!16 = !{!10, !6, i64 40}


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