; 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.__va_list_tag = type { i32, i32, ptr, ptr }
%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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @gz_init(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @gz_comp(ptr noundef, i32 noundef) #1

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

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

14:                                               ; preds = %2
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %120

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

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

28:                                               ; preds = %23, %15
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %120

29:                                               ; preds = %23
  %30 = load ptr, ptr %8, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.gz_state, ptr %30, i32 0, i32 4
  %32 = load i32, ptr %31, align 8, !tbaa !15
  %33 = icmp eq i32 %32, 0
  br i1 %33, label %34, label %39

34:                                               ; preds = %29
  %35 = load ptr, ptr %8, align 8, !tbaa !5
  %36 = call i32 @gz_init(ptr noundef %35)
  %37 = icmp eq i32 %36, -1
  br i1 %37, label %38, label %39

38:                                               ; preds = %34
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %120

39:                                               ; preds = %34, %29
  %40 = load ptr, ptr %8, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.gz_state, ptr %40, i32 0, i32 18
  %42 = load i32, ptr %41, align 8, !tbaa !16
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %44, label %55

44:                                               ; preds = %39
  %45 = load ptr, ptr %8, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.gz_state, ptr %45, i32 0, i32 18
  store i32 0, ptr %46, align 8, !tbaa !16
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.gz_state, ptr %48, i32 0, i32 17
  %50 = load i64, ptr %49, align 8, !tbaa !17
  %51 = call i32 @gz_zero(ptr noundef %47, i64 noundef %50)
  %52 = icmp eq i32 %51, -1
  br i1 %52, label %53, label %54

53:                                               ; preds = %44
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %120

54:                                               ; preds = %44
  br label %55

55:                                               ; preds = %54, %39
  %56 = load ptr, ptr %9, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.z_stream_s, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 8, !tbaa !18
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %65

60:                                               ; preds = %55
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  %62 = call i32 @gz_comp(ptr noundef %61, i32 noundef 0)
  %63 = icmp eq i32 %62, -1
  br i1 %63, label %64, label %65

64:                                               ; preds = %60
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %120

65:                                               ; preds = %60, %55
  %66 = load ptr, ptr %8, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.gz_state, ptr %66, i32 0, i32 4
  %68 = load i32, ptr %67, align 8, !tbaa !15
  store i32 %68, ptr %6, align 4, !tbaa !19
  %69 = load ptr, ptr %8, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.gz_state, ptr %69, i32 0, i32 6
  %71 = load ptr, ptr %70, align 8, !tbaa !20
  %72 = load i32, ptr %6, align 4, !tbaa !19
  %73 = sub nsw i32 %72, 1
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds i8, ptr %71, i64 %74
  store i8 0, ptr %75, align 1, !tbaa !21
  %76 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %10, i64 0, i64 0
  call void @llvm.va_start.p0(ptr %76)
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.gz_state, ptr %77, i32 0, i32 6
  %79 = load ptr, ptr %78, align 8, !tbaa !20
  %80 = load i32, ptr %6, align 4, !tbaa !19
  %81 = sext i32 %80 to i64
  %82 = load ptr, ptr %5, align 8, !tbaa !5
  %83 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %10, i64 0, i64 0
  %84 = call i32 @vsnprintf(ptr noundef %79, i64 noundef %81, ptr noundef %82, ptr noundef %83) #4
  store i32 %84, ptr %7, align 4, !tbaa !19
  %85 = getelementptr inbounds [1 x %struct.__va_list_tag], ptr %10, i64 0, i64 0
  call void @llvm.va_end.p0(ptr %85)
  %86 = load i32, ptr %7, align 4, !tbaa !19
  %87 = icmp sle i32 %86, 0
  br i1 %87, label %103, label %88

88:                                               ; preds = %65
  %89 = load i32, ptr %7, align 4, !tbaa !19
  %90 = load i32, ptr %6, align 4, !tbaa !19
  %91 = icmp sge i32 %89, %90
  br i1 %91, label %103, label %92

92:                                               ; preds = %88
  %93 = load ptr, ptr %8, align 8, !tbaa !5
  %94 = getelementptr inbounds %struct.gz_state, ptr %93, i32 0, i32 6
  %95 = load ptr, ptr %94, align 8, !tbaa !20
  %96 = load i32, ptr %6, align 4, !tbaa !19
  %97 = sub nsw i32 %96, 1
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds i8, ptr %95, i64 %98
  %100 = load i8, ptr %99, align 1, !tbaa !21
  %101 = zext i8 %100 to i32
  %102 = icmp ne i32 %101, 0
  br i1 %102, label %103, label %104

103:                                              ; preds = %92, %88, %65
  store i32 0, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %120

104:                                              ; preds = %92
  %105 = load i32, ptr %7, align 4, !tbaa !19
  %106 = load ptr, ptr %9, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.z_stream_s, ptr %106, i32 0, i32 1
  store i32 %105, ptr %107, align 8, !tbaa !18
  %108 = load ptr, ptr %8, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.gz_state, ptr %108, i32 0, i32 6
  %110 = load ptr, ptr %109, align 8, !tbaa !20
  %111 = load ptr, ptr %9, align 8, !tbaa !5
  %112 = getelementptr inbounds %struct.z_stream_s, ptr %111, i32 0, i32 0
  store ptr %110, ptr %112, align 8, !tbaa !22
  %113 = load i32, ptr %7, align 4, !tbaa !19
  %114 = sext i32 %113 to i64
  %115 = load ptr, ptr %8, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.gz_state, ptr %115, i32 0, i32 3
  %117 = load i64, ptr %116, align 8, !tbaa !23
  %118 = add nsw i64 %117, %114
  store i64 %118, ptr %116, align 8, !tbaa !23
  %119 = load i32, ptr %7, align 4, !tbaa !19
  store i32 %119, ptr %3, align 4
  store i32 1, ptr %11, align 4
  br label %120

120:                                              ; preds = %104, %103, %64, %53, %38, %28, %14
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %121 = load i32, ptr %3, align 4
  ret i32 %121
}

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

; Function Attrs: nounwind
declare i32 @vsnprintf(ptr noundef, i64 noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn }
attributes #3 = { nounwind "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 #4 = { 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, !11, i64 0}
!10 = !{!"", !11, i64 0, !11, i64 4, !6, i64 8, !12, i64 16, !11, i64 24, !11, i64 28, !6, i64 32, !6, i64 40, !6, i64 48, !11, i64 56, !11, i64 60, !12, i64 64, !12, i64 72, !11, i64 80, !11, i64 84, !11, i64 88, !11, i64 92, !12, i64 96, !11, i64 104, !11, i64 108, !6, i64 112, !13, i64 120}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!"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}
!14 = !{!10, !11, i64 108}
!15 = !{!10, !11, i64 24}
!16 = !{!10, !11, i64 104}
!17 = !{!10, !12, i64 96}
!18 = !{!13, !11, i64 8}
!19 = !{!11, !11, i64 0}
!20 = !{!10, !6, i64 32}
!21 = !{!7, !7, i64 0}
!22 = !{!13, !6, i64 0}
!23 = !{!10, !12, 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"

%struct.__va_list_tag = type { i32, i32, ptr, ptr }

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

; Function Attrs: nounwind uwtable
declare hidden i32 @gz_init(ptr noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @gz_comp(ptr noundef, i32 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, -2147483648) i32 @gzprintf(ptr noundef %0, ptr nocapture noundef readonly %1, ...) local_unnamed_addr #1 {
  %3 = alloca [1 x %struct.__va_list_tag], align 16
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #4
  %4 = icmp eq ptr %0, null
  br i1 %4, label %52, 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 %52

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

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %0, i64 24
  %13 = load i32, ptr %12, align 8, !tbaa !14
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %15, label %18

15:                                               ; preds = %11
  %16 = tail call i32 @gz_init(ptr noundef nonnull %0)
  %17 = icmp eq i32 %16, -1
  br i1 %17, label %52, label %18

18:                                               ; preds = %15, %11
  %19 = getelementptr inbounds i8, ptr %0, i64 104
  %20 = load i32, ptr %19, align 8, !tbaa !15
  %.not34 = icmp eq i32 %20, 0
  br i1 %.not34, label %26, label %21

21:                                               ; preds = %18
  store i32 0, ptr %19, align 8, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %0, i64 96
  %23 = load i64, ptr %22, align 8, !tbaa !16
  %24 = tail call i32 @gz_zero(ptr noundef nonnull %0, i64 noundef %23)
  %25 = icmp eq i32 %24, -1
  br i1 %25, label %52, label %26

26:                                               ; preds = %21, %18
  %27 = getelementptr inbounds i8, ptr %0, i64 128
  %28 = load i32, ptr %27, align 8, !tbaa !17
  %.not35 = icmp eq i32 %28, 0
  br i1 %.not35, label %32, label %29

29:                                               ; preds = %26
  %30 = tail call i32 @gz_comp(ptr noundef nonnull %0, i32 noundef 0)
  %31 = icmp eq i32 %30, -1
  br i1 %31, label %52, label %32

32:                                               ; preds = %29, %26
  %33 = load i32, ptr %12, align 8, !tbaa !14
  %34 = getelementptr inbounds i8, ptr %0, i64 32
  %35 = load ptr, ptr %34, align 8, !tbaa !18
  %36 = add nsw i32 %33, -1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i8, ptr %35, i64 %37
  store i8 0, ptr %38, align 1, !tbaa !19
  call void @llvm.va_start.p0(ptr nonnull %3)
  %39 = load ptr, ptr %34, align 8, !tbaa !18
  %40 = sext i32 %33 to i64
  %41 = call i32 @vsnprintf(ptr noundef %39, i64 noundef %40, ptr noundef %1, ptr noundef nonnull %3) #4
  call void @llvm.va_end.p0(ptr nonnull %3)
  %42 = icmp sgt i32 %41, 0
  %.not36 = icmp slt i32 %41, %33
  %or.cond = and i1 %42, %.not36
  br i1 %or.cond, label %43, label %52

43:                                               ; preds = %32
  %44 = load ptr, ptr %34, align 8, !tbaa !18
  %45 = getelementptr inbounds i8, ptr %44, i64 %37
  %46 = load i8, ptr %45, align 1, !tbaa !19
  %.not37 = icmp eq i8 %46, 0
  br i1 %.not37, label %47, label %52

47:                                               ; preds = %43
  store i32 %41, ptr %27, align 8, !tbaa !17
  store ptr %44, ptr %6, align 8, !tbaa !20
  %48 = zext nneg i32 %41 to i64
  %49 = getelementptr inbounds i8, ptr %0, i64 16
  %50 = load i64, ptr %49, align 8, !tbaa !21
  %51 = add nsw i64 %50, %48
  store i64 %51, ptr %49, align 8, !tbaa !21
  br label %52

52:                                               ; preds = %32, %43, %29, %21, %15, %5, %8, %2, %47
  %.0 = phi i32 [ %41, %47 ], [ -1, %2 ], [ 0, %8 ], [ 0, %5 ], [ 0, %15 ], [ 0, %21 ], [ 0, %29 ], [ 0, %43 ], [ 0, %32 ]
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #4
  ret i32 %.0
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_start.p0(ptr) #2

; Function Attrs: nofree nounwind
declare noundef i32 @vsnprintf(ptr nocapture noundef, i64 noundef, ptr nocapture noundef readonly, ptr noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.va_end.p0(ptr) #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #3 = { nofree nounwind "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 #4 = { 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 24}
!15 = !{!6, !7, i64 104}
!16 = !{!6, !11, i64 96}
!17 = !{!12, !7, i64 8}
!18 = !{!6, !10, i64 32}
!19 = !{!8, !8, i64 0}
!20 = !{!12, !10, i64 0}
!21 = !{!6, !11, i64 16}


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