; LLVM IR from GPUOpen-LibrariesAndSDKs/TAN :: tan/common/wav.ll (Z14WriteWaveFileFPKciiilPPf)

; 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.RiffWave = type { %struct.RiffHeader, %struct.WaveHeader }
%struct.RiffHeader = type { [4 x i8], i32 }
%struct.WaveHeader = type { [4 x i8], %struct.WaveFormat, %struct.DataHeader }
%struct.WaveFormat = type { [4 x i8], i32, %struct.WaveInfo }
%struct.WaveInfo = type { i16, i16, i32, i32, i16, i16 }
%struct.DataHeader = type { [4 x i8], i32 }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z15SetupWaveHeaderP8RiffWavejttj(ptr noundef, i32 noundef, i16 noundef zeroext, i16 noundef zeroext, 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare noundef signext i8 @_Z7fopen_sPP8_IO_FILEPKcS3_(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #3

declare i32 @fclose(ptr noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z14WriteWaveFileFPKciiilPPf(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i64 noundef %4, ptr noundef %5) #4 {
  %7 = alloca i1, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  %13 = alloca ptr, align 8
  %14 = alloca %struct.RiffWave, align 1
  %15 = alloca ptr, align 8
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca ptr, align 8
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca i32, align 4
  %24 = alloca float, align 4
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  %27 = alloca i32, align 4
  %28 = alloca float, align 4
  %29 = alloca i32, align 4
  %30 = alloca i32, align 4
  %31 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store i32 %2, ptr %10, align 4, !tbaa !9
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i64 %4, ptr %12, align 8, !tbaa !11
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 44, ptr %14) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #5
  %32 = load i32, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %11, align 4, !tbaa !9
  %34 = trunc i32 %33 to i16
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = trunc i32 %35 to i16
  %37 = load i64, ptr %12, align 8, !tbaa !11
  %38 = trunc i64 %37 to i32
  call void @_Z15SetupWaveHeaderP8RiffWavejttj(ptr noundef %14, i32 noundef %32, i16 noundef zeroext %34, i16 noundef zeroext %36, i32 noundef %38)
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #5
  %39 = load i32, ptr %11, align 4, !tbaa !9
  %40 = sdiv i32 %39, 8
  store i32 %40, ptr %16, align 4, !tbaa !9
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = call noundef signext i8 @_Z7fopen_sPP8_IO_FILEPKcS3_(ptr noundef %15, ptr noundef %41, ptr noundef @.str.15)
  %43 = sext i8 %42 to i32
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %48, label %45

45:                                               ; preds = %6
  %46 = load ptr, ptr %15, align 8, !tbaa !5
  %47 = icmp ne ptr %46, null
  br i1 %47, label %49, label %48

48:                                               ; preds = %45, %6
  store i1 false, ptr %7, align 1
  store i32 1, ptr %17, align 4
  br label %225

49:                                               ; preds = %45
  %50 = load ptr, ptr %15, align 8, !tbaa !5
  %51 = call i64 @fwrite(ptr noundef %14, i64 noundef 44, i64 noundef 1, ptr noundef %50)
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  %52 = load i32, ptr %16, align 4, !tbaa !9
  %53 = load i32, ptr %10, align 4, !tbaa !9
  %54 = mul nsw i32 %52, %53
  %55 = sext i32 %54 to i64
  %56 = load i64, ptr %12, align 8, !tbaa !11
  %57 = mul nsw i64 %55, %56
  %58 = call noalias noundef nonnull ptr @_Znam(i64 noundef %57) #6
  store ptr %58, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #5
  %59 = load ptr, ptr %18, align 8, !tbaa !5
  store ptr %59, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #5
  %60 = load ptr, ptr %18, align 8, !tbaa !5
  store ptr %60, ptr %20, align 8, !tbaa !5
  %61 = load i32, ptr %16, align 4, !tbaa !9
  switch i32 %61, label %210 [
    i32 1, label %62
    i32 2, label %116
    i32 4, label %170
  ]

62:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #5
  store i32 0, ptr %21, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %112, %62
  %64 = load i32, ptr %21, align 4, !tbaa !9
  %65 = sext i32 %64 to i64
  %66 = load i64, ptr %12, align 8, !tbaa !11
  %67 = icmp slt i64 %65, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %63
  store i32 3, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #5
  br label %115

69:                                               ; preds = %63
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #5
  %70 = load i32, ptr %21, align 4, !tbaa !9
  %71 = load i32, ptr %10, align 4, !tbaa !9
  %72 = mul nsw i32 %70, %71
  store i32 %72, ptr %22, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #5
  store i32 0, ptr %23, align 4, !tbaa !9
  br label %73

73:                                               ; preds = %108, %69
  %74 = load i32, ptr %23, align 4, !tbaa !9
  %75 = load i32, ptr %10, align 4, !tbaa !9
  %76 = icmp slt i32 %74, %75
  br i1 %76, label %78, label %77

77:                                               ; preds = %73
  store i32 6, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #5
  br label %111

78:                                               ; preds = %73
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #5
  %79 = load ptr, ptr %13, align 8, !tbaa !5
  %80 = load i32, ptr %23, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds ptr, ptr %79, i64 %81
  %83 = load ptr, ptr %82, align 8, !tbaa !5
  %84 = load i32, ptr %21, align 4, !tbaa !9
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds float, ptr %83, i64 %85
  %87 = load float, ptr %86, align 4, !tbaa !13
  store float %87, ptr %24, align 4, !tbaa !13
  %88 = load float, ptr %24, align 4, !tbaa !13
  %89 = fpext float %88 to double
  %90 = fcmp ogt double %89, 1.000000e+00
  br i1 %90, label %91, label %92

91:                                               ; preds = %78
  store float 1.000000e+00, ptr %24, align 4, !tbaa !13
  br label %92

92:                                               ; preds = %91, %78
  %93 = load float, ptr %24, align 4, !tbaa !13
  %94 = fpext float %93 to double
  %95 = fcmp olt double %94, -1.000000e+00
  br i1 %95, label %96, label %97

96:                                               ; preds = %92
  store float -1.000000e+00, ptr %24, align 4, !tbaa !13
  br label %97

97:                                               ; preds = %96, %92
  %98 = load float, ptr %24, align 4, !tbaa !13
  %99 = fpext float %98 to double
  %100 = fmul double %99, 1.270000e+02
  %101 = fptosi double %100 to i8
  %102 = load ptr, ptr %18, align 8, !tbaa !5
  %103 = load i32, ptr %22, align 4, !tbaa !9
  %104 = load i32, ptr %23, align 4, !tbaa !9
  %105 = add nsw i32 %103, %104
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds i8, ptr %102, i64 %106
  store i8 %101, ptr %107, align 1, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #5
  br label %108

108:                                              ; preds = %97
  %109 = load i32, ptr %23, align 4, !tbaa !9
  %110 = add nsw i32 %109, 1
  store i32 %110, ptr %23, align 4, !tbaa !9
  br label %73, !llvm.loop !16

111:                                              ; preds = %77
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #5
  br label %112

112:                                              ; preds = %111
  %113 = load i32, ptr %21, align 4, !tbaa !9
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %21, align 4, !tbaa !9
  br label %63, !llvm.loop !18

115:                                              ; preds = %68
  br label %211

116:                                              ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #5
  store i32 0, ptr %25, align 4, !tbaa !9
  br label %117

117:                                              ; preds = %166, %116
  %118 = load i32, ptr %25, align 4, !tbaa !9
  %119 = sext i32 %118 to i64
  %120 = load i64, ptr %12, align 8, !tbaa !11
  %121 = icmp slt i64 %119, %120
  br i1 %121, label %123, label %122

122:                                              ; preds = %117
  store i32 9, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #5
  br label %169

123:                                              ; preds = %117
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #5
  %124 = load i32, ptr %25, align 4, !tbaa !9
  %125 = load i32, ptr %10, align 4, !tbaa !9
  %126 = mul nsw i32 %124, %125
  store i32 %126, ptr %26, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %27) #5
  store i32 0, ptr %27, align 4, !tbaa !9
  br label %127

127:                                              ; preds = %162, %123
  %128 = load i32, ptr %27, align 4, !tbaa !9
  %129 = load i32, ptr %10, align 4, !tbaa !9
  %130 = icmp slt i32 %128, %129
  br i1 %130, label %132, label %131

131:                                              ; preds = %127
  store i32 12, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %27) #5
  br label %165

132:                                              ; preds = %127
  call void @llvm.lifetime.start.p0(i64 4, ptr %28) #5
  %133 = load ptr, ptr %13, align 8, !tbaa !5
  %134 = load i32, ptr %27, align 4, !tbaa !9
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds ptr, ptr %133, i64 %135
  %137 = load ptr, ptr %136, align 8, !tbaa !5
  %138 = load i32, ptr %25, align 4, !tbaa !9
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds float, ptr %137, i64 %139
  %141 = load float, ptr %140, align 4, !tbaa !13
  store float %141, ptr %28, align 4, !tbaa !13
  %142 = load float, ptr %28, align 4, !tbaa !13
  %143 = fpext float %142 to double
  %144 = fcmp ogt double %143, 1.000000e+00
  br i1 %144, label %145, label %146

145:                                              ; preds = %132
  store float 1.000000e+00, ptr %28, align 4, !tbaa !13
  br label %146

146:                                              ; preds = %145, %132
  %147 = load float, ptr %28, align 4, !tbaa !13
  %148 = fpext float %147 to double
  %149 = fcmp olt double %148, -1.000000e+00
  br i1 %149, label %150, label %151

150:                                              ; preds = %146
  store float -1.000000e+00, ptr %28, align 4, !tbaa !13
  br label %151

151:                                              ; preds = %150, %146
  %152 = load float, ptr %28, align 4, !tbaa !13
  %153 = fpext float %152 to double
  %154 = fmul double %153, 3.276700e+04
  %155 = fptosi double %154 to i16
  %156 = load ptr, ptr %19, align 8, !tbaa !5
  %157 = load i32, ptr %26, align 4, !tbaa !9
  %158 = load i32, ptr %27, align 4, !tbaa !9
  %159 = add nsw i32 %157, %158
  %160 = sext i32 %159 to i64
  %161 = getelementptr inbounds i16, ptr %156, i64 %160
  store i16 %155, ptr %161, align 2, !tbaa !19
  call void @llvm.lifetime.end.p0(i64 4, ptr %28) #5
  br label %162

162:                                              ; preds = %151
  %163 = load i32, ptr %27, align 4, !tbaa !9
  %164 = add nsw i32 %163, 1
  store i32 %164, ptr %27, align 4, !tbaa !9
  br label %127, !llvm.loop !21

165:                                              ; preds = %131
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #5
  br label %166

166:                                              ; preds = %165
  %167 = load i32, ptr %25, align 4, !tbaa !9
  %168 = add nsw i32 %167, 1
  store i32 %168, ptr %25, align 4, !tbaa !9
  br label %117, !llvm.loop !22

169:                                              ; preds = %122
  br label %211

170:                                              ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %29) #5
  store i32 0, ptr %29, align 4, !tbaa !9
  br label %171

171:                                              ; preds = %206, %170
  %172 = load i32, ptr %29, align 4, !tbaa !9
  %173 = sext i32 %172 to i64
  %174 = load i64, ptr %12, align 8, !tbaa !11
  %175 = icmp slt i64 %173, %174
  br i1 %175, label %177, label %176

176:                                              ; preds = %171
  store i32 15, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %29) #5
  br label %209

177:                                              ; preds = %171
  call void @llvm.lifetime.start.p0(i64 4, ptr %30) #5
  %178 = load i32, ptr %29, align 4, !tbaa !9
  %179 = load i32, ptr %10, align 4, !tbaa !9
  %180 = mul nsw i32 %178, %179
  store i32 %180, ptr %30, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %31) #5
  store i32 0, ptr %31, align 4, !tbaa !9
  br label %181

181:                                              ; preds = %202, %177
  %182 = load i32, ptr %31, align 4, !tbaa !9
  %183 = load i32, ptr %10, align 4, !tbaa !9
  %184 = icmp slt i32 %182, %183
  br i1 %184, label %186, label %185

185:                                              ; preds = %181
  store i32 18, ptr %17, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %31) #5
  br label %205

186:                                              ; preds = %181
  %187 = load ptr, ptr %13, align 8, !tbaa !5
  %188 = load i32, ptr %31, align 4, !tbaa !9
  %189 = sext i32 %188 to i64
  %190 = getelementptr inbounds ptr, ptr %187, i64 %189
  %191 = load ptr, ptr %190, align 8, !tbaa !5
  %192 = load i32, ptr %29, align 4, !tbaa !9
  %193 = sext i32 %192 to i64
  %194 = getelementptr inbounds float, ptr %191, i64 %193
  %195 = load float, ptr %194, align 4, !tbaa !13
  %196 = load ptr, ptr %20, align 8, !tbaa !5
  %197 = load i32, ptr %30, align 4, !tbaa !9
  %198 = load i32, ptr %31, align 4, !tbaa !9
  %199 = add nsw i32 %197, %198
  %200 = sext i32 %199 to i64
  %201 = getelementptr inbounds float, ptr %196, i64 %200
  store float %195, ptr %201, align 4, !tbaa !13
  br label %202

202:                                              ; preds = %186
  %203 = load i32, ptr %31, align 4, !tbaa !9
  %204 = add nsw i32 %203, 1
  store i32 %204, ptr %31, align 4, !tbaa !9
  br label %181, !llvm.loop !23

205:                                              ; preds = %185
  call void @llvm.lifetime.end.p0(i64 4, ptr %30) #5
  br label %206

206:                                              ; preds = %205
  %207 = load i32, ptr %29, align 4, !tbaa !9
  %208 = add nsw i32 %207, 1
  store i32 %208, ptr %29, align 4, !tbaa !9
  br label %171, !llvm.loop !24

209:                                              ; preds = %176
  br label %211

210:                                              ; preds = %49
  store i1 false, ptr %7, align 1
  store i32 1, ptr %17, align 4
  br label %224

211:                                              ; preds = %209, %169, %115
  %212 = load ptr, ptr %18, align 8, !tbaa !5
  %213 = load i64, ptr %12, align 8, !tbaa !11
  %214 = load i32, ptr %10, align 4, !tbaa !9
  %215 = sext i32 %214 to i64
  %216 = mul nsw i64 %213, %215
  %217 = load i32, ptr %16, align 4, !tbaa !9
  %218 = sext i32 %217 to i64
  %219 = mul nsw i64 %216, %218
  %220 = load ptr, ptr %15, align 8, !tbaa !5
  %221 = call i64 @fwrite(ptr noundef %212, i64 noundef %219, i64 noundef 1, ptr noundef %220)
  %222 = load ptr, ptr %15, align 8, !tbaa !5
  %223 = call i32 @fclose(ptr noundef %222)
  store i1 false, ptr %7, align 1
  store i32 1, ptr %17, align 4
  br label %224

224:                                              ; preds = %211, %210
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  br label %225

225:                                              ; preds = %224, %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #5
  call void @llvm.lifetime.end.p0(i64 44, ptr %14) #5
  %226 = load i1, ptr %7, align 1
  ret i1 %226
}

declare i64 @fwrite(ptr noundef, i64 noundef, i64 noundef, ptr noundef) #2

attributes #0 = { mustprogress 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 = { "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 = { nobuiltin allocsize(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 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"float", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = !{!20, !20, i64 0}
!20 = !{!"short", !7, i64 0}
!21 = distinct !{!21, !17}
!22 = distinct !{!22, !17}
!23 = distinct !{!23, !17}
!24 = distinct !{!24, !17}


; 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.RiffWave = type { %struct.RiffHeader, %struct.WaveHeader }
%struct.RiffHeader = type { [4 x i8], i32 }
%struct.WaveHeader = type { [4 x i8], %struct.WaveFormat, %struct.DataHeader }
%struct.WaveFormat = type { [4 x i8], i32, %struct.WaveInfo }
%struct.WaveInfo = type { i16, i16, i32, i32, i16, i16 }
%struct.DataHeader = type { [4 x i8], i32 }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_Z15SetupWaveHeaderP8RiffWavejttj(ptr noundef, i32 noundef, i16 noundef zeroext, i16 noundef zeroext, 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

declare noundef signext i8 @_Z7fopen_sPP8_IO_FILEPKcS3_(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fclose(ptr nocapture noundef) local_unnamed_addr #4

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z14WriteWaveFileFPKciiilPPf(ptr noundef %0, i32 noundef %1, i32 noundef %2, i32 noundef %3, i64 noundef %4, ptr nocapture noundef readonly %5) local_unnamed_addr #5 {
  %7 = alloca %struct.RiffWave, align 1
  %8 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 44, ptr nonnull %7) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #6
  %9 = trunc i32 %3 to i16
  %10 = trunc i32 %2 to i16
  %11 = trunc i64 %4 to i32
  call void @_Z15SetupWaveHeaderP8RiffWavejttj(ptr noundef nonnull %7, i32 noundef %1, i16 noundef zeroext %9, i16 noundef zeroext %10, i32 noundef %11)
  %12 = sdiv i32 %3, 8
  %13 = call noundef signext i8 @_Z7fopen_sPP8_IO_FILEPKcS3_(ptr noundef nonnull %8, ptr noundef %0, ptr noundef nonnull @.str.15)
  %14 = icmp eq i8 %13, 0
  %15 = load ptr, ptr %8, align 8
  %16 = icmp ne ptr %15, null
  %or.cond = select i1 %14, i1 %16, i1 false
  br i1 %or.cond, label %17, label %84

17:                                               ; preds = %6
  %18 = call i64 @fwrite(ptr noundef nonnull %7, i64 noundef 44, i64 noundef 1, ptr noundef nonnull %15)
  %19 = mul nsw i32 %12, %2
  %20 = sext i32 %19 to i64
  %21 = mul nsw i64 %20, %4
  %22 = call noalias noundef nonnull ptr @_Znam(i64 noundef %21) #7
  switch i32 %12, label %84 [
    i32 1, label %.preheader
    i32 2, label %.preheader79
    i32 4, label %.preheader81
  ]

.preheader81:                                     ; preds = %17
  %23 = icmp sgt i64 %4, 0
  %24 = icmp sgt i32 %2, 0
  %or.cond137 = and i1 %23, %24
  br i1 %or.cond137, label %.lr.ph.us.preheader, label %.loopexit

.lr.ph.us.preheader:                              ; preds = %.preheader81
  %25 = zext nneg i32 %2 to i64
  %xtraiter = and i64 %25, 3
  %26 = icmp ult i32 %2, 4
  %unroll_iter = and i64 %25, 2147483644
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br label %.lr.ph.us

.lr.ph.us:                                        ; preds = %.lr.ph.us.preheader, %._crit_edge.us
  %indvars.iv103 = phi i64 [ 0, %.lr.ph.us.preheader ], [ %indvars.iv.next104, %._crit_edge.us ]
  %27 = mul nuw nsw i64 %indvars.iv103, %25
  %invariant.gep = getelementptr inbounds float, ptr %22, i64 %27
  br i1 %26, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new

.lr.ph.us.new:                                    ; preds = %.lr.ph.us, %.lr.ph.us.new
  %indvars.iv = phi i64 [ %indvars.iv.next.3, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %niter = phi i64 [ %niter.next.3, %.lr.ph.us.new ], [ 0, %.lr.ph.us ]
  %28 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = getelementptr inbounds float, ptr %29, i64 %indvars.iv103
  %31 = load float, ptr %30, align 4, !tbaa !9
  %gep = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv
  store float %31, ptr %gep, align 4, !tbaa !9
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %32 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv.next
  %33 = load ptr, ptr %32, align 8, !tbaa !5
  %34 = getelementptr inbounds float, ptr %33, i64 %indvars.iv103
  %35 = load float, ptr %34, align 4, !tbaa !9
  %gep.1 = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.next
  store float %35, ptr %gep.1, align 4, !tbaa !9
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %36 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv.next.1
  %37 = load ptr, ptr %36, align 8, !tbaa !5
  %38 = getelementptr inbounds float, ptr %37, i64 %indvars.iv103
  %39 = load float, ptr %38, align 4, !tbaa !9
  %gep.2 = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.next.1
  store float %39, ptr %gep.2, align 4, !tbaa !9
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %40 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv.next.2
  %41 = load ptr, ptr %40, align 8, !tbaa !5
  %42 = getelementptr inbounds float, ptr %41, i64 %indvars.iv103
  %43 = load float, ptr %42, align 4, !tbaa !9
  %gep.3 = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.next.2
  store float %43, ptr %gep.3, align 4, !tbaa !9
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.us.unr-lcssa, label %.lr.ph.us.new, !llvm.loop !11

._crit_edge.us.unr-lcssa:                         ; preds = %.lr.ph.us.new, %.lr.ph.us
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.us ], [ %indvars.iv.next.3, %.lr.ph.us.new ]
  br i1 %lcmp.mod.not, label %._crit_edge.us, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.us.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.us.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.us.unr-lcssa ]
  %44 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv.epil
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = getelementptr inbounds float, ptr %45, i64 %indvars.iv103
  %47 = load float, ptr %46, align 4, !tbaa !9
  %gep.epil = getelementptr inbounds float, ptr %invariant.gep, i64 %indvars.iv.epil
  store float %47, ptr %gep.epil, align 4, !tbaa !9
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge.us, label %.epil.preheader, !llvm.loop !13

._crit_edge.us:                                   ; preds = %.epil.preheader, %._crit_edge.us.unr-lcssa
  %indvars.iv.next104 = add nuw nsw i64 %indvars.iv103, 1
  %exitcond106.not = icmp eq i64 %indvars.iv.next104, %4
  br i1 %exitcond106.not, label %.loopexit, label %.lr.ph.us, !llvm.loop !15

.preheader79:                                     ; preds = %17
  %48 = icmp sgt i64 %4, 0
  %49 = icmp sgt i32 %2, 0
  %or.cond138 = and i1 %48, %49
  br i1 %or.cond138, label %.lr.ph.us89.preheader, label %.loopexit

.lr.ph.us89.preheader:                            ; preds = %.preheader79
  %50 = zext nneg i32 %2 to i64
  br label %.lr.ph.us89

.lr.ph.us89:                                      ; preds = %.lr.ph.us89.preheader, %._crit_edge.us90
  %indvars.iv115 = phi i64 [ 0, %.lr.ph.us89.preheader ], [ %indvars.iv.next116, %._crit_edge.us90 ]
  %51 = mul nuw nsw i64 %indvars.iv115, %50
  %invariant.gep133 = getelementptr inbounds i16, ptr %22, i64 %51
  br label %52

52:                                               ; preds = %.lr.ph.us89, %52
  %indvars.iv110 = phi i64 [ 0, %.lr.ph.us89 ], [ %indvars.iv.next111, %52 ]
  %53 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv110
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = getelementptr inbounds float, ptr %54, i64 %indvars.iv115
  %56 = load float, ptr %55, align 4, !tbaa !9
  %57 = fcmp ogt float %56, 1.000000e+00
  %.067.us = select i1 %57, float 1.000000e+00, float %56
  %58 = fcmp olt float %.067.us, -1.000000e+00
  %.168.us = select i1 %58, float -1.000000e+00, float %.067.us
  %59 = fpext float %.168.us to double
  %60 = fmul double %59, 3.276700e+04
  %61 = fptosi double %60 to i16
  %gep134 = getelementptr inbounds i16, ptr %invariant.gep133, i64 %indvars.iv110
  store i16 %61, ptr %gep134, align 2, !tbaa !16
  %indvars.iv.next111 = add nuw nsw i64 %indvars.iv110, 1
  %exitcond114.not = icmp eq i64 %indvars.iv.next111, %50
  br i1 %exitcond114.not, label %._crit_edge.us90, label %52, !llvm.loop !18

._crit_edge.us90:                                 ; preds = %52
  %indvars.iv.next116 = add nuw nsw i64 %indvars.iv115, 1
  %exitcond118.not = icmp eq i64 %indvars.iv.next116, %4
  br i1 %exitcond118.not, label %.loopexit, label %.lr.ph.us89, !llvm.loop !19

.preheader:                                       ; preds = %17
  %62 = icmp sgt i64 %4, 0
  %63 = icmp sgt i32 %2, 0
  %or.cond139 = and i1 %62, %63
  br i1 %or.cond139, label %.lr.ph.us94.preheader, label %.loopexit

.lr.ph.us94.preheader:                            ; preds = %.preheader
  %64 = zext nneg i32 %2 to i64
  br label %.lr.ph.us94

.lr.ph.us94:                                      ; preds = %.lr.ph.us94.preheader, %._crit_edge.us95
  %indvars.iv127 = phi i64 [ 0, %.lr.ph.us94.preheader ], [ %indvars.iv.next128, %._crit_edge.us95 ]
  %65 = mul nuw nsw i64 %indvars.iv127, %64
  %invariant.gep135 = getelementptr inbounds i8, ptr %22, i64 %65
  br label %66

66:                                               ; preds = %.lr.ph.us94, %66
  %indvars.iv122 = phi i64 [ 0, %.lr.ph.us94 ], [ %indvars.iv.next123, %66 ]
  %67 = getelementptr inbounds ptr, ptr %5, i64 %indvars.iv122
  %68 = load ptr, ptr %67, align 8, !tbaa !5
  %69 = getelementptr inbounds float, ptr %68, i64 %indvars.iv127
  %70 = load float, ptr %69, align 4, !tbaa !9
  %71 = fcmp ogt float %70, 1.000000e+00
  %.071.us = select i1 %71, float 1.000000e+00, float %70
  %72 = fcmp olt float %.071.us, -1.000000e+00
  %.172.us = select i1 %72, float -1.000000e+00, float %.071.us
  %73 = fpext float %.172.us to double
  %74 = fmul double %73, 1.270000e+02
  %75 = fptosi double %74 to i8
  %gep136 = getelementptr inbounds i8, ptr %invariant.gep135, i64 %indvars.iv122
  store i8 %75, ptr %gep136, align 1, !tbaa !20
  %indvars.iv.next123 = add nuw nsw i64 %indvars.iv122, 1
  %exitcond126.not = icmp eq i64 %indvars.iv.next123, %64
  br i1 %exitcond126.not, label %._crit_edge.us95, label %66, !llvm.loop !21

._crit_edge.us95:                                 ; preds = %66
  %indvars.iv.next128 = add nuw nsw i64 %indvars.iv127, 1
  %exitcond130.not = icmp eq i64 %indvars.iv.next128, %4
  br i1 %exitcond130.not, label %.loopexit, label %.lr.ph.us94, !llvm.loop !22

.loopexit:                                        ; preds = %._crit_edge.us, %._crit_edge.us90, %._crit_edge.us95, %.preheader81, %.preheader79, %.preheader
  %76 = sext i32 %2 to i64
  %77 = mul nsw i64 %76, %4
  %78 = sext i32 %12 to i64
  %79 = mul nsw i64 %77, %78
  %80 = load ptr, ptr %8, align 8, !tbaa !5
  %81 = call i64 @fwrite(ptr noundef nonnull %22, i64 noundef %79, i64 noundef 1, ptr noundef %80)
  %82 = load ptr, ptr %8, align 8, !tbaa !5
  %83 = call i32 @fclose(ptr noundef %82)
  br label %84

84:                                               ; preds = %.loopexit, %17, %6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #6
  call void @llvm.lifetime.end.p0(i64 44, ptr nonnull %7) #6
  ret i1 false
}

; Function Attrs: nofree nounwind
declare noundef i64 @fwrite(ptr nocapture noundef, i64 noundef, i64 noundef, ptr nocapture noundef) local_unnamed_addr #4

attributes #0 = { mustprogress 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 = { "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 = { nobuiltin allocsize(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 = { 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 #5 = { mustprogress 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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.unroll.disable"}
!15 = distinct !{!15, !12}
!16 = !{!17, !17, i64 0}
!17 = !{!"short", !7, i64 0}
!18 = distinct !{!18, !12}
!19 = distinct !{!19, !12}
!20 = !{!7, !7, i64 0}
!21 = distinct !{!21, !12}
!22 = distinct !{!22, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass