; LLVM IR from sslab-gatech/janus :: lkl/arch/xtensa/boot/lib (zmem)

; 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, i64, i64, ptr, i64, i64, ptr, ptr, ptr, i32, i64, i64 }

; Function Attrs: noreturn nounwind uwtable
declare dso_local void @exit() #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @zalloc(i32 noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local void @gunzip(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca %struct.z_stream_s, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store ptr %2, ptr %7, align 8, !tbaa !5
  store ptr %3, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 96, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 10, ptr %11, align 4, !tbaa !9
  %13 = load ptr, ptr %7, align 8, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %13, i64 3
  %15 = load i8, ptr %14, align 1, !tbaa !11
  %16 = zext i8 %15 to i32
  store i32 %16, ptr %12, align 4, !tbaa !9
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %17, i64 2
  %19 = load i8, ptr %18, align 1, !tbaa !11
  %20 = zext i8 %19 to i32
  %21 = icmp ne i32 %20, 8
  br i1 %21, label %26, label %22

22:                                               ; preds = %4
  %23 = load i32, ptr %12, align 4, !tbaa !9
  %24 = and i32 %23, 224
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %27

26:                                               ; preds = %22, %4
  call void @exit() #5
  unreachable

27:                                               ; preds = %22
  %28 = load i32, ptr %12, align 4, !tbaa !9
  %29 = and i32 %28, 4
  %30 = icmp ne i32 %29, 0
  br i1 %30, label %31, label %43

31:                                               ; preds = %27
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = getelementptr inbounds i8, ptr %32, i64 10
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = zext i8 %34 to i32
  %36 = add nsw i32 12, %35
  %37 = load ptr, ptr %7, align 8, !tbaa !5
  %38 = getelementptr inbounds i8, ptr %37, i64 11
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = zext i8 %39 to i32
  %41 = shl i32 %40, 8
  %42 = add nsw i32 %36, %41
  store i32 %42, ptr %11, align 4, !tbaa !9
  br label %43

43:                                               ; preds = %31, %27
  %44 = load i32, ptr %12, align 4, !tbaa !9
  %45 = and i32 %44, 8
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %59

47:                                               ; preds = %43
  br label %48

48:                                               ; preds = %57, %47
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = add nsw i32 %50, 1
  store i32 %51, ptr %11, align 4, !tbaa !9
  %52 = sext i32 %50 to i64
  %53 = getelementptr inbounds i8, ptr %49, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = zext i8 %54 to i32
  %56 = icmp ne i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %48
  br label %48, !llvm.loop !12

58:                                               ; preds = %48
  br label %59

59:                                               ; preds = %58, %43
  %60 = load i32, ptr %12, align 4, !tbaa !9
  %61 = and i32 %60, 16
  %62 = icmp ne i32 %61, 0
  br i1 %62, label %63, label %75

63:                                               ; preds = %59
  br label %64

64:                                               ; preds = %73, %63
  %65 = load ptr, ptr %7, align 8, !tbaa !5
  %66 = load i32, ptr %11, align 4, !tbaa !9
  %67 = add nsw i32 %66, 1
  store i32 %67, ptr %11, align 4, !tbaa !9
  %68 = sext i32 %66 to i64
  %69 = getelementptr inbounds i8, ptr %65, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !11
  %71 = zext i8 %70 to i32
  %72 = icmp ne i32 %71, 0
  br i1 %72, label %73, label %74

73:                                               ; preds = %64
  br label %64, !llvm.loop !14

74:                                               ; preds = %64
  br label %75

75:                                               ; preds = %74, %59
  %76 = load i32, ptr %12, align 4, !tbaa !9
  %77 = and i32 %76, 2
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %82

79:                                               ; preds = %75
  %80 = load i32, ptr %11, align 4, !tbaa !9
  %81 = add nsw i32 %80, 2
  store i32 %81, ptr %11, align 4, !tbaa !9
  br label %82

82:                                               ; preds = %79, %75
  %83 = load i32, ptr %11, align 4, !tbaa !9
  %84 = load ptr, ptr %8, align 8, !tbaa !5
  %85 = load i32, ptr %84, align 4, !tbaa !9
  %86 = icmp sge i32 %83, %85
  br i1 %86, label %87, label %88

87:                                               ; preds = %82
  call void @exit() #5
  unreachable

88:                                               ; preds = %82
  %89 = call i32 @zlib_inflate_workspacesize()
  %90 = call ptr @zalloc(i32 noundef %89)
  %91 = getelementptr inbounds %struct.z_stream_s, ptr %9, i32 0, i32 8
  store ptr %90, ptr %91, align 8, !tbaa !15
  %92 = call i32 @zlib_inflateInit2(ptr noundef %9, i32 noundef -15)
  store i32 %92, ptr %10, align 4, !tbaa !9
  %93 = load i32, ptr %10, align 4, !tbaa !9
  %94 = icmp ne i32 %93, 0
  br i1 %94, label %95, label %96

95:                                               ; preds = %88
  call void @exit() #5
  unreachable

96:                                               ; preds = %88
  %97 = load ptr, ptr %7, align 8, !tbaa !5
  %98 = load i32, ptr %11, align 4, !tbaa !9
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds i8, ptr %97, i64 %99
  %101 = getelementptr inbounds %struct.z_stream_s, ptr %9, i32 0, i32 0
  store ptr %100, ptr %101, align 8, !tbaa !18
  %102 = load ptr, ptr %8, align 8, !tbaa !5
  %103 = load i32, ptr %102, align 4, !tbaa !9
  %104 = load i32, ptr %11, align 4, !tbaa !9
  %105 = sub nsw i32 %103, %104
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds %struct.z_stream_s, ptr %9, i32 0, i32 1
  store i64 %106, ptr %107, align 8, !tbaa !19
  %108 = load ptr, ptr %5, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.z_stream_s, ptr %9, i32 0, i32 3
  store ptr %108, ptr %109, align 8, !tbaa !20
  %110 = load i32, ptr %6, align 4, !tbaa !9
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds %struct.z_stream_s, ptr %9, i32 0, i32 4
  store i64 %111, ptr %112, align 8, !tbaa !21
  %113 = call i32 @zlib_inflate(ptr noundef %9, i32 noundef 5)
  store i32 %113, ptr %10, align 4, !tbaa !9
  %114 = load i32, ptr %10, align 4, !tbaa !9
  %115 = icmp ne i32 %114, 0
  br i1 %115, label %116, label %120

116:                                              ; preds = %96
  %117 = load i32, ptr %10, align 4, !tbaa !9
  %118 = icmp ne i32 %117, 1
  br i1 %118, label %119, label %120

119:                                              ; preds = %116
  call void @exit() #5
  unreachable

120:                                              ; preds = %116, %96
  %121 = getelementptr inbounds %struct.z_stream_s, ptr %9, i32 0, i32 3
  %122 = load ptr, ptr %121, align 8, !tbaa !20
  %123 = load ptr, ptr %5, align 8, !tbaa !5
  %124 = ptrtoint ptr %122 to i64
  %125 = ptrtoint ptr %123 to i64
  %126 = sub i64 %124, %125
  %127 = trunc i64 %126 to i32
  %128 = load ptr, ptr %8, align 8, !tbaa !5
  store i32 %127, ptr %128, align 4, !tbaa !9
  %129 = call i32 @zlib_inflateEnd(ptr noundef %9)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 96, ptr %9) #4
  ret void
}

declare i32 @zlib_inflate_workspacesize() #3

declare i32 @zlib_inflateInit2(ptr noundef, i32 noundef) #3

declare i32 @zlib_inflate(ptr noundef, i32 noundef) #3

declare i32 @zlib_inflateEnd(ptr noundef) #3

attributes #0 = { noreturn 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 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 memory(argmem: readwrite) }
attributes #3 = { "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 }
attributes #5 = { noreturn }

!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 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!16, !6, i64 64}
!16 = !{!"z_stream_s", !6, i64 0, !17, i64 8, !17, i64 16, !6, i64 24, !17, i64 32, !17, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !10, i64 72, !17, i64 80, !17, i64 88}
!17 = !{!"long", !7, i64 0}
!18 = !{!16, !6, i64 0}
!19 = !{!16, !17, i64 8}
!20 = !{!16, !6, i64 24}
!21 = !{!16, !17, i64 32}


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

; Function Attrs: noreturn nounwind uwtable
declare dso_local void @exit() local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @gunzip(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr nocapture noundef %3) local_unnamed_addr #1 {
  %5 = alloca %struct.z_stream_s, align 8
  call void @llvm.lifetime.start.p0(i64 96, ptr nonnull %5) #4
  %6 = getelementptr inbounds i8, ptr %2, i64 3
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = zext i8 %7 to i32
  %9 = getelementptr inbounds i8, ptr %2, i64 2
  %10 = load i8, ptr %9, align 1, !tbaa !5
  %.not = icmp eq i8 %10, 8
  %.not27 = icmp ult i8 %7, 32
  %or.cond36 = select i1 %.not, i1 %.not27, i1 false
  br i1 %or.cond36, label %12, label %11

11:                                               ; preds = %4
  tail call void @exit() #5
  unreachable

12:                                               ; preds = %4
  %13 = and i32 %8, 4
  %.not28 = icmp eq i32 %13, 0
  br i1 %.not28, label %24, label %14

14:                                               ; preds = %12
  %15 = getelementptr inbounds i8, ptr %2, i64 10
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = zext i8 %16 to i32
  %18 = add nuw nsw i32 %17, 12
  %19 = getelementptr inbounds i8, ptr %2, i64 11
  %20 = load i8, ptr %19, align 1, !tbaa !5
  %21 = zext i8 %20 to i32
  %22 = shl nuw nsw i32 %21, 8
  %23 = add nuw nsw i32 %18, %22
  br label %24

24:                                               ; preds = %14, %12
  %.0 = phi i32 [ %23, %14 ], [ 10, %12 ]
  %25 = and i32 %8, 8
  %.not29 = icmp eq i32 %25, 0
  br i1 %.not29, label %.loopexit38, label %.preheader37.preheader

.preheader37.preheader:                           ; preds = %24
  %26 = zext nneg i32 %.0 to i64
  br label %.preheader37

.preheader37:                                     ; preds = %.preheader37.preheader, %.preheader37
  %indvars.iv = phi i64 [ %26, %.preheader37.preheader ], [ %indvars.iv.next, %.preheader37 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %27 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %.not30 = icmp eq i8 %28, 0
  br i1 %.not30, label %.loopexit38.loopexit, label %.preheader37, !llvm.loop !8

.loopexit38.loopexit:                             ; preds = %.preheader37
  %29 = trunc nsw i64 %indvars.iv.next to i32
  br label %.loopexit38

.loopexit38:                                      ; preds = %.loopexit38.loopexit, %24
  %.2 = phi i32 [ %.0, %24 ], [ %29, %.loopexit38.loopexit ]
  %.not31 = icmp ult i8 %7, 16
  br i1 %.not31, label %.loopexit, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.loopexit38
  %30 = sext i32 %.2 to i64
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %indvars.iv42 = phi i64 [ %30, %.preheader.preheader ], [ %indvars.iv.next43, %.preheader ]
  %indvars.iv.next43 = add nsw i64 %indvars.iv42, 1
  %31 = getelementptr inbounds i8, ptr %2, i64 %indvars.iv42
  %32 = load i8, ptr %31, align 1, !tbaa !5
  %.not32 = icmp eq i8 %32, 0
  br i1 %.not32, label %.loopexit.loopexit, label %.preheader, !llvm.loop !10

.loopexit.loopexit:                               ; preds = %.preheader
  %33 = trunc nsw i64 %indvars.iv.next43 to i32
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %.loopexit38
  %.4 = phi i32 [ %.2, %.loopexit38 ], [ %33, %.loopexit.loopexit ]
  %34 = and i32 %8, 2
  %spec.select = add i32 %.4, %34
  %35 = load i32, ptr %3, align 4, !tbaa !11
  %.not34 = icmp slt i32 %spec.select, %35
  br i1 %.not34, label %37, label %36

36:                                               ; preds = %.loopexit
  tail call void @exit() #5
  unreachable

37:                                               ; preds = %.loopexit
  %38 = tail call i32 @zlib_inflate_workspacesize() #4
  %39 = tail call ptr @zalloc(i32 noundef %38)
  %40 = getelementptr inbounds i8, ptr %5, i64 64
  store ptr %39, ptr %40, align 8, !tbaa !13
  %41 = call i32 @zlib_inflateInit2(ptr noundef nonnull %5, i32 noundef -15) #4
  %.not35 = icmp eq i32 %41, 0
  br i1 %.not35, label %43, label %42

42:                                               ; preds = %37
  call void @exit() #5
  unreachable

43:                                               ; preds = %37
  %44 = sext i32 %spec.select to i64
  %45 = getelementptr inbounds i8, ptr %2, i64 %44
  store ptr %45, ptr %5, align 8, !tbaa !17
  %46 = load i32, ptr %3, align 4, !tbaa !11
  %47 = sub nsw i32 %46, %spec.select
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds i8, ptr %5, i64 8
  store i64 %48, ptr %49, align 8, !tbaa !18
  %50 = getelementptr inbounds i8, ptr %5, i64 24
  store ptr %0, ptr %50, align 8, !tbaa !19
  %51 = sext i32 %1 to i64
  %52 = getelementptr inbounds i8, ptr %5, i64 32
  store i64 %51, ptr %52, align 8, !tbaa !20
  %53 = call i32 @zlib_inflate(ptr noundef nonnull %5, i32 noundef 5) #4
  %or.cond = icmp ugt i32 %53, 1
  br i1 %or.cond, label %54, label %55

54:                                               ; preds = %43
  call void @exit() #5
  unreachable

55:                                               ; preds = %43
  %56 = load ptr, ptr %50, align 8, !tbaa !19
  %57 = ptrtoint ptr %56 to i64
  %58 = ptrtoint ptr %0 to i64
  %59 = sub i64 %57, %58
  %60 = trunc i64 %59 to i32
  store i32 %60, ptr %3, align 4, !tbaa !11
  %61 = call i32 @zlib_inflateEnd(ptr noundef nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 96, ptr nonnull %5) #4
  ret void
}

declare i32 @zlib_inflate_workspacesize() local_unnamed_addr #3

declare i32 @zlib_inflateInit2(ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @zlib_inflate(ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @zlib_inflateEnd(ptr noundef) local_unnamed_addr #3

attributes #0 = { noreturn 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 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 memory(argmem: readwrite) }
attributes #3 = { "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 }
attributes #5 = { noreturn }

!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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}
!10 = distinct !{!10, !9}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !6, i64 0}
!13 = !{!14, !15, i64 64}
!14 = !{!"z_stream_s", !15, i64 0, !16, i64 8, !16, i64 16, !15, i64 24, !16, i64 32, !16, i64 40, !15, i64 48, !15, i64 56, !15, i64 64, !12, i64 72, !16, i64 80, !16, i64 88}
!15 = !{!"any pointer", !6, i64 0}
!16 = !{!"long", !6, i64 0}
!17 = !{!14, !15, i64 0}
!18 = !{!14, !16, i64 8}
!19 = !{!14, !15, i64 24}
!20 = !{!14, !16, i64 32}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass