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

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

@.str = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local i32 @inflateReset(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local i32 @inflateEnd(ptr noundef) #0

; Function Attrs: nounwind uwtable
define dso_local i32 @inflateInit2_(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = 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
  %10 = load ptr, ptr %8, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %24, label %12

12:                                               ; preds = %4
  %13 = load ptr, ptr %8, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 0
  %15 = load i8, ptr %14, align 1, !tbaa !11
  %16 = sext i8 %15 to i32
  %17 = load i8, ptr @.str, align 1, !tbaa !11
  %18 = sext i8 %17 to i32
  %19 = icmp ne i32 %16, %18
  br i1 %19, label %24, label %20

20:                                               ; preds = %12
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = icmp ne i64 %22, 112
  br i1 %23, label %24, label %25

24:                                               ; preds = %20, %12, %4
  store i32 -6, ptr %5, align 4
  br label %117

25:                                               ; preds = %20
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp eq ptr %26, null
  br i1 %27, label %28, label %29

28:                                               ; preds = %25
  store i32 -2, ptr %5, align 4
  br label %117

29:                                               ; preds = %25
  %30 = load ptr, ptr %6, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.z_stream_s, ptr %30, i32 0, i32 6
  store ptr null, ptr %31, align 8, !tbaa !12
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.z_stream_s, ptr %32, i32 0, i32 8
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  %35 = icmp eq ptr %34, null
  br i1 %35, label %36, label %41

36:                                               ; preds = %29
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.z_stream_s, ptr %37, i32 0, i32 8
  store ptr @zcalloc, ptr %38, align 8, !tbaa !15
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.z_stream_s, ptr %39, i32 0, i32 10
  store ptr null, ptr %40, align 8, !tbaa !16
  br label %41

41:                                               ; preds = %36, %29
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.z_stream_s, ptr %42, i32 0, i32 9
  %44 = load ptr, ptr %43, align 8, !tbaa !17
  %45 = icmp eq ptr %44, null
  br i1 %45, label %46, label %49

46:                                               ; preds = %41
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.z_stream_s, ptr %47, i32 0, i32 9
  store ptr @zcfree, ptr %48, align 8, !tbaa !17
  br label %49

49:                                               ; preds = %46, %41
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.z_stream_s, ptr %50, i32 0, i32 8
  %52 = load ptr, ptr %51, align 8, !tbaa !15
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.z_stream_s, ptr %53, i32 0, i32 10
  %55 = load ptr, ptr %54, align 8, !tbaa !16
  %56 = call ptr %52(ptr noundef %55, i32 noundef 1, i32 noundef 40)
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.z_stream_s, ptr %57, i32 0, i32 7
  store ptr %56, ptr %58, align 8, !tbaa !18
  %59 = icmp eq ptr %56, null
  br i1 %59, label %60, label %61

60:                                               ; preds = %49
  store i32 -4, ptr %5, align 4
  br label %117

61:                                               ; preds = %49
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.z_stream_s, ptr %62, i32 0, i32 7
  %64 = load ptr, ptr %63, align 8, !tbaa !18
  %65 = getelementptr inbounds %struct.internal_state, ptr %64, i32 0, i32 4
  store ptr null, ptr %65, align 8, !tbaa !19
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.z_stream_s, ptr %66, i32 0, i32 7
  %68 = load ptr, ptr %67, align 8, !tbaa !18
  %69 = getelementptr inbounds %struct.internal_state, ptr %68, i32 0, i32 2
  store i32 0, ptr %69, align 8, !tbaa !21
  %70 = load i32, ptr %7, align 4, !tbaa !9
  %71 = icmp slt i32 %70, 0
  br i1 %71, label %72, label %79

72:                                               ; preds = %61
  %73 = load i32, ptr %7, align 4, !tbaa !9
  %74 = sub nsw i32 0, %73
  store i32 %74, ptr %7, align 4, !tbaa !9
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.z_stream_s, ptr %75, i32 0, i32 7
  %77 = load ptr, ptr %76, align 8, !tbaa !18
  %78 = getelementptr inbounds %struct.internal_state, ptr %77, i32 0, i32 2
  store i32 1, ptr %78, align 8, !tbaa !21
  br label %79

79:                                               ; preds = %72, %61
  %80 = load i32, ptr %7, align 4, !tbaa !9
  %81 = icmp slt i32 %80, 8
  br i1 %81, label %85, label %82

82:                                               ; preds = %79
  %83 = load i32, ptr %7, align 4, !tbaa !9
  %84 = icmp sgt i32 %83, 15
  br i1 %84, label %85, label %88

85:                                               ; preds = %82, %79
  %86 = load ptr, ptr %6, align 8, !tbaa !5
  %87 = call i32 @inflateEnd(ptr noundef %86)
  store i32 -2, ptr %5, align 4
  br label %117

88:                                               ; preds = %82
  %89 = load i32, ptr %7, align 4, !tbaa !9
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.z_stream_s, ptr %90, i32 0, i32 7
  %92 = load ptr, ptr %91, align 8, !tbaa !18
  %93 = getelementptr inbounds %struct.internal_state, ptr %92, i32 0, i32 3
  store i32 %89, ptr %93, align 4, !tbaa !22
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.z_stream_s, ptr %95, i32 0, i32 7
  %97 = load ptr, ptr %96, align 8, !tbaa !18
  %98 = getelementptr inbounds %struct.internal_state, ptr %97, i32 0, i32 2
  %99 = load i32, ptr %98, align 8, !tbaa !21
  %100 = icmp ne i32 %99, 0
  %101 = zext i1 %100 to i64
  %102 = select i1 %100, ptr null, ptr @adler32
  %103 = load i32, ptr %7, align 4, !tbaa !9
  %104 = shl i32 1, %103
  %105 = call ptr @inflate_blocks_new(ptr noundef %94, ptr noundef %102, i32 noundef %104)
  %106 = load ptr, ptr %6, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.z_stream_s, ptr %106, i32 0, i32 7
  %108 = load ptr, ptr %107, align 8, !tbaa !18
  %109 = getelementptr inbounds %struct.internal_state, ptr %108, i32 0, i32 4
  store ptr %105, ptr %109, align 8, !tbaa !19
  %110 = icmp eq ptr %105, null
  br i1 %110, label %111, label %114

111:                                              ; preds = %88
  %112 = load ptr, ptr %6, align 8, !tbaa !5
  %113 = call i32 @inflateEnd(ptr noundef %112)
  store i32 -4, ptr %5, align 4
  br label %117

114:                                              ; preds = %88
  %115 = load ptr, ptr %6, align 8, !tbaa !5
  %116 = call i32 @inflateReset(ptr noundef %115)
  store i32 0, ptr %5, align 4
  br label %117

117:                                              ; preds = %114, %111, %85, %60, %28, %24
  %118 = load i32, ptr %5, align 4
  ret i32 %118
}

declare ptr @zcalloc(ptr noundef, i32 noundef, i32 noundef) #1

declare void @zcfree(ptr noundef, ptr noundef) #1

declare ptr @inflate_blocks_new(ptr noundef, ptr noundef, i32 noundef) #1

declare i64 @adler32(i64 noundef, ptr noundef, i32 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, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !6, i64 48}
!13 = !{!"z_stream_s", !6, i64 0, !10, i64 8, !14, i64 16, !6, i64 24, !10, i64 32, !14, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !10, i64 88, !14, i64 96, !14, i64 104}
!14 = !{!"long", !7, i64 0}
!15 = !{!13, !6, i64 64}
!16 = !{!13, !6, i64 80}
!17 = !{!13, !6, i64 72}
!18 = !{!13, !6, i64 56}
!19 = !{!20, !6, i64 32}
!20 = !{!"internal_state", !10, i64 0, !7, i64 8, !10, i64 24, !10, i64 28, !6, i64 32}
!21 = !{!20, !10, i64 24}
!22 = !{!20, !10, i64 28}


; 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 = external hidden unnamed_addr constant [6 x i8], align 1

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

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -6, 1) i32 @inflateInit2_(ptr noundef %0, i32 noundef %1, ptr noundef readonly %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = icmp eq ptr %2, null
  br i1 %5, label %50, label %6

6:                                                ; preds = %4
  %7 = load i8, ptr %2, align 1, !tbaa !5
  %8 = load i8, ptr @.str, align 1, !tbaa !5
  %9 = icmp ne i8 %7, %8
  %10 = icmp ne i32 %3, 112
  %or.cond = or i1 %10, %9
  br i1 %or.cond, label %50, label %11

11:                                               ; preds = %6
  %12 = icmp eq ptr %0, null
  br i1 %12, label %50, label %13

13:                                               ; preds = %11
  %14 = getelementptr inbounds i8, ptr %0, i64 48
  store ptr null, ptr %14, align 8, !tbaa !8
  %15 = getelementptr inbounds i8, ptr %0, i64 64
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  %17 = icmp eq ptr %16, null
  br i1 %17, label %18, label %20

18:                                               ; preds = %13
  store ptr @zcalloc, ptr %15, align 8, !tbaa !13
  %19 = getelementptr inbounds i8, ptr %0, i64 80
  store ptr null, ptr %19, align 8, !tbaa !14
  br label %20

20:                                               ; preds = %18, %13
  %21 = phi ptr [ @zcalloc, %18 ], [ %16, %13 ]
  %22 = getelementptr inbounds i8, ptr %0, i64 72
  %23 = load ptr, ptr %22, align 8, !tbaa !15
  %24 = icmp eq ptr %23, null
  br i1 %24, label %25, label %26

25:                                               ; preds = %20
  store ptr @zcfree, ptr %22, align 8, !tbaa !15
  br label %26

26:                                               ; preds = %25, %20
  %27 = getelementptr inbounds i8, ptr %0, i64 80
  %28 = load ptr, ptr %27, align 8, !tbaa !14
  %29 = tail call ptr %21(ptr noundef %28, i32 noundef 1, i32 noundef 40) #3
  %30 = getelementptr inbounds i8, ptr %0, i64 56
  store ptr %29, ptr %30, align 8, !tbaa !16
  %31 = icmp eq ptr %29, null
  br i1 %31, label %50, label %32

32:                                               ; preds = %26
  %33 = getelementptr inbounds i8, ptr %29, i64 32
  store ptr null, ptr %33, align 8, !tbaa !17
  %34 = getelementptr inbounds i8, ptr %29, i64 24
  %.lobit = lshr i32 %1, 31
  %spec.select38 = tail call i32 @llvm.abs.i32(i32 %1, i1 true)
  store i32 %.lobit, ptr %34, align 8, !tbaa !19
  %35 = add nsw i32 %spec.select38, -16
  %or.cond4 = icmp ult i32 %35, -8
  br i1 %or.cond4, label %36, label %38

36:                                               ; preds = %32
  %37 = tail call i32 @inflateEnd(ptr noundef nonnull %0)
  br label %50

38:                                               ; preds = %32
  %39 = getelementptr inbounds i8, ptr %29, i64 28
  store i32 %spec.select38, ptr %39, align 4, !tbaa !20
  %.not = icmp sgt i32 %1, -1
  %40 = select i1 %.not, ptr @adler32, ptr null
  %41 = shl nuw nsw i32 1, %spec.select38
  %42 = tail call ptr @inflate_blocks_new(ptr noundef nonnull %0, ptr noundef %40, i32 noundef %41) #3
  %43 = load ptr, ptr %30, align 8, !tbaa !16
  %44 = getelementptr inbounds i8, ptr %43, i64 32
  store ptr %42, ptr %44, align 8, !tbaa !17
  %45 = icmp eq ptr %42, null
  br i1 %45, label %46, label %48

46:                                               ; preds = %38
  %47 = tail call i32 @inflateEnd(ptr noundef nonnull %0)
  br label %50

48:                                               ; preds = %38
  %49 = tail call i32 @inflateReset(ptr noundef nonnull %0)
  br label %50

50:                                               ; preds = %26, %11, %4, %6, %48, %46, %36
  %.0 = phi i32 [ -2, %36 ], [ -4, %46 ], [ 0, %48 ], [ -6, %6 ], [ -6, %4 ], [ -2, %11 ], [ -4, %26 ]
  ret i32 %.0
}

declare ptr @zcalloc(ptr noundef, i32 noundef, i32 noundef) #1

declare void @zcfree(ptr noundef, ptr noundef) #1

declare ptr @inflate_blocks_new(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

declare i64 @adler32(i64 noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #2

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !10, i64 48}
!9 = !{!"z_stream_s", !10, i64 0, !11, i64 8, !12, i64 16, !10, i64 24, !11, i64 32, !12, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !11, i64 88, !12, i64 96, !12, i64 104}
!10 = !{!"any pointer", !6, i64 0}
!11 = !{!"int", !6, i64 0}
!12 = !{!"long", !6, i64 0}
!13 = !{!9, !10, i64 64}
!14 = !{!9, !10, i64 80}
!15 = !{!9, !10, i64 72}
!16 = !{!9, !10, i64 56}
!17 = !{!18, !10, i64 32}
!18 = !{!"internal_state", !11, i64 0, !6, i64 8, !11, i64 24, !11, i64 28, !10, i64 32}
!19 = !{!18, !11, i64 24}
!20 = !{!18, !11, i64 28}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass