; LLVM IR from mkazhdan/DMG :: Util/ZLIB (infblock)

; 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.z_stream_s = type { ptr, i32, i64, ptr, i32, i64, ptr, ptr, ptr, ptr, ptr, i32, i64, i64 }
%struct.inflate_blocks_state = type { i32, %union.anon, i32, i32, i64, ptr, ptr, ptr, ptr, ptr, ptr, i64 }
%union.anon = type { %struct.anon }
%struct.anon = type { i32, i32, ptr, i32, ptr }

; Function Attrs: nounwind uwtable
declare dso_local void @inflate_blocks_reset(ptr noundef, ptr noundef, ptr noundef) #0

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

18:                                               ; preds = %3
  %19 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %19, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %85

20:                                               ; preds = %3
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.z_stream_s, ptr %21, i32 0, i32 8
  %23 = load ptr, ptr %22, align 8, !tbaa !11
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.z_stream_s, ptr %24, i32 0, i32 10
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = call ptr %23(ptr noundef %26, i32 noundef 8, i32 noundef 1440)
  %28 = load ptr, ptr %8, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.inflate_blocks_state, ptr %28, i32 0, i32 5
  store ptr %27, ptr %29, align 8, !tbaa !15
  %30 = icmp eq ptr %27, null
  br i1 %30, label %31, label %39

31:                                               ; preds = %20
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.z_stream_s, ptr %32, i32 0, i32 9
  %34 = load ptr, ptr %33, align 8, !tbaa !17
  %35 = load ptr, ptr %5, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.z_stream_s, ptr %35, i32 0, i32 10
  %37 = load ptr, ptr %36, align 8, !tbaa !14
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  call void %34(ptr noundef %37, ptr noundef %38)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %85

39:                                               ; preds = %20
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.z_stream_s, ptr %40, i32 0, i32 8
  %42 = load ptr, ptr %41, align 8, !tbaa !11
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.z_stream_s, ptr %43, i32 0, i32 10
  %45 = load ptr, ptr %44, align 8, !tbaa !14
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = call ptr %42(ptr noundef %45, i32 noundef 1, i32 noundef %46)
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.inflate_blocks_state, ptr %48, i32 0, i32 6
  store ptr %47, ptr %49, align 8, !tbaa !18
  %50 = icmp eq ptr %47, null
  br i1 %50, label %51, label %68

51:                                               ; preds = %39
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.z_stream_s, ptr %52, i32 0, i32 9
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.z_stream_s, ptr %55, i32 0, i32 10
  %57 = load ptr, ptr %56, align 8, !tbaa !14
  %58 = load ptr, ptr %8, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.inflate_blocks_state, ptr %58, i32 0, i32 5
  %60 = load ptr, ptr %59, align 8, !tbaa !15
  call void %54(ptr noundef %57, ptr noundef %60)
  %61 = load ptr, ptr %5, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.z_stream_s, ptr %61, i32 0, i32 9
  %63 = load ptr, ptr %62, align 8, !tbaa !17
  %64 = load ptr, ptr %5, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.z_stream_s, ptr %64, i32 0, i32 10
  %66 = load ptr, ptr %65, align 8, !tbaa !14
  %67 = load ptr, ptr %8, align 8, !tbaa !5
  call void %63(ptr noundef %66, ptr noundef %67)
  store ptr null, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %85

68:                                               ; preds = %39
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.inflate_blocks_state, ptr %69, i32 0, i32 6
  %71 = load ptr, ptr %70, align 8, !tbaa !18
  %72 = load i32, ptr %7, align 4, !tbaa !9
  %73 = zext i32 %72 to i64
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  %75 = load ptr, ptr %8, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.inflate_blocks_state, ptr %75, i32 0, i32 7
  store ptr %74, ptr %76, align 8, !tbaa !19
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = load ptr, ptr %8, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.inflate_blocks_state, ptr %78, i32 0, i32 10
  store ptr %77, ptr %79, align 8, !tbaa !20
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.inflate_blocks_state, ptr %80, i32 0, i32 0
  store i32 0, ptr %81, align 8, !tbaa !21
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = load ptr, ptr %5, align 8, !tbaa !5
  call void @inflate_blocks_reset(ptr noundef %82, ptr noundef %83, ptr noundef null)
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %84, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %85

85:                                               ; preds = %68, %51, %31, %18
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  %86 = load ptr, ptr %4, align 8
  ret ptr %86
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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, !6, i64 64}
!12 = !{!"z_stream_s", !6, i64 0, !10, i64 8, !13, i64 16, !6, i64 24, !10, i64 32, !13, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !13, i64 96, !13, i64 104}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !6, i64 80}
!15 = !{!16, !6, i64 56}
!16 = !{!"inflate_blocks_state", !10, i64 0, !7, i64 8, !10, i64 40, !10, i64 44, !13, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !13, i64 104}
!17 = !{!12, !6, i64 72}
!18 = !{!16, !6, i64 64}
!19 = !{!16, !6, i64 72}
!20 = !{!16, !6, i64 96}
!21 = !{!16, !10, 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: nounwind uwtable
declare dso_local void @inflate_blocks_reset(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local ptr @inflate_blocks_new(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 64
  %5 = load ptr, ptr %4, align 8, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 80
  %7 = load ptr, ptr %6, align 8, !tbaa !12
  %8 = tail call ptr %5(ptr noundef %7, i32 noundef 1, i32 noundef 112) #1
  %9 = icmp eq ptr %8, null
  br i1 %9, label %38, label %10

10:                                               ; preds = %3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = load ptr, ptr %6, align 8, !tbaa !12
  %13 = tail call ptr %11(ptr noundef %12, i32 noundef 8, i32 noundef 1440) #1
  %14 = getelementptr inbounds i8, ptr %8, i64 56
  store ptr %13, ptr %14, align 8, !tbaa !13
  %15 = icmp eq ptr %13, null
  br i1 %15, label %16, label %20

16:                                               ; preds = %10
  %17 = getelementptr inbounds i8, ptr %0, i64 72
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = load ptr, ptr %6, align 8, !tbaa !12
  tail call void %18(ptr noundef %19, ptr noundef nonnull %8) #1
  br label %38

20:                                               ; preds = %10
  %21 = load ptr, ptr %4, align 8, !tbaa !5
  %22 = load ptr, ptr %6, align 8, !tbaa !12
  %23 = tail call ptr %21(ptr noundef %22, i32 noundef 1, i32 noundef %2) #1
  %24 = getelementptr inbounds i8, ptr %8, i64 64
  store ptr %23, ptr %24, align 8, !tbaa !16
  %25 = icmp eq ptr %23, null
  br i1 %25, label %26, label %33

26:                                               ; preds = %20
  %27 = getelementptr inbounds i8, ptr %0, i64 72
  %28 = load ptr, ptr %27, align 8, !tbaa !15
  %29 = load ptr, ptr %6, align 8, !tbaa !12
  %30 = load ptr, ptr %14, align 8, !tbaa !13
  tail call void %28(ptr noundef %29, ptr noundef %30) #1
  %31 = load ptr, ptr %27, align 8, !tbaa !15
  %32 = load ptr, ptr %6, align 8, !tbaa !12
  tail call void %31(ptr noundef %32, ptr noundef nonnull %8) #1
  br label %38

33:                                               ; preds = %20
  %34 = zext i32 %2 to i64
  %35 = getelementptr inbounds i8, ptr %23, i64 %34
  %36 = getelementptr inbounds i8, ptr %8, i64 72
  store ptr %35, ptr %36, align 8, !tbaa !17
  %37 = getelementptr inbounds i8, ptr %8, i64 96
  store ptr %1, ptr %37, align 8, !tbaa !18
  store i32 0, ptr %8, align 8, !tbaa !19
  tail call void @inflate_blocks_reset(ptr noundef nonnull %8, ptr noundef nonnull %0, ptr noundef null)
  br label %38

38:                                               ; preds = %3, %33, %26, %16
  %.0 = phi ptr [ null, %16 ], [ null, %26 ], [ %8, %33 ], [ null, %3 ]
  ret ptr %.0
}

attributes #0 = { 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 #1 = { 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, !7, i64 64}
!6 = !{!"z_stream_s", !7, i64 0, !10, i64 8, !11, i64 16, !7, i64 24, !10, i64 32, !11, i64 40, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !10, i64 88, !11, i64 96, !11, i64 104}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !7, i64 80}
!13 = !{!14, !7, i64 56}
!14 = !{!"inflate_blocks_state", !10, i64 0, !8, i64 8, !10, i64 40, !10, i64 44, !11, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !7, i64 88, !7, i64 96, !11, i64 104}
!15 = !{!6, !7, i64 72}
!16 = !{!14, !7, i64 64}
!17 = !{!14, !7, i64 72}
!18 = !{!14, !7, i64 96}
!19 = !{!14, !10, i64 0}


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