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

; 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 }

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z15SetupWaveHeaderP8RiffWavejttj(ptr noundef %0, i32 noundef %1, i16 noundef zeroext %2, i16 noundef zeroext %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i16, align 2
  %9 = alloca i16, align 2
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i32 %1, ptr %7, align 4, !tbaa !9
  store i16 %2, ptr %8, align 2, !tbaa !11
  store i16 %3, ptr %9, align 2, !tbaa !11
  store i32 %4, ptr %10, align 4, !tbaa !9
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 1 %12, i8 0, i64 44, i1 false)
  %13 = load ptr, ptr %6, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.RiffWave, ptr %13, i32 0, i32 0
  %15 = getelementptr inbounds %struct.RiffHeader, ptr %14, i32 0, i32 0
  %16 = getelementptr inbounds [4 x i8], ptr %15, i64 0, i64 0
  store i8 82, ptr %16, align 1, !tbaa !13
  %17 = load ptr, ptr %6, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.RiffWave, ptr %17, i32 0, i32 0
  %19 = getelementptr inbounds %struct.RiffHeader, ptr %18, i32 0, i32 0
  %20 = getelementptr inbounds [4 x i8], ptr %19, i64 0, i64 1
  store i8 73, ptr %20, align 1, !tbaa !13
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.RiffWave, ptr %21, i32 0, i32 0
  %23 = getelementptr inbounds %struct.RiffHeader, ptr %22, i32 0, i32 0
  %24 = getelementptr inbounds [4 x i8], ptr %23, i64 0, i64 2
  store i8 70, ptr %24, align 1, !tbaa !13
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.RiffWave, ptr %25, i32 0, i32 0
  %27 = getelementptr inbounds %struct.RiffHeader, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds [4 x i8], ptr %27, i64 0, i64 3
  store i8 70, ptr %28, align 1, !tbaa !13
  %29 = load ptr, ptr %6, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.RiffWave, ptr %29, i32 0, i32 1
  %31 = getelementptr inbounds %struct.WaveHeader, ptr %30, i32 0, i32 0
  %32 = getelementptr inbounds [4 x i8], ptr %31, i64 0, i64 0
  store i8 87, ptr %32, align 1, !tbaa !13
  %33 = load ptr, ptr %6, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.RiffWave, ptr %33, i32 0, i32 1
  %35 = getelementptr inbounds %struct.WaveHeader, ptr %34, i32 0, i32 0
  %36 = getelementptr inbounds [4 x i8], ptr %35, i64 0, i64 1
  store i8 65, ptr %36, align 1, !tbaa !13
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.RiffWave, ptr %37, i32 0, i32 1
  %39 = getelementptr inbounds %struct.WaveHeader, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds [4 x i8], ptr %39, i64 0, i64 2
  store i8 86, ptr %40, align 1, !tbaa !13
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.RiffWave, ptr %41, i32 0, i32 1
  %43 = getelementptr inbounds %struct.WaveHeader, ptr %42, i32 0, i32 0
  %44 = getelementptr inbounds [4 x i8], ptr %43, i64 0, i64 3
  store i8 69, ptr %44, align 1, !tbaa !13
  %45 = load ptr, ptr %6, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.RiffWave, ptr %45, i32 0, i32 1
  %47 = getelementptr inbounds %struct.WaveHeader, ptr %46, i32 0, i32 2
  %48 = getelementptr inbounds %struct.DataHeader, ptr %47, i32 0, i32 0
  %49 = getelementptr inbounds [4 x i8], ptr %48, i64 0, i64 0
  store i8 100, ptr %49, align 1, !tbaa !13
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.RiffWave, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds %struct.WaveHeader, ptr %51, i32 0, i32 2
  %53 = getelementptr inbounds %struct.DataHeader, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds [4 x i8], ptr %53, i64 0, i64 1
  store i8 97, ptr %54, align 1, !tbaa !13
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.RiffWave, ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds %struct.WaveHeader, ptr %56, i32 0, i32 2
  %58 = getelementptr inbounds %struct.DataHeader, ptr %57, i32 0, i32 0
  %59 = getelementptr inbounds [4 x i8], ptr %58, i64 0, i64 2
  store i8 116, ptr %59, align 1, !tbaa !13
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.RiffWave, ptr %60, i32 0, i32 1
  %62 = getelementptr inbounds %struct.WaveHeader, ptr %61, i32 0, i32 2
  %63 = getelementptr inbounds %struct.DataHeader, ptr %62, i32 0, i32 0
  %64 = getelementptr inbounds [4 x i8], ptr %63, i64 0, i64 3
  store i8 97, ptr %64, align 1, !tbaa !13
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.RiffWave, ptr %65, i32 0, i32 1
  %67 = getelementptr inbounds %struct.WaveHeader, ptr %66, i32 0, i32 1
  %68 = getelementptr inbounds %struct.WaveFormat, ptr %67, i32 0, i32 0
  %69 = getelementptr inbounds [4 x i8], ptr %68, i64 0, i64 0
  store i8 102, ptr %69, align 1, !tbaa !13
  %70 = load ptr, ptr %6, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.RiffWave, ptr %70, i32 0, i32 1
  %72 = getelementptr inbounds %struct.WaveHeader, ptr %71, i32 0, i32 1
  %73 = getelementptr inbounds %struct.WaveFormat, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds [4 x i8], ptr %73, i64 0, i64 1
  store i8 109, ptr %74, align 1, !tbaa !13
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.RiffWave, ptr %75, i32 0, i32 1
  %77 = getelementptr inbounds %struct.WaveHeader, ptr %76, i32 0, i32 1
  %78 = getelementptr inbounds %struct.WaveFormat, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds [4 x i8], ptr %78, i64 0, i64 2
  store i8 116, ptr %79, align 1, !tbaa !13
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.RiffWave, ptr %80, i32 0, i32 1
  %82 = getelementptr inbounds %struct.WaveHeader, ptr %81, i32 0, i32 1
  %83 = getelementptr inbounds %struct.WaveFormat, ptr %82, i32 0, i32 0
  %84 = getelementptr inbounds [4 x i8], ptr %83, i64 0, i64 3
  store i8 32, ptr %84, align 1, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %85 = load i32, ptr %10, align 4, !tbaa !9
  %86 = load i16, ptr %9, align 2, !tbaa !11
  %87 = zext i16 %86 to i32
  %88 = mul i32 %85, %87
  %89 = load i16, ptr %8, align 2, !tbaa !11
  %90 = zext i16 %89 to i32
  %91 = sdiv i32 %90, 8
  %92 = mul i32 %88, %91
  store i32 %92, ptr %11, align 4, !tbaa !9
  %93 = load i32, ptr %11, align 4, !tbaa !9
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.RiffWave, ptr %94, i32 0, i32 1
  %96 = getelementptr inbounds %struct.WaveHeader, ptr %95, i32 0, i32 2
  %97 = getelementptr inbounds %struct.DataHeader, ptr %96, i32 0, i32 1
  store i32 %93, ptr %97, align 1, !tbaa !14
  %98 = load i32, ptr %11, align 4, !tbaa !9
  %99 = zext i32 %98 to i64
  %100 = add i64 %99, 36
  %101 = trunc i64 %100 to i32
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.RiffWave, ptr %102, i32 0, i32 0
  %104 = getelementptr inbounds %struct.RiffHeader, ptr %103, i32 0, i32 1
  store i32 %101, ptr %104, align 1, !tbaa !21
  %105 = load ptr, ptr %6, align 8, !tbaa !5
  %106 = getelementptr inbounds %struct.RiffWave, ptr %105, i32 0, i32 1
  %107 = getelementptr inbounds %struct.WaveHeader, ptr %106, i32 0, i32 1
  %108 = getelementptr inbounds %struct.WaveFormat, ptr %107, i32 0, i32 1
  store i32 16, ptr %108, align 1, !tbaa !22
  %109 = load i16, ptr %8, align 2, !tbaa !11
  %110 = zext i16 %109 to i32
  %111 = icmp eq i32 %110, 32
  %112 = zext i1 %111 to i64
  %113 = select i1 %111, i32 3, i32 1
  %114 = trunc i32 %113 to i16
  %115 = load ptr, ptr %6, align 8, !tbaa !5
  %116 = getelementptr inbounds %struct.RiffWave, ptr %115, i32 0, i32 1
  %117 = getelementptr inbounds %struct.WaveHeader, ptr %116, i32 0, i32 1
  %118 = getelementptr inbounds %struct.WaveFormat, ptr %117, i32 0, i32 2
  %119 = getelementptr inbounds %struct.WaveInfo, ptr %118, i32 0, i32 0
  store i16 %114, ptr %119, align 1, !tbaa !23
  %120 = load i16, ptr %9, align 2, !tbaa !11
  %121 = load ptr, ptr %6, align 8, !tbaa !5
  %122 = getelementptr inbounds %struct.RiffWave, ptr %121, i32 0, i32 1
  %123 = getelementptr inbounds %struct.WaveHeader, ptr %122, i32 0, i32 1
  %124 = getelementptr inbounds %struct.WaveFormat, ptr %123, i32 0, i32 2
  %125 = getelementptr inbounds %struct.WaveInfo, ptr %124, i32 0, i32 1
  store i16 %120, ptr %125, align 1, !tbaa !24
  %126 = load i32, ptr %7, align 4, !tbaa !9
  %127 = load ptr, ptr %6, align 8, !tbaa !5
  %128 = getelementptr inbounds %struct.RiffWave, ptr %127, i32 0, i32 1
  %129 = getelementptr inbounds %struct.WaveHeader, ptr %128, i32 0, i32 1
  %130 = getelementptr inbounds %struct.WaveFormat, ptr %129, i32 0, i32 2
  %131 = getelementptr inbounds %struct.WaveInfo, ptr %130, i32 0, i32 2
  store i32 %126, ptr %131, align 1, !tbaa !25
  %132 = load i16, ptr %9, align 2, !tbaa !11
  %133 = zext i16 %132 to i32
  %134 = load i32, ptr %7, align 4, !tbaa !9
  %135 = mul i32 %133, %134
  %136 = load i16, ptr %8, align 2, !tbaa !11
  %137 = zext i16 %136 to i32
  %138 = sdiv i32 %137, 8
  %139 = mul i32 %135, %138
  %140 = load ptr, ptr %6, align 8, !tbaa !5
  %141 = getelementptr inbounds %struct.RiffWave, ptr %140, i32 0, i32 1
  %142 = getelementptr inbounds %struct.WaveHeader, ptr %141, i32 0, i32 1
  %143 = getelementptr inbounds %struct.WaveFormat, ptr %142, i32 0, i32 2
  %144 = getelementptr inbounds %struct.WaveInfo, ptr %143, i32 0, i32 3
  store i32 %139, ptr %144, align 1, !tbaa !26
  %145 = load i16, ptr %9, align 2, !tbaa !11
  %146 = zext i16 %145 to i32
  %147 = load i16, ptr %8, align 2, !tbaa !11
  %148 = zext i16 %147 to i32
  %149 = sdiv i32 %148, 8
  %150 = mul nsw i32 %146, %149
  %151 = trunc i32 %150 to i16
  %152 = load ptr, ptr %6, align 8, !tbaa !5
  %153 = getelementptr inbounds %struct.RiffWave, ptr %152, i32 0, i32 1
  %154 = getelementptr inbounds %struct.WaveHeader, ptr %153, i32 0, i32 1
  %155 = getelementptr inbounds %struct.WaveFormat, ptr %154, i32 0, i32 2
  %156 = getelementptr inbounds %struct.WaveInfo, ptr %155, i32 0, i32 4
  store i16 %151, ptr %156, align 1, !tbaa !27
  %157 = load i16, ptr %8, align 2, !tbaa !11
  %158 = load ptr, ptr %6, align 8, !tbaa !5
  %159 = getelementptr inbounds %struct.RiffWave, ptr %158, i32 0, i32 1
  %160 = getelementptr inbounds %struct.WaveHeader, ptr %159, i32 0, i32 1
  %161 = getelementptr inbounds %struct.WaveFormat, ptr %160, i32 0, i32 2
  %162 = getelementptr inbounds %struct.WaveInfo, ptr %161, i32 0, i32 5
  store i16 %157, ptr %162, align 1, !tbaa !28
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  ret void
}

; 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

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 = { 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !10, i64 40}
!15 = !{!"_ZTS8RiffWave", !16, i64 0, !17, i64 8}
!16 = !{!"_ZTS10RiffHeader", !7, i64 0, !10, i64 4}
!17 = !{!"_ZTS10WaveHeader", !7, i64 0, !18, i64 4, !20, i64 28}
!18 = !{!"_ZTS10WaveFormat", !7, i64 0, !10, i64 4, !19, i64 8}
!19 = !{!"_ZTS8WaveInfo", !12, i64 0, !12, i64 2, !10, i64 4, !10, i64 8, !12, i64 12, !12, i64 14}
!20 = !{!"_ZTS10DataHeader", !7, i64 0, !10, i64 4}
!21 = !{!15, !10, i64 4}
!22 = !{!15, !10, i64 16}
!23 = !{!15, !12, i64 20}
!24 = !{!15, !12, i64 22}
!25 = !{!15, !10, i64 24}
!26 = !{!15, !10, i64 28}
!27 = !{!15, !12, i64 32}
!28 = !{!15, !12, i64 34}


; 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"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) uwtable
define dso_local void @_Z15SetupWaveHeaderP8RiffWavejttj(ptr nocapture noundef writeonly %0, i32 noundef %1, i16 noundef zeroext %2, i16 noundef zeroext %3, i32 noundef %4) local_unnamed_addr #0 {
  store <4 x i8> <i8 82, i8 73, i8 70, i8 70>, ptr %0, align 1, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 8
  %7 = getelementptr inbounds i8, ptr %0, i64 36
  store <4 x i8> <i8 100, i8 97, i8 116, i8 97>, ptr %7, align 1, !tbaa !5
  store <8 x i8> <i8 87, i8 65, i8 86, i8 69, i8 102, i8 109, i8 116, i8 32>, ptr %6, align 1, !tbaa !5
  %8 = zext i16 %3 to i32
  %9 = lshr i16 %2, 3
  %10 = zext nneg i16 %9 to i32
  %11 = mul nuw nsw i32 %10, %8
  %12 = mul i32 %11, %4
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 %12, ptr %13, align 1, !tbaa !8
  %14 = add i32 %12, 36
  %15 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %14, ptr %15, align 1, !tbaa !17
  %16 = getelementptr inbounds i8, ptr %0, i64 16
  store i32 16, ptr %16, align 1, !tbaa !18
  %17 = icmp eq i16 %2, 32
  %18 = select i1 %17, i16 3, i16 1
  %19 = getelementptr inbounds i8, ptr %0, i64 20
  store i16 %18, ptr %19, align 1, !tbaa !19
  %20 = getelementptr inbounds i8, ptr %0, i64 22
  store i16 %3, ptr %20, align 1, !tbaa !20
  %21 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %1, ptr %21, align 1, !tbaa !21
  %22 = mul i32 %11, %1
  %23 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 %22, ptr %23, align 1, !tbaa !22
  %24 = mul i16 %9, %3
  %25 = getelementptr inbounds i8, ptr %0, i64 32
  store i16 %24, ptr %25, align 1, !tbaa !23
  %26 = getelementptr inbounds i8, ptr %0, i64 34
  store i16 %2, ptr %26, align 1, !tbaa !24
  ret void
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: write) 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" }

!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++ TBAA"}
!8 = !{!9, !11, i64 40}
!9 = !{!"_ZTS8RiffWave", !10, i64 0, !12, i64 8}
!10 = !{!"_ZTS10RiffHeader", !6, i64 0, !11, i64 4}
!11 = !{!"int", !6, i64 0}
!12 = !{!"_ZTS10WaveHeader", !6, i64 0, !13, i64 4, !16, i64 28}
!13 = !{!"_ZTS10WaveFormat", !6, i64 0, !11, i64 4, !14, i64 8}
!14 = !{!"_ZTS8WaveInfo", !15, i64 0, !15, i64 2, !11, i64 4, !11, i64 8, !15, i64 12, !15, i64 14}
!15 = !{!"short", !6, i64 0}
!16 = !{!"_ZTS10DataHeader", !6, i64 0, !11, i64 4}
!17 = !{!9, !11, i64 4}
!18 = !{!9, !11, i64 16}
!19 = !{!9, !15, i64 20}
!20 = !{!9, !15, i64 22}
!21 = !{!9, !11, i64 24}
!22 = !{!9, !11, i64 28}
!23 = !{!9, !15, i64 32}
!24 = !{!9, !15, i64 34}


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