; LLVM IR from zsiciarz/aquila :: aquila/source (WaveFileHandler)

; 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.Aquila::WaveHeader" = type { [4 x i8], i32, [4 x i8], [4 x i8], i32, i16, i16, i32, i32, i16, i16, [4 x i8], i32 }

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Aquila15WaveFileHandler12createHeaderERKNS_12SignalSourceERNS_10WaveHeaderE(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef nonnull align 4 dereferenceable(44) %2) #1 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %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 %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %12 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  %13 = load ptr, ptr %5, align 8, !tbaa !5
  %14 = load ptr, ptr %13, align 8, !tbaa !9
  %15 = getelementptr inbounds ptr, ptr %14, i64 2
  %16 = load ptr, ptr %15, align 8
  %17 = call noundef double %16(ptr noundef nonnull align 8 dereferenceable(40) %13)
  %18 = fptoui double %17 to i32
  store i32 %18, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 2, ptr %8) #3
  store i16 1, ptr %8, align 2, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 2, ptr %9) #3
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %19, align 8, !tbaa !9
  %21 = getelementptr inbounds ptr, ptr %20, i64 4
  %22 = load ptr, ptr %21, align 8
  %23 = call noundef zeroext i16 %22(ptr noundef nonnull align 8 dereferenceable(40) %19)
  store i16 %23, ptr %9, align 2, !tbaa !13
  %24 = load i16, ptr %9, align 2, !tbaa !13
  %25 = zext i16 %24 to i32
  %26 = icmp sgt i32 %25, 16
  br i1 %26, label %27, label %28

27:                                               ; preds = %3
  store i16 16, ptr %9, align 2, !tbaa !13
  br label %28

28:                                               ; preds = %27, %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %29 = load i32, ptr %7, align 4, !tbaa !11
  %30 = load i16, ptr %8, align 2, !tbaa !13
  %31 = zext i16 %30 to i32
  %32 = mul i32 %29, %31
  %33 = load i16, ptr %9, align 2, !tbaa !13
  %34 = zext i16 %33 to i32
  %35 = mul i32 %32, %34
  %36 = udiv i32 %35, 8
  store i32 %36, ptr %10, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = load ptr, ptr %37, align 8, !tbaa !9
  %39 = getelementptr inbounds ptr, ptr %38, i64 5
  %40 = load ptr, ptr %39, align 8
  %41 = call noundef i64 %40(ptr noundef nonnull align 8 dereferenceable(40) %37)
  %42 = load i16, ptr %8, align 2, !tbaa !13
  %43 = zext i16 %42 to i64
  %44 = mul i64 %41, %43
  %45 = load i16, ptr %9, align 2, !tbaa !13
  %46 = zext i16 %45 to i64
  %47 = mul i64 %44, %46
  %48 = udiv i64 %47, 8
  %49 = trunc i64 %48 to i32
  store i32 %49, ptr %11, align 4, !tbaa !11
  %50 = load ptr, ptr %6, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %50, i32 0, i32 0
  %52 = getelementptr inbounds [4 x i8], ptr %51, i64 0, i64 0
  %53 = call ptr @strncpy(ptr noundef %52, ptr noundef @.str, i64 noundef 4) #3
  %54 = load i32, ptr %11, align 4, !tbaa !11
  %55 = zext i32 %54 to i64
  %56 = add i64 %55, 44
  %57 = sub i64 %56, 8
  %58 = trunc i64 %57 to i32
  %59 = load ptr, ptr %6, align 8, !tbaa !5
  %60 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %59, i32 0, i32 1
  store i32 %58, ptr %60, align 4, !tbaa !15
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %61, i32 0, i32 2
  %63 = getelementptr inbounds [4 x i8], ptr %62, i64 0, i64 0
  %64 = call ptr @strncpy(ptr noundef %63, ptr noundef @.str.1, i64 noundef 4) #3
  %65 = load ptr, ptr %6, align 8, !tbaa !5
  %66 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %65, i32 0, i32 3
  %67 = getelementptr inbounds [4 x i8], ptr %66, i64 0, i64 0
  %68 = call ptr @strncpy(ptr noundef %67, ptr noundef @.str.2, i64 noundef 4) #3
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %69, i32 0, i32 4
  store i32 16, ptr %70, align 4, !tbaa !17
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %71, i32 0, i32 5
  store i16 1, ptr %72, align 4, !tbaa !18
  %73 = load i16, ptr %8, align 2, !tbaa !13
  %74 = load ptr, ptr %6, align 8, !tbaa !5
  %75 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %74, i32 0, i32 6
  store i16 %73, ptr %75, align 2, !tbaa !19
  %76 = load i32, ptr %7, align 4, !tbaa !11
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %77, i32 0, i32 7
  store i32 %76, ptr %78, align 4, !tbaa !20
  %79 = load i32, ptr %10, align 4, !tbaa !11
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %80, i32 0, i32 8
  store i32 %79, ptr %81, align 4, !tbaa !21
  %82 = load ptr, ptr %6, align 8, !tbaa !5
  %83 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %82, i32 0, i32 6
  %84 = load i16, ptr %83, align 2, !tbaa !19
  %85 = zext i16 %84 to i32
  %86 = load i16, ptr %9, align 2, !tbaa !13
  %87 = zext i16 %86 to i32
  %88 = mul nsw i32 %85, %87
  %89 = sdiv i32 %88, 8
  %90 = trunc i32 %89 to i16
  %91 = load ptr, ptr %6, align 8, !tbaa !5
  %92 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %91, i32 0, i32 9
  store i16 %90, ptr %92, align 4, !tbaa !22
  %93 = load i16, ptr %9, align 2, !tbaa !13
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %94, i32 0, i32 10
  store i16 %93, ptr %95, align 2, !tbaa !23
  %96 = load ptr, ptr %6, align 8, !tbaa !5
  %97 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %96, i32 0, i32 11
  %98 = getelementptr inbounds [4 x i8], ptr %97, i64 0, i64 0
  %99 = call ptr @strncpy(ptr noundef %98, ptr noundef @.str.3, i64 noundef 4) #3
  %100 = load i32, ptr %11, align 4, !tbaa !11
  %101 = load ptr, ptr %6, align 8, !tbaa !5
  %102 = getelementptr inbounds %"struct.Aquila::WaveHeader", ptr %101, i32 0, i32 12
  store i32 %100, ptr %102, align 4, !tbaa !24
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 2, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 = !{!"vtable pointer", !8, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"short", !7, i64 0}
!15 = !{!16, !12, i64 4}
!16 = !{!"_ZTSN6Aquila10WaveHeaderE", !7, i64 0, !12, i64 4, !7, i64 8, !7, i64 12, !12, i64 16, !14, i64 20, !14, i64 22, !12, i64 24, !12, i64 28, !14, i64 32, !14, i64 34, !7, i64 36, !12, i64 40}
!17 = !{!16, !12, i64 16}
!18 = !{!16, !14, i64 20}
!19 = !{!16, !14, i64 22}
!20 = !{!16, !12, i64 24}
!21 = !{!16, !12, i64 28}
!22 = !{!16, !14, i64 32}
!23 = !{!16, !14, i64 34}
!24 = !{!16, !12, i64 40}


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

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

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN6Aquila15WaveFileHandler12createHeaderERKNS_12SignalSourceERNS_10WaveHeaderE(ptr nocapture noundef nonnull readnone align 8 dereferenceable(32) %0, ptr noundef nonnull align 8 dereferenceable(40) %1, ptr noundef nonnull align 4 dereferenceable(44) %2) local_unnamed_addr #0 align 2 {
  %4 = load ptr, ptr %1, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 16
  %6 = load ptr, ptr %5, align 8
  %7 = tail call noundef double %6(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %8 = fptoui double %7 to i32
  %9 = load ptr, ptr %1, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %9, i64 32
  %11 = load ptr, ptr %10, align 8
  %12 = tail call noundef zeroext i16 %11(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %spec.store.select = tail call i16 @llvm.umin.i16(i16 %12, i16 16)
  %13 = zext nneg i16 %spec.store.select to i32
  %14 = mul i32 %13, %8
  %15 = lshr i32 %14, 3
  %16 = load ptr, ptr %1, align 8, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %16, i64 40
  %18 = load ptr, ptr %17, align 8
  %19 = tail call noundef i64 %18(ptr noundef nonnull align 8 dereferenceable(40) %1)
  %20 = zext nneg i16 %spec.store.select to i64
  %21 = mul i64 %19, %20
  %22 = lshr i64 %21, 3
  %23 = trunc i64 %22 to i32
  %24 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %2, ptr noundef nonnull dereferenceable(1) @.str, i64 noundef 4) #3
  %25 = add i32 %23, 36
  %26 = getelementptr inbounds i8, ptr %2, i64 4
  store i32 %25, ptr %26, align 4, !tbaa !8
  %27 = getelementptr inbounds i8, ptr %2, i64 8
  %28 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %27, ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef 4) #3
  %29 = getelementptr inbounds i8, ptr %2, i64 12
  %30 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %29, ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef 4) #3
  %31 = getelementptr inbounds i8, ptr %2, i64 16
  store i32 16, ptr %31, align 4, !tbaa !13
  %32 = getelementptr inbounds i8, ptr %2, i64 20
  store i16 1, ptr %32, align 4, !tbaa !14
  %33 = getelementptr inbounds i8, ptr %2, i64 22
  store i16 1, ptr %33, align 2, !tbaa !15
  %34 = getelementptr inbounds i8, ptr %2, i64 24
  store i32 %8, ptr %34, align 4, !tbaa !16
  %35 = getelementptr inbounds i8, ptr %2, i64 28
  store i32 %15, ptr %35, align 4, !tbaa !17
  %36 = lshr i16 %spec.store.select, 3
  %37 = getelementptr inbounds i8, ptr %2, i64 32
  store i16 %36, ptr %37, align 4, !tbaa !18
  %38 = getelementptr inbounds i8, ptr %2, i64 34
  store i16 %spec.store.select, ptr %38, align 2, !tbaa !19
  %39 = getelementptr inbounds i8, ptr %2, i64 36
  %40 = tail call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %39, ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef 4) #3
  %41 = getelementptr inbounds i8, ptr %2, i64 40
  store i32 %23, ptr %41, align 4, !tbaa !20
  ret void
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i16 @llvm.umin.i16(i16, i16) #2

attributes #0 = { 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 #1 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !11, i64 4}
!9 = !{!"_ZTSN6Aquila10WaveHeaderE", !10, i64 0, !11, i64 4, !10, i64 8, !10, i64 12, !11, i64 16, !12, i64 20, !12, i64 22, !11, i64 24, !11, i64 28, !12, i64 32, !12, i64 34, !10, i64 36, !11, i64 40}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = !{!"int", !10, i64 0}
!12 = !{!"short", !10, i64 0}
!13 = !{!9, !11, i64 16}
!14 = !{!9, !12, i64 20}
!15 = !{!9, !12, i64 22}
!16 = !{!9, !11, i64 24}
!17 = !{!9, !11, i64 28}
!18 = !{!9, !12, i64 32}
!19 = !{!9, !12, i64 34}
!20 = !{!9, !11, i64 40}


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