; LLVM IR from dbry/wavpack-stream :: cli (wave64)

; 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.Wave64ChunkHeader = type { [16 x i8], i64 }
%struct.Wave64FileHeader = type { [16 x i8], i64, [16 x i8] }
%struct.WaveHeader = type { i16, i16, i32, i32, i16, i16, i16, i16, i32, i16, [14 x i8] }

@riff_guid = external hidden constant [16 x i8], align 16
@wave_guid = external hidden constant [16 x i8], align 16
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@fmt_guid = external hidden constant [16 x i8], align 16
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@data_guid = external hidden constant [16 x i8], align 16
@.str.18 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [43 x i8], align 1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

declare void @error_line(ptr noundef, ...) #2

; 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 @WriteWave64Header(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) #3 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.Wave64ChunkHeader, align 8
  %11 = alloca %struct.Wave64ChunkHeader, align 8
  %12 = alloca %struct.Wave64FileHeader, align 8
  %13 = alloca %struct.WaveHeader, align 4
  %14 = alloca i32, align 4
  %15 = alloca i64, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i32 %3, ptr %9, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 24, ptr %10) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr %11) #5
  call void @llvm.lifetime.start.p0(i64 40, ptr %12) #5
  call void @llvm.lifetime.start.p0(i64 40, ptr %13) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = call i32 @WavpackStreamGetNumChannels(ptr noundef %25)
  store i32 %26, ptr %17, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  %27 = load ptr, ptr %7, align 8, !tbaa !5
  %28 = call i32 @WavpackStreamGetChannelMask(ptr noundef %27)
  store i32 %28, ptr %18, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #5
  %29 = load ptr, ptr %7, align 8, !tbaa !5
  %30 = call i32 @WavpackStreamGetSampleRate(ptr noundef %29)
  store i32 %30, ptr %19, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #5
  %31 = load ptr, ptr %7, align 8, !tbaa !5
  %32 = call i32 @WavpackStreamGetBytesPerSample(ptr noundef %31)
  store i32 %32, ptr %20, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #5
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = call i32 @WavpackStreamGetBitsPerSample(ptr noundef %33)
  store i32 %34, ptr %21, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #5
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = call i32 @WavpackStreamGetFloatNormExp(ptr noundef %35)
  %37 = icmp ne i32 %36, 0
  %38 = zext i1 %37 to i64
  %39 = select i1 %37, i32 3, i32 1
  store i32 %39, ptr %22, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #5
  store i32 16, ptr %23, align 4, !tbaa !11
  %40 = load i32, ptr %22, align 4, !tbaa !11
  %41 = icmp eq i32 %40, 3
  br i1 %41, label %42, label %47

42:                                               ; preds = %4
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = call i32 @WavpackStreamGetFloatNormExp(ptr noundef %43)
  %45 = icmp ne i32 %44, 127
  br i1 %45, label %46, label %47

46:                                               ; preds = %42
  call void (ptr, ...) @error_line(ptr noundef @.str.18)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %24, align 4
  br label %180

47:                                               ; preds = %42, %4
  %48 = load i64, ptr %8, align 8, !tbaa !9
  %49 = icmp eq i64 %48, -1
  br i1 %49, label %50, label %56

50:                                               ; preds = %47
  %51 = load i32, ptr %20, align 4, !tbaa !11
  %52 = load i32, ptr %17, align 4, !tbaa !11
  %53 = mul nsw i32 %51, %52
  %54 = sdiv i32 2147479552, %53
  %55 = sext i32 %54 to i64
  store i64 %55, ptr %8, align 8, !tbaa !9
  br label %56

56:                                               ; preds = %50, %47
  %57 = load i64, ptr %8, align 8, !tbaa !9
  %58 = load i32, ptr %20, align 4, !tbaa !11
  %59 = sext i32 %58 to i64
  %60 = mul nsw i64 %57, %59
  %61 = load i32, ptr %17, align 4, !tbaa !11
  %62 = sext i32 %61 to i64
  %63 = mul nsw i64 %60, %62
  store i64 %63, ptr %15, align 8, !tbaa !9
  call void @llvm.memset.p0.i64(ptr align 4 %13, i8 0, i64 40, i1 false)
  %64 = load i32, ptr %22, align 4, !tbaa !11
  %65 = trunc i32 %64 to i16
  %66 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 0
  store i16 %65, ptr %66, align 4, !tbaa !13
  %67 = load i32, ptr %17, align 4, !tbaa !11
  %68 = trunc i32 %67 to i16
  %69 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 1
  store i16 %68, ptr %69, align 2, !tbaa !16
  %70 = load i32, ptr %19, align 4, !tbaa !11
  %71 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 2
  store i32 %70, ptr %71, align 4, !tbaa !17
  %72 = load i32, ptr %19, align 4, !tbaa !11
  %73 = load i32, ptr %17, align 4, !tbaa !11
  %74 = mul nsw i32 %72, %73
  %75 = load i32, ptr %20, align 4, !tbaa !11
  %76 = mul nsw i32 %74, %75
  %77 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 3
  store i32 %76, ptr %77, align 4, !tbaa !18
  %78 = load i32, ptr %20, align 4, !tbaa !11
  %79 = load i32, ptr %17, align 4, !tbaa !11
  %80 = mul nsw i32 %78, %79
  %81 = trunc i32 %80 to i16
  %82 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 4
  store i16 %81, ptr %82, align 4, !tbaa !19
  %83 = load i32, ptr %21, align 4, !tbaa !11
  %84 = trunc i32 %83 to i16
  %85 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 5
  store i16 %84, ptr %85, align 2, !tbaa !20
  %86 = load i32, ptr %17, align 4, !tbaa !11
  %87 = icmp sgt i32 %86, 2
  br i1 %87, label %93, label %88

88:                                               ; preds = %56
  %89 = load i32, ptr %18, align 4, !tbaa !11
  %90 = load i32, ptr %17, align 4, !tbaa !11
  %91 = sub nsw i32 5, %90
  %92 = icmp ne i32 %89, %91
  br i1 %92, label %93, label %120

93:                                               ; preds = %88, %56
  store i32 40, ptr %23, align 4, !tbaa !11
  %94 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 6
  store i16 22, ptr %94, align 4, !tbaa !21
  %95 = load i32, ptr %21, align 4, !tbaa !11
  %96 = trunc i32 %95 to i16
  %97 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 7
  store i16 %96, ptr %97, align 2, !tbaa !22
  %98 = load i32, ptr %22, align 4, !tbaa !11
  %99 = trunc i32 %98 to i16
  %100 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 9
  store i16 %99, ptr %100, align 4, !tbaa !23
  %101 = load i32, ptr %18, align 4, !tbaa !11
  %102 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 8
  store i32 %101, ptr %102, align 4, !tbaa !24
  %103 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 0
  store i16 -2, ptr %103, align 4, !tbaa !13
  %104 = load i32, ptr %20, align 4, !tbaa !11
  %105 = mul nsw i32 %104, 8
  %106 = trunc i32 %105 to i16
  %107 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 5
  store i16 %106, ptr %107, align 2, !tbaa !20
  %108 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 10
  %109 = getelementptr inbounds [14 x i8], ptr %108, i64 0, i64 4
  store i8 16, ptr %109, align 2, !tbaa !25
  %110 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 10
  %111 = getelementptr inbounds [14 x i8], ptr %110, i64 0, i64 6
  store i8 -128, ptr %111, align 2, !tbaa !25
  %112 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 10
  %113 = getelementptr inbounds [14 x i8], ptr %112, i64 0, i64 9
  store i8 -86, ptr %113, align 1, !tbaa !25
  %114 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 10
  %115 = getelementptr inbounds [14 x i8], ptr %114, i64 0, i64 11
  store i8 56, ptr %115, align 1, !tbaa !25
  %116 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 10
  %117 = getelementptr inbounds [14 x i8], ptr %116, i64 0, i64 12
  store i8 -101, ptr %117, align 2, !tbaa !25
  %118 = getelementptr inbounds %struct.WaveHeader, ptr %13, i32 0, i32 10
  %119 = getelementptr inbounds [14 x i8], ptr %118, i64 0, i64 13
  store i8 113, ptr %119, align 1, !tbaa !25
  br label %120

120:                                              ; preds = %93, %88
  %121 = load i32, ptr %23, align 4, !tbaa !11
  %122 = sext i32 %121 to i64
  %123 = add i64 64, %122
  %124 = add i64 %123, 24
  %125 = load i64, ptr %15, align 8, !tbaa !9
  %126 = add nsw i64 %125, 7
  %127 = and i64 %126, -8
  %128 = add i64 %124, %127
  store i64 %128, ptr %16, align 8, !tbaa !9
  %129 = getelementptr inbounds %struct.Wave64FileHeader, ptr %12, i32 0, i32 0
  %130 = getelementptr inbounds [16 x i8], ptr %129, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %130, ptr align 16 @riff_guid, i64 16, i1 false)
  %131 = getelementptr inbounds %struct.Wave64FileHeader, ptr %12, i32 0, i32 2
  %132 = getelementptr inbounds [16 x i8], ptr %131, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %132, ptr align 16 @wave_guid, i64 16, i1 false)
  %133 = load i64, ptr %16, align 8, !tbaa !9
  %134 = getelementptr inbounds %struct.Wave64FileHeader, ptr %12, i32 0, i32 1
  store i64 %133, ptr %134, align 8, !tbaa !26
  %135 = getelementptr inbounds %struct.Wave64ChunkHeader, ptr %11, i32 0, i32 0
  %136 = getelementptr inbounds [16 x i8], ptr %135, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %136, ptr align 16 @fmt_guid, i64 16, i1 false)
  %137 = load i32, ptr %23, align 4, !tbaa !11
  %138 = sext i32 %137 to i64
  %139 = add i64 24, %138
  %140 = getelementptr inbounds %struct.Wave64ChunkHeader, ptr %11, i32 0, i32 1
  store i64 %139, ptr %140, align 8, !tbaa !28
  %141 = getelementptr inbounds %struct.Wave64ChunkHeader, ptr %10, i32 0, i32 0
  %142 = getelementptr inbounds [16 x i8], ptr %141, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %142, ptr align 16 @data_guid, i64 16, i1 false)
  %143 = load i64, ptr %15, align 8, !tbaa !9
  %144 = add i64 %143, 24
  %145 = getelementptr inbounds %struct.Wave64ChunkHeader, ptr %10, i32 0, i32 1
  store i64 %144, ptr %145, align 8, !tbaa !28
  call void @WavpackStreamNativeToLittleEndian(ptr noundef %12, ptr noundef @.str.2)
  call void @WavpackStreamNativeToLittleEndian(ptr noundef %11, ptr noundef @.str.2)
  call void @WavpackStreamNativeToLittleEndian(ptr noundef %13, ptr noundef @.str.3)
  call void @WavpackStreamNativeToLittleEndian(ptr noundef %10, ptr noundef @.str.2)
  %146 = load ptr, ptr %6, align 8, !tbaa !5
  %147 = call i32 @DoWriteFile(ptr noundef %146, ptr noundef %12, i32 noundef 40, ptr noundef %14)
  %148 = icmp ne i32 %147, 0
  br i1 %148, label %149, label %178

149:                                              ; preds = %120
  %150 = load i32, ptr %14, align 4, !tbaa !11
  %151 = zext i32 %150 to i64
  %152 = icmp ne i64 %151, 40
  br i1 %152, label %178, label %153

153:                                              ; preds = %149
  %154 = load ptr, ptr %6, align 8, !tbaa !5
  %155 = call i32 @DoWriteFile(ptr noundef %154, ptr noundef %11, i32 noundef 24, ptr noundef %14)
  %156 = icmp ne i32 %155, 0
  br i1 %156, label %157, label %178

157:                                              ; preds = %153
  %158 = load i32, ptr %14, align 4, !tbaa !11
  %159 = zext i32 %158 to i64
  %160 = icmp ne i64 %159, 24
  br i1 %160, label %178, label %161

161:                                              ; preds = %157
  %162 = load ptr, ptr %6, align 8, !tbaa !5
  %163 = load i32, ptr %23, align 4, !tbaa !11
  %164 = call i32 @DoWriteFile(ptr noundef %162, ptr noundef %13, i32 noundef %163, ptr noundef %14)
  %165 = icmp ne i32 %164, 0
  br i1 %165, label %166, label %178

166:                                              ; preds = %161
  %167 = load i32, ptr %14, align 4, !tbaa !11
  %168 = load i32, ptr %23, align 4, !tbaa !11
  %169 = icmp ne i32 %167, %168
  br i1 %169, label %178, label %170

170:                                              ; preds = %166
  %171 = load ptr, ptr %6, align 8, !tbaa !5
  %172 = call i32 @DoWriteFile(ptr noundef %171, ptr noundef %10, i32 noundef 24, ptr noundef %14)
  %173 = icmp ne i32 %172, 0
  br i1 %173, label %174, label %178

174:                                              ; preds = %170
  %175 = load i32, ptr %14, align 4, !tbaa !11
  %176 = zext i32 %175 to i64
  %177 = icmp ne i64 %176, 24
  br i1 %177, label %178, label %179

178:                                              ; preds = %174, %170, %166, %161, %157, %153, %149, %120
  call void (ptr, ...) @error_line(ptr noundef @.str.19)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %24, align 4
  br label %180

179:                                              ; preds = %174
  store i32 1, ptr %5, align 4
  store i32 1, ptr %24, align 4
  br label %180

180:                                              ; preds = %179, %178, %46
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr %10) #5
  %181 = load i32, ptr %5, align 4
  ret i32 %181
}

declare i32 @WavpackStreamGetNumChannels(ptr noundef) #2

declare i32 @WavpackStreamGetChannelMask(ptr noundef) #2

declare i32 @WavpackStreamGetSampleRate(ptr noundef) #2

declare i32 @WavpackStreamGetBytesPerSample(ptr noundef) #2

declare i32 @WavpackStreamGetBitsPerSample(ptr noundef) #2

declare i32 @WavpackStreamGetFloatNormExp(ptr noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

declare void @WavpackStreamNativeToLittleEndian(ptr noundef, ptr noundef) #2

declare i32 @DoWriteFile(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 #3 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !15, i64 0}
!14 = !{!"", !15, i64 0, !15, i64 2, !12, i64 4, !12, i64 8, !15, i64 12, !15, i64 14, !15, i64 16, !15, i64 18, !12, i64 20, !15, i64 24, !7, i64 26}
!15 = !{!"short", !7, i64 0}
!16 = !{!14, !15, i64 2}
!17 = !{!14, !12, i64 4}
!18 = !{!14, !12, i64 8}
!19 = !{!14, !15, i64 12}
!20 = !{!14, !15, i64 14}
!21 = !{!14, !15, i64 16}
!22 = !{!14, !15, i64 18}
!23 = !{!14, !15, i64 24}
!24 = !{!14, !12, i64 20}
!25 = !{!7, !7, i64 0}
!26 = !{!27, !10, i64 16}
!27 = !{!"", !7, i64 0, !10, i64 16, !7, i64 24}
!28 = !{!29, !10, i64 16}
!29 = !{!"", !7, i64 0, !10, 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.Wave64ChunkHeader = type { [16 x i8], i64 }
%struct.Wave64FileHeader = type { [16 x i8], i64, [16 x i8] }
%struct.WaveHeader = type { i16, i16, i32, i32, i16, i16, i16, i16, i32, i16, [14 x i8] }

@riff_guid = external hidden local_unnamed_addr constant [16 x i8], align 16
@wave_guid = external hidden local_unnamed_addr constant [16 x i8], align 16
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1
@fmt_guid = external hidden local_unnamed_addr constant [16 x i8], align 16
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@data_guid = external hidden local_unnamed_addr constant [16 x i8], align 16
@.str.18 = external hidden unnamed_addr constant [67 x i8], align 1
@.str.19 = external hidden unnamed_addr constant [43 x i8], align 1

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

declare void @error_line(ptr noundef, ...) local_unnamed_addr #2

; 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 0, 2) i32 @WriteWave64Header(ptr noundef %0, ptr noundef %1, i64 noundef %2, i32 noundef %3) local_unnamed_addr #3 {
  %5 = alloca %struct.Wave64ChunkHeader, align 8
  %6 = alloca %struct.Wave64ChunkHeader, align 8
  %7 = alloca %struct.Wave64FileHeader, align 8
  %8 = alloca %struct.WaveHeader, align 4
  %9 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %6) #5
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %7) #5
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %8) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #5
  %10 = tail call i32 @WavpackStreamGetNumChannels(ptr noundef %1) #5
  %11 = tail call i32 @WavpackStreamGetChannelMask(ptr noundef %1) #5
  %12 = tail call i32 @WavpackStreamGetSampleRate(ptr noundef %1) #5
  %13 = tail call i32 @WavpackStreamGetBytesPerSample(ptr noundef %1) #5
  %14 = tail call i32 @WavpackStreamGetBitsPerSample(ptr noundef %1) #5
  %15 = tail call i32 @WavpackStreamGetFloatNormExp(ptr noundef %1) #5
  %.not = icmp eq i32 %15, 0
  br i1 %.not, label %19, label %16

16:                                               ; preds = %4
  %17 = tail call i32 @WavpackStreamGetFloatNormExp(ptr noundef %1) #5
  %.not53 = icmp eq i32 %17, 127
  br i1 %.not53, label %19, label %18

18:                                               ; preds = %16
  tail call void (ptr, ...) @error_line(ptr noundef nonnull @.str.18) #5
  br label %84

19:                                               ; preds = %16, %4
  %20 = icmp eq i64 %2, -1
  %21 = mul i32 %13, %10
  br i1 %20, label %22, label %._crit_edge

22:                                               ; preds = %19
  %23 = sdiv i32 2147479552, %21
  %24 = sext i32 %23 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %19, %22
  %.050 = phi i64 [ %24, %22 ], [ %2, %19 ]
  %25 = sext i32 %13 to i64
  %26 = sext i32 %10 to i64
  %27 = mul nsw i64 %25, %26
  %28 = mul i64 %27, %.050
  %29 = getelementptr inbounds i8, ptr %8, i64 16
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(40) %29, i8 0, i64 24, i1 false)
  %30 = select i1 %.not, i16 1, i16 3
  store i16 %30, ptr %8, align 4, !tbaa !5
  %31 = trunc i32 %10 to i16
  %32 = getelementptr inbounds i8, ptr %8, i64 2
  store i16 %31, ptr %32, align 2, !tbaa !11
  %33 = getelementptr inbounds i8, ptr %8, i64 4
  store i32 %12, ptr %33, align 4, !tbaa !12
  %34 = mul i32 %21, %12
  %35 = getelementptr inbounds i8, ptr %8, i64 8
  store i32 %34, ptr %35, align 4, !tbaa !13
  %36 = trunc i32 %21 to i16
  %37 = getelementptr inbounds i8, ptr %8, i64 12
  store i16 %36, ptr %37, align 4, !tbaa !14
  %38 = trunc i32 %14 to i16
  %39 = getelementptr inbounds i8, ptr %8, i64 14
  store i16 %38, ptr %39, align 2, !tbaa !15
  %40 = icmp slt i32 %10, 3
  %41 = sub nsw i32 5, %10
  %.not54 = icmp eq i32 %11, %41
  %or.cond57 = select i1 %40, i1 %.not54, i1 false
  br i1 %or.cond57, label %54, label %42

42:                                               ; preds = %._crit_edge
  %43 = getelementptr inbounds i8, ptr %8, i64 16
  store i16 22, ptr %43, align 4, !tbaa !16
  %44 = getelementptr inbounds i8, ptr %8, i64 18
  store i16 %38, ptr %44, align 2, !tbaa !17
  %45 = getelementptr inbounds i8, ptr %8, i64 24
  store i16 %30, ptr %45, align 4, !tbaa !18
  %46 = getelementptr inbounds i8, ptr %8, i64 20
  store i32 %11, ptr %46, align 4, !tbaa !19
  store i16 -2, ptr %8, align 4, !tbaa !5
  %.tr = trunc i32 %13 to i16
  %47 = shl i16 %.tr, 3
  store i16 %47, ptr %39, align 2, !tbaa !15
  %48 = getelementptr inbounds i8, ptr %8, i64 30
  store i8 16, ptr %48, align 2, !tbaa !20
  %49 = getelementptr inbounds i8, ptr %8, i64 32
  store i8 -128, ptr %49, align 4, !tbaa !20
  %50 = getelementptr inbounds i8, ptr %8, i64 35
  store i8 -86, ptr %50, align 1, !tbaa !20
  %51 = getelementptr inbounds i8, ptr %8, i64 37
  store i8 56, ptr %51, align 1, !tbaa !20
  %52 = getelementptr inbounds i8, ptr %8, i64 38
  store i8 -101, ptr %52, align 2, !tbaa !20
  %53 = getelementptr inbounds i8, ptr %8, i64 39
  store i8 113, ptr %53, align 1, !tbaa !20
  br label %54

54:                                               ; preds = %._crit_edge, %42
  %.0 = phi i32 [ 40, %42 ], [ 16, %._crit_edge ]
  %55 = zext nneg i32 %.0 to i64
  %56 = add nsw i64 %28, 7
  %57 = and i64 %56, -8
  %58 = add i64 %57, 88
  %59 = add i64 %58, %55
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %7, ptr noundef nonnull align 16 dereferenceable(16) @riff_guid, i64 16, i1 false)
  %60 = getelementptr inbounds i8, ptr %7, i64 24
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %60, ptr noundef nonnull align 16 dereferenceable(16) @wave_guid, i64 16, i1 false)
  %61 = getelementptr inbounds i8, ptr %7, i64 16
  store i64 %59, ptr %61, align 8, !tbaa !21
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 16 dereferenceable(16) @fmt_guid, i64 16, i1 false)
  %62 = add nuw nsw i64 %55, 24
  %63 = getelementptr inbounds i8, ptr %6, i64 16
  store i64 %62, ptr %63, align 8, !tbaa !24
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 16 dereferenceable(16) @data_guid, i64 16, i1 false)
  %64 = add i64 %28, 24
  %65 = getelementptr inbounds i8, ptr %5, i64 16
  store i64 %64, ptr %65, align 8, !tbaa !24
  call void @WavpackStreamNativeToLittleEndian(ptr noundef nonnull %7, ptr noundef nonnull @.str.2) #5
  call void @WavpackStreamNativeToLittleEndian(ptr noundef nonnull %6, ptr noundef nonnull @.str.2) #5
  call void @WavpackStreamNativeToLittleEndian(ptr noundef nonnull %8, ptr noundef nonnull @.str.3) #5
  call void @WavpackStreamNativeToLittleEndian(ptr noundef nonnull %5, ptr noundef nonnull @.str.2) #5
  %66 = call i32 @DoWriteFile(ptr noundef %0, ptr noundef nonnull %7, i32 noundef 40, ptr noundef nonnull %9) #5
  %67 = icmp eq i32 %66, 0
  %68 = load i32, ptr %9, align 4
  %69 = icmp ne i32 %68, 40
  %or.cond = select i1 %67, i1 true, i1 %69
  br i1 %or.cond, label %83, label %70

70:                                               ; preds = %54
  %71 = call i32 @DoWriteFile(ptr noundef %0, ptr noundef nonnull %6, i32 noundef 24, ptr noundef nonnull %9) #5
  %72 = icmp eq i32 %71, 0
  %73 = load i32, ptr %9, align 4
  %74 = icmp ne i32 %73, 24
  %or.cond5 = select i1 %72, i1 true, i1 %74
  br i1 %or.cond5, label %83, label %75

75:                                               ; preds = %70
  %76 = call i32 @DoWriteFile(ptr noundef %0, ptr noundef nonnull %8, i32 noundef %.0, ptr noundef nonnull %9) #5
  %.not55 = icmp ne i32 %76, 0
  %77 = load i32, ptr %9, align 4
  %.not56 = icmp eq i32 %77, %.0
  %or.cond58 = select i1 %.not55, i1 %.not56, i1 false
  br i1 %or.cond58, label %78, label %83

78:                                               ; preds = %75
  %79 = call i32 @DoWriteFile(ptr noundef %0, ptr noundef nonnull %5, i32 noundef 24, ptr noundef nonnull %9) #5
  %80 = icmp eq i32 %79, 0
  %81 = load i32, ptr %9, align 4
  %82 = icmp ne i32 %81, 24
  %or.cond8 = select i1 %80, i1 true, i1 %82
  br i1 %or.cond8, label %83, label %84

83:                                               ; preds = %78, %75, %70, %54
  call void (ptr, ...) @error_line(ptr noundef nonnull @.str.19) #5
  br label %84

84:                                               ; preds = %78, %83, %18
  %.049 = phi i32 [ 0, %18 ], [ 0, %83 ], [ 1, %78 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %7) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %5) #5
  ret i32 %.049
}

declare i32 @WavpackStreamGetNumChannels(ptr noundef) local_unnamed_addr #2

declare i32 @WavpackStreamGetChannelMask(ptr noundef) local_unnamed_addr #2

declare i32 @WavpackStreamGetSampleRate(ptr noundef) local_unnamed_addr #2

declare i32 @WavpackStreamGetBytesPerSample(ptr noundef) local_unnamed_addr #2

declare i32 @WavpackStreamGetBitsPerSample(ptr noundef) local_unnamed_addr #2

declare i32 @WavpackStreamGetFloatNormExp(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #4

declare void @WavpackStreamNativeToLittleEndian(ptr noundef, ptr noundef) local_unnamed_addr #2

declare i32 @DoWriteFile(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 #3 = { 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 #4 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 2, !10, i64 4, !10, i64 8, !7, i64 12, !7, i64 14, !7, i64 16, !7, i64 18, !10, i64 20, !7, i64 24, !8, i64 26}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 2}
!12 = !{!6, !10, i64 4}
!13 = !{!6, !10, i64 8}
!14 = !{!6, !7, i64 12}
!15 = !{!6, !7, i64 14}
!16 = !{!6, !7, i64 16}
!17 = !{!6, !7, i64 18}
!18 = !{!6, !7, i64 24}
!19 = !{!6, !10, i64 20}
!20 = !{!8, !8, i64 0}
!21 = !{!22, !23, i64 16}
!22 = !{!"", !8, i64 0, !23, i64 16, !8, i64 24}
!23 = !{!"long", !8, i64 0}
!24 = !{!25, !23, i64 16}
!25 = !{!"", !8, i64 0, !23, i64 16}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass