; LLVM IR from niessner/Matterport :: code/gaps/pkgs/png (gzwrite)

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

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gzputc(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca [1 x i8], align 1
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %6) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #2
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  %11 = icmp eq ptr %10, null
  br i1 %11, label %12, label %13

12:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %90

13:                                               ; preds = %2
  %14 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %14, ptr %7, align 8, !tbaa !5
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.gz_state, ptr %15, i32 0, i32 21
  store ptr %16, ptr %8, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.gz_state, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !11
  %20 = icmp ne i32 %19, 31153
  br i1 %20, label %26, label %21

21:                                               ; preds = %13
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.gz_state, ptr %22, i32 0, i32 19
  %24 = load i32, ptr %23, align 4, !tbaa !15
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %21, %13
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %90

27:                                               ; preds = %21
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.gz_state, ptr %28, i32 0, i32 18
  %30 = load i32, ptr %29, align 8, !tbaa !16
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %32, label %43

32:                                               ; preds = %27
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.gz_state, ptr %33, i32 0, i32 18
  store i32 0, ptr %34, align 8, !tbaa !16
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load ptr, ptr %7, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.gz_state, ptr %36, i32 0, i32 17
  %38 = load i64, ptr %37, align 8, !tbaa !17
  %39 = call i32 @gz_zero(ptr noundef %35, i64 noundef %38)
  %40 = icmp eq i32 %39, -1
  br i1 %40, label %41, label %42

41:                                               ; preds = %32
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %90

42:                                               ; preds = %32
  br label %43

43:                                               ; preds = %42, %27
  %44 = load ptr, ptr %8, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.z_stream_s, ptr %44, i32 0, i32 1
  %46 = load i32, ptr %45, align 8, !tbaa !18
  %47 = load ptr, ptr %7, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.gz_state, ptr %47, i32 0, i32 4
  %49 = load i32, ptr %48, align 8, !tbaa !19
  %50 = icmp ult i32 %46, %49
  br i1 %50, label %51, label %79

51:                                               ; preds = %43
  %52 = load ptr, ptr %8, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.z_stream_s, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %53, align 8, !tbaa !18
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %62

56:                                               ; preds = %51
  %57 = load ptr, ptr %7, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.gz_state, ptr %57, i32 0, i32 6
  %59 = load ptr, ptr %58, align 8, !tbaa !20
  %60 = load ptr, ptr %8, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.z_stream_s, ptr %60, i32 0, i32 0
  store ptr %59, ptr %61, align 8, !tbaa !21
  br label %62

62:                                               ; preds = %56, %51
  %63 = load i32, ptr %5, align 4, !tbaa !9
  %64 = trunc i32 %63 to i8
  %65 = load ptr, ptr %8, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.z_stream_s, ptr %65, i32 0, i32 0
  %67 = load ptr, ptr %66, align 8, !tbaa !21
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.z_stream_s, ptr %68, i32 0, i32 1
  %70 = load i32, ptr %69, align 8, !tbaa !18
  %71 = add i32 %70, 1
  store i32 %71, ptr %69, align 8, !tbaa !18
  %72 = zext i32 %70 to i64
  %73 = getelementptr inbounds i8, ptr %67, i64 %72
  store i8 %64, ptr %73, align 1, !tbaa !22
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = getelementptr inbounds %struct.gz_state, ptr %74, i32 0, i32 3
  %76 = load i64, ptr %75, align 8, !tbaa !23
  %77 = add nsw i64 %76, 1
  store i64 %77, ptr %75, align 8, !tbaa !23
  %78 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %78, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %90

79:                                               ; preds = %43
  %80 = load i32, ptr %5, align 4, !tbaa !9
  %81 = trunc i32 %80 to i8
  %82 = getelementptr inbounds [1 x i8], ptr %6, i64 0, i64 0
  store i8 %81, ptr %82, align 1, !tbaa !22
  %83 = load ptr, ptr %4, align 8, !tbaa !5
  %84 = getelementptr inbounds [1 x i8], ptr %6, i64 0, i64 0
  %85 = call i32 @gzwrite(ptr noundef %83, ptr noundef %84, i32 noundef 1)
  %86 = icmp ne i32 %85, 1
  br i1 %86, label %87, label %88

87:                                               ; preds = %79
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %90

88:                                               ; preds = %79
  %89 = load i32, ptr %5, align 4, !tbaa !9
  store i32 %89, ptr %3, align 4
  store i32 1, ptr %9, align 4
  br label %90

90:                                               ; preds = %88, %87, %62, %41, %26, %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %6) #2
  %91 = load i32, ptr %3, align 4
  ret i32 %91
}

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, !10, i64 0}
!12 = !{!"", !10, i64 0, !10, i64 4, !6, i64 8, !13, i64 16, !10, i64 24, !10, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56, !10, i64 60, !13, i64 64, !13, i64 72, !10, i64 80, !10, i64 84, !10, i64 88, !10, i64 92, !13, i64 96, !10, i64 104, !10, i64 108, !6, i64 112, !14, i64 120}
!13 = !{!"long", !7, i64 0}
!14 = !{!"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}
!15 = !{!12, !10, i64 108}
!16 = !{!12, !10, i64 104}
!17 = !{!12, !13, i64 96}
!18 = !{!14, !10, i64 8}
!19 = !{!12, !10, i64 24}
!20 = !{!12, !6, i64 32}
!21 = !{!14, !6, i64 0}
!22 = !{!7, !7, i64 0}
!23 = !{!12, !13, i64 16}


; 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 i32 @gzwrite(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @gzputc(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = alloca [1 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %3) #2
  %4 = icmp eq ptr %0, null
  br i1 %4, label %42, label %5

5:                                                ; preds = %2
  %6 = getelementptr inbounds i8, ptr %0, i64 120
  %7 = load i32, ptr %0, align 8, !tbaa !5
  %.not = icmp eq i32 %7, 31153
  br i1 %.not, label %8, label %42

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %0, i64 108
  %10 = load i32, ptr %9, align 4, !tbaa !13
  %.not24 = icmp eq i32 %10, 0
  br i1 %.not24, label %11, label %42

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 104
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %.not25 = icmp eq i32 %13, 0
  br i1 %.not25, label %19, label %14

14:                                               ; preds = %11
  store i32 0, ptr %12, align 8, !tbaa !14
  %15 = getelementptr inbounds i8, ptr %0, i64 96
  %16 = load i64, ptr %15, align 8, !tbaa !15
  %17 = tail call i32 @gz_zero(ptr noundef nonnull %0, i64 noundef %16)
  %18 = icmp eq i32 %17, -1
  br i1 %18, label %42, label %19

19:                                               ; preds = %14, %11
  %20 = getelementptr inbounds i8, ptr %0, i64 128
  %21 = load i32, ptr %20, align 8, !tbaa !16
  %22 = getelementptr inbounds i8, ptr %0, i64 24
  %23 = load i32, ptr %22, align 8, !tbaa !17
  %24 = icmp ult i32 %21, %23
  br i1 %24, label %25, label %39

25:                                               ; preds = %19
  %26 = icmp eq i32 %21, 0
  br i1 %26, label %27, label %._crit_edge

._crit_edge:                                      ; preds = %25
  %.pre = load ptr, ptr %6, align 8, !tbaa !18
  br label %30

27:                                               ; preds = %25
  %28 = getelementptr inbounds i8, ptr %0, i64 32
  %29 = load ptr, ptr %28, align 8, !tbaa !19
  store ptr %29, ptr %6, align 8, !tbaa !18
  br label %30

30:                                               ; preds = %._crit_edge, %27
  %31 = phi ptr [ %.pre, %._crit_edge ], [ %29, %27 ]
  %32 = trunc i32 %1 to i8
  %33 = add nuw i32 %21, 1
  store i32 %33, ptr %20, align 8, !tbaa !16
  %34 = zext i32 %21 to i64
  %35 = getelementptr inbounds i8, ptr %31, i64 %34
  store i8 %32, ptr %35, align 1, !tbaa !20
  %36 = getelementptr inbounds i8, ptr %0, i64 16
  %37 = load i64, ptr %36, align 8, !tbaa !21
  %38 = add nsw i64 %37, 1
  store i64 %38, ptr %36, align 8, !tbaa !21
  br label %42

39:                                               ; preds = %19
  %40 = trunc i32 %1 to i8
  store i8 %40, ptr %3, align 1, !tbaa !20
  %41 = call i32 @gzwrite(ptr noundef nonnull %0, ptr noundef nonnull %3, i32 noundef 1)
  %.not26 = icmp eq i32 %41, 1
  %. = select i1 %.not26, i32 %1, i32 -1
  br label %42

42:                                               ; preds = %39, %14, %5, %8, %2, %30
  %.0 = phi i32 [ %1, %30 ], [ -1, %2 ], [ -1, %8 ], [ -1, %5 ], [ -1, %14 ], [ %., %39 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %3) #2
  ret i32 %.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 = { mustprogress 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, !7, i64 0}
!6 = !{!"", !7, i64 0, !7, i64 4, !10, i64 8, !11, i64 16, !7, i64 24, !7, i64 28, !10, i64 32, !10, i64 40, !10, i64 48, !7, i64 56, !7, i64 60, !11, i64 64, !11, i64 72, !7, i64 80, !7, i64 84, !7, i64 88, !7, i64 92, !11, i64 96, !7, i64 104, !7, i64 108, !10, i64 112, !12, i64 120}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"z_stream_s", !10, i64 0, !7, i64 8, !11, i64 16, !10, i64 24, !7, i64 32, !11, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !7, i64 88, !11, i64 96, !11, i64 104}
!13 = !{!6, !7, i64 108}
!14 = !{!6, !7, i64 104}
!15 = !{!6, !11, i64 96}
!16 = !{!12, !7, i64 8}
!17 = !{!6, !7, i64 24}
!18 = !{!12, !10, i64 0}
!19 = !{!6, !10, i64 32}
!20 = !{!8, !8, i64 0}
!21 = !{!6, !11, i64 16}


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