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

; 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
@.str.16 = external hidden unnamed_addr constant [24 x i8], align 1
@_ZTISt13runtime_error = external constant ptr

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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

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

declare i32 @fclose(ptr noundef) #3

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z14WriteWaveFileSPKcjttjPs(ptr noundef %0, i32 noundef %1, i16 noundef zeroext %2, i16 noundef zeroext %3, i32 noundef %4, ptr noundef %5) #4 personality ptr @__gxx_personality_v0 {
  %7 = alloca i1, align 1
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i16, align 2
  %11 = alloca i16, align 2
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca %struct.RiffWave, align 1
  %17 = alloca i16, align 2
  %18 = alloca ptr, align 8
  %19 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store i16 %2, ptr %10, align 2, !tbaa !11
  store i16 %3, ptr %11, align 2, !tbaa !11
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  store ptr null, ptr %14, align 8, !tbaa !5
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = call noundef signext i8 @_Z7fopen_sPP8_IO_FILEPKcS3_(ptr noundef %14, ptr noundef %20, ptr noundef @.str.15)
  %22 = load ptr, ptr %14, align 8, !tbaa !5
  %23 = icmp ne ptr %22, null
  br i1 %23, label %25, label %24

24:                                               ; preds = %6
  store i1 false, ptr %7, align 1
  store i32 1, ptr %15, align 4
  br label %61

25:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 44, ptr %16) #6
  call void @llvm.memset.p0.i64(ptr align 1 %16, i8 0, i64 44, i1 false)
  %26 = load i32, ptr %9, align 4, !tbaa !9
  %27 = load i16, ptr %11, align 2, !tbaa !11
  %28 = load i16, ptr %10, align 2, !tbaa !11
  %29 = load i32, ptr %12, align 4, !tbaa !9
  call void @_Z15SetupWaveHeaderP8RiffWavejttj(ptr noundef %16, i32 noundef %26, i16 noundef zeroext %27, i16 noundef zeroext %28, i32 noundef %29)
  %30 = load ptr, ptr %14, align 8, !tbaa !5
  %31 = call i64 @fwrite(ptr noundef %16, i64 noundef 44, i64 noundef 1, ptr noundef %30)
  call void @llvm.lifetime.start.p0(i64 2, ptr %17) #6
  %32 = load i16, ptr %11, align 2, !tbaa !11
  %33 = zext i16 %32 to i32
  %34 = sdiv i32 %33, 8
  %35 = trunc i32 %34 to i16
  store i16 %35, ptr %17, align 2, !tbaa !11
  %36 = load i16, ptr %17, align 2, !tbaa !11
  %37 = zext i16 %36 to i32
  %38 = icmp eq i32 2, %37
  br i1 %38, label %39, label %51

39:                                               ; preds = %25
  %40 = load ptr, ptr %13, align 8, !tbaa !5
  %41 = load i16, ptr %10, align 2, !tbaa !11
  %42 = zext i16 %41 to i32
  %43 = load i32, ptr %12, align 4, !tbaa !9
  %44 = mul i32 %42, %43
  %45 = load i16, ptr %17, align 2, !tbaa !11
  %46 = zext i16 %45 to i32
  %47 = mul i32 %44, %46
  %48 = zext i32 %47 to i64
  %49 = load ptr, ptr %14, align 8, !tbaa !5
  %50 = call i64 @fwrite(ptr noundef %40, i64 noundef %48, i64 noundef 1, ptr noundef %49)
  br label %58

51:                                               ; preds = %25
  %52 = call ptr @__cxa_allocate_exception(i64 16) #6
  invoke void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %52, ptr noundef @.str.16)
          to label %53 unwind label %54

53:                                               ; preds = %51
  call void @__cxa_throw(ptr %52, ptr @_ZTISt13runtime_error, ptr @_ZNSt13runtime_errorD1Ev) #7
  unreachable

54:                                               ; preds = %51
  %55 = landingpad { ptr, i32 }
          cleanup
  %56 = extractvalue { ptr, i32 } %55, 0
  store ptr %56, ptr %18, align 8
  %57 = extractvalue { ptr, i32 } %55, 1
  store i32 %57, ptr %19, align 4
  call void @__cxa_free_exception(ptr %52) #6
  call void @llvm.lifetime.end.p0(i64 2, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 44, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  br label %63

58:                                               ; preds = %39
  %59 = load ptr, ptr %14, align 8, !tbaa !5
  %60 = call i32 @fclose(ptr noundef %59)
  store i1 true, ptr %7, align 1
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 2, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 44, ptr %16) #6
  br label %61

61:                                               ; preds = %58, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  %62 = load i1, ptr %7, align 1
  ret i1 %62

63:                                               ; preds = %54
  %64 = load ptr, ptr %18, align 8
  %65 = load i32, ptr %19, align 4
  %66 = insertvalue { ptr, i32 } poison, ptr %64, 0
  %67 = insertvalue { ptr, i32 } %66, i32 %65, 1
  resume { ptr, i32 } %67
}

declare ptr @__cxa_allocate_exception(i64)

declare void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #3

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr)

; Function Attrs: nounwind
declare void @_ZNSt13runtime_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #5

declare void @__cxa_throw(ptr, ptr, ptr)

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 nounwind willreturn memory(argmem: write) }
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 = { 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 "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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}


; 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
@.str.16 = external hidden unnamed_addr constant [24 x i8], align 1
@_ZTISt13runtime_error = external constant ptr

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z14WriteWaveFileSPKcjttjPs(ptr noundef %0, i32 noundef %1, i16 noundef zeroext %2, i16 noundef zeroext %3, i32 noundef %4, ptr nocapture noundef %5) local_unnamed_addr #5 personality ptr @__gxx_personality_v0 {
  %7 = alloca ptr, align 8
  %8 = alloca %struct.RiffWave, align 1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #7
  store ptr null, ptr %7, align 8, !tbaa !5
  %9 = call noundef signext i8 @_Z7fopen_sPP8_IO_FILEPKcS3_(ptr noundef nonnull %7, ptr noundef %0, ptr noundef nonnull @.str.15)
  %10 = load ptr, ptr %7, align 8, !tbaa !5
  %.not = icmp ne ptr %10, null
  br i1 %.not, label %11, label %29

11:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 44, ptr nonnull %8) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 1 dereferenceable(44) %8, i8 0, i64 44, i1 false)
  call void @_Z15SetupWaveHeaderP8RiffWavejttj(ptr noundef nonnull %8, i32 noundef %1, i16 noundef zeroext %3, i16 noundef zeroext %2, i32 noundef %4)
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = call i64 @fwrite(ptr noundef nonnull %8, i64 noundef 44, i64 noundef 1, ptr noundef %12)
  %.mask = and i16 %3, -8
  %14 = icmp eq i16 %.mask, 16
  br i1 %14, label %15, label %24

15:                                               ; preds = %11
  %16 = zext i16 %2 to i32
  %17 = shl nuw nsw i32 %16, 1
  %18 = mul i32 %17, %4
  %19 = zext i32 %18 to i64
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = call i64 @fwrite(ptr noundef %5, i64 noundef %19, i64 noundef 1, ptr noundef %20)
  %22 = load ptr, ptr %7, align 8, !tbaa !5
  %23 = call i32 @fclose(ptr noundef %22)
  call void @llvm.lifetime.end.p0(i64 44, ptr nonnull %8) #7
  br label %29

24:                                               ; preds = %11
  %25 = call ptr @__cxa_allocate_exception(i64 16) #7
  invoke void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16) %25, ptr noundef nonnull @.str.16)
          to label %26 unwind label %27

26:                                               ; preds = %24
  call void @__cxa_throw(ptr nonnull %25, ptr nonnull @_ZTISt13runtime_error, ptr nonnull @_ZNSt13runtime_errorD1Ev) #8
  unreachable

27:                                               ; preds = %24
  %28 = landingpad { ptr, i32 }
          cleanup
  call void @__cxa_free_exception(ptr %25) #7
  call void @llvm.lifetime.end.p0(i64 44, ptr nonnull %8) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #7
  resume { ptr, i32 } %28

29:                                               ; preds = %6, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #7
  ret i1 %.not
}

declare ptr @__cxa_allocate_exception(i64) local_unnamed_addr

declare void @_ZNSt13runtime_errorC1EPKc(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef) unnamed_addr #3

declare i32 @__gxx_personality_v0(...)

declare void @__cxa_free_exception(ptr) local_unnamed_addr

; Function Attrs: nounwind
declare void @_ZNSt13runtime_errorD1Ev(ptr noundef nonnull align 8 dereferenceable(16)) unnamed_addr #6

declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr

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 nounwind willreturn memory(argmem: write) }
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 = { 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 "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 #7 = { nounwind }
attributes #8 = { 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++ TBAA"}


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