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

; Function Attrs: nounwind uwtable
define dso_local void @inflate_blocks_reset(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = icmp ne ptr %7, null
  br i1 %8, label %9, label %14

9:                                                ; preds = %3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.inflate_blocks_state, ptr %10, i32 0, i32 11
  %12 = load i64, ptr %11, align 8, !tbaa !9
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  store i64 %12, ptr %13, align 8, !tbaa !13
  br label %14

14:                                               ; preds = %9, %3
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.inflate_blocks_state, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !14
  %18 = icmp eq i32 %17, 4
  br i1 %18, label %24, label %19

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.inflate_blocks_state, ptr %20, i32 0, i32 0
  %22 = load i32, ptr %21, align 8, !tbaa !14
  %23 = icmp eq i32 %22, 5
  br i1 %23, label %24, label %35

24:                                               ; preds = %19, %14
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.z_stream_s, ptr %25, i32 0, i32 9
  %27 = load ptr, ptr %26, align 8, !tbaa !15
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.z_stream_s, ptr %28, i32 0, i32 10
  %30 = load ptr, ptr %29, align 8, !tbaa !17
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.inflate_blocks_state, ptr %31, i32 0, i32 1
  %33 = getelementptr inbounds %struct.anon, ptr %32, i32 0, i32 2
  %34 = load ptr, ptr %33, align 8, !tbaa !18
  call void %27(ptr noundef %30, ptr noundef %34)
  br label %35

35:                                               ; preds = %24, %19
  %36 = load ptr, ptr %4, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.inflate_blocks_state, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %37, align 8, !tbaa !14
  %39 = icmp eq i32 %38, 6
  br i1 %39, label %40, label %46

40:                                               ; preds = %35
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.inflate_blocks_state, ptr %41, i32 0, i32 1
  %43 = getelementptr inbounds %struct.anon.0, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !18
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  call void @inflate_codes_free(ptr noundef %44, ptr noundef %45)
  br label %46

46:                                               ; preds = %40, %35
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.inflate_blocks_state, ptr %47, i32 0, i32 0
  store i32 0, ptr %48, align 8, !tbaa !14
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.inflate_blocks_state, ptr %49, i32 0, i32 3
  store i32 0, ptr %50, align 4, !tbaa !19
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.inflate_blocks_state, ptr %51, i32 0, i32 4
  store i64 0, ptr %52, align 8, !tbaa !20
  %53 = load ptr, ptr %4, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.inflate_blocks_state, ptr %53, i32 0, i32 6
  %55 = load ptr, ptr %54, align 8, !tbaa !21
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.inflate_blocks_state, ptr %56, i32 0, i32 9
  store ptr %55, ptr %57, align 8, !tbaa !22
  %58 = load ptr, ptr %4, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.inflate_blocks_state, ptr %58, i32 0, i32 8
  store ptr %55, ptr %59, align 8, !tbaa !23
  %60 = load ptr, ptr %4, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.inflate_blocks_state, ptr %60, i32 0, i32 10
  %62 = load ptr, ptr %61, align 8, !tbaa !24
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %73

64:                                               ; preds = %46
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.inflate_blocks_state, ptr %65, i32 0, i32 10
  %67 = load ptr, ptr %66, align 8, !tbaa !24
  %68 = call i64 %67(i64 noundef 0, ptr noundef null, i32 noundef 0)
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.inflate_blocks_state, ptr %69, i32 0, i32 11
  store i64 %68, ptr %70, align 8, !tbaa !9
  %71 = load ptr, ptr %5, align 8, !tbaa !5
  %72 = getelementptr inbounds %struct.z_stream_s, ptr %71, i32 0, i32 12
  store i64 %68, ptr %72, align 8, !tbaa !25
  br label %73

73:                                               ; preds = %64, %46
  ret void
}

declare void @inflate_codes_free(ptr noundef, ptr noundef) #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 = { "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" }

!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, !12, i64 104}
!10 = !{!"inflate_blocks_state", !11, i64 0, !7, i64 8, !11, i64 40, !11, i64 44, !12, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !12, i64 104}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !11, i64 0}
!15 = !{!16, !6, i64 72}
!16 = !{!"z_stream_s", !6, i64 0, !11, i64 8, !12, i64 16, !6, i64 24, !11, i64 32, !12, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !11, i64 88, !12, i64 96, !12, i64 104}
!17 = !{!16, !6, i64 80}
!18 = !{!7, !7, i64 0}
!19 = !{!10, !11, i64 44}
!20 = !{!10, !12, i64 48}
!21 = !{!10, !6, i64 64}
!22 = !{!10, !6, i64 88}
!23 = !{!10, !6, i64 80}
!24 = !{!10, !6, i64 96}
!25 = !{!16, !12, i64 96}


; 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
define dso_local void @inflate_blocks_reset(ptr nocapture noundef %0, ptr noundef %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %7, label %4

4:                                                ; preds = %3
  %5 = getelementptr inbounds i8, ptr %0, i64 104
  %6 = load i64, ptr %5, align 8, !tbaa !5
  store i64 %6, ptr %2, align 8, !tbaa !12
  br label %7

7:                                                ; preds = %4, %3
  %8 = load i32, ptr %0, align 8, !tbaa !13
  %9 = and i32 %8, -2
  %switch = icmp eq i32 %9, 4
  br i1 %switch, label %10, label %17

10:                                               ; preds = %7
  %11 = getelementptr inbounds i8, ptr %1, i64 72
  %12 = load ptr, ptr %11, align 8, !tbaa !14
  %13 = getelementptr inbounds i8, ptr %1, i64 80
  %14 = load ptr, ptr %13, align 8, !tbaa !16
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  %16 = load ptr, ptr %15, align 8, !tbaa !17
  tail call void %12(ptr noundef %14, ptr noundef %16) #2
  %.pr = load i32, ptr %0, align 8, !tbaa !13
  br label %17

17:                                               ; preds = %7, %10
  %18 = phi i32 [ %8, %7 ], [ %.pr, %10 ]
  %19 = icmp eq i32 %18, 6
  br i1 %19, label %20, label %23

20:                                               ; preds = %17
  %21 = getelementptr inbounds i8, ptr %0, i64 8
  %22 = load ptr, ptr %21, align 8, !tbaa !17
  tail call void @inflate_codes_free(ptr noundef %22, ptr noundef %1) #2
  br label %23

23:                                               ; preds = %20, %17
  store i32 0, ptr %0, align 8, !tbaa !13
  %24 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 0, ptr %24, align 4, !tbaa !18
  %25 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 0, ptr %25, align 8, !tbaa !19
  %26 = getelementptr inbounds i8, ptr %0, i64 64
  %27 = load ptr, ptr %26, align 8, !tbaa !20
  %28 = getelementptr inbounds i8, ptr %0, i64 88
  store ptr %27, ptr %28, align 8, !tbaa !21
  %29 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr %27, ptr %29, align 8, !tbaa !22
  %30 = getelementptr inbounds i8, ptr %0, i64 96
  %31 = load ptr, ptr %30, align 8, !tbaa !23
  %.not23 = icmp eq ptr %31, null
  br i1 %.not23, label %36, label %32

32:                                               ; preds = %23
  %33 = tail call i64 %31(i64 noundef 0, ptr noundef null, i32 noundef 0) #2
  %34 = getelementptr inbounds i8, ptr %0, i64 104
  store i64 %33, ptr %34, align 8, !tbaa !5
  %35 = getelementptr inbounds i8, ptr %1, i64 96
  store i64 %33, ptr %35, align 8, !tbaa !24
  br label %36

36:                                               ; preds = %32, %23
  ret void
}

declare void @inflate_codes_free(ptr noundef, ptr noundef) local_unnamed_addr #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 = { "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 }

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


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