; LLVM IR from jingweizhanghuai/Morn :: src/wave (morn_WAV_file)

; 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.MWAVHeader = type { i16, i16, i32, i32, i16, i16 }
%struct.MWAVInfo = type { ptr, i32, i32, i32, i32, ptr }

@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.9 = 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

declare i32 @fseek(ptr noundef, i64 noundef, i32 noundef) #1

declare void @m_Free(ptr noundef) #1

declare i32 @fclose(ptr noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local void @endWAVWrite(ptr noundef %0) #2 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %struct.MWAVHeader, align 4
  %8 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  store ptr %9, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.MWAVInfo, ptr %10, i32 0, i32 0
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  store ptr %12, ptr %4, align 8, !tbaa !5
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = call i32 @fseek(ptr noundef %13, i64 noundef 0, i32 noundef 0)
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.MWAVInfo, ptr %15, i32 0, i32 3
  %17 = load i32, ptr %16, align 8, !tbaa !12
  %18 = icmp sle i32 %17, 0
  br i1 %18, label %19, label %24

19:                                               ; preds = %1
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.MWAVInfo, ptr %20, i32 0, i32 0
  %22 = load ptr, ptr %21, align 8, !tbaa !9
  %23 = call i32 @fclose(ptr noundef %22)
  store i32 1, ptr %5, align 4
  br label %90

24:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.MWAVInfo, ptr %25, i32 0, i32 3
  %27 = load i32, ptr %26, align 8, !tbaa !12
  %28 = mul nsw i32 %27, 2
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.MWAVInfo, ptr %29, i32 0, i32 2
  %31 = load i32, ptr %30, align 4, !tbaa !13
  %32 = mul nsw i32 %28, %31
  store i32 %32, ptr %6, align 4, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #3
  %33 = getelementptr inbounds %struct.MWAVHeader, ptr %7, i32 0, i32 0
  store i16 1, ptr %33, align 4, !tbaa !15
  %34 = load ptr, ptr %3, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.MWAVInfo, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 4, !tbaa !13
  %37 = trunc i32 %36 to i16
  %38 = getelementptr inbounds %struct.MWAVHeader, ptr %7, i32 0, i32 1
  store i16 %37, ptr %38, align 2, !tbaa !18
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.MWAVInfo, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 8, !tbaa !19
  %42 = getelementptr inbounds %struct.MWAVHeader, ptr %7, i32 0, i32 2
  store i32 %41, ptr %42, align 4, !tbaa !20
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.MWAVInfo, ptr %43, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !19
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.MWAVInfo, ptr %46, i32 0, i32 2
  %48 = load i32, ptr %47, align 4, !tbaa !13
  %49 = shl i32 %48, 1
  %50 = mul nsw i32 %45, %49
  %51 = getelementptr inbounds %struct.MWAVHeader, ptr %7, i32 0, i32 3
  store i32 %50, ptr %51, align 4, !tbaa !21
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.MWAVInfo, ptr %52, i32 0, i32 2
  %54 = load i32, ptr %53, align 4, !tbaa !13
  %55 = shl i32 %54, 1
  %56 = trunc i32 %55 to i16
  %57 = getelementptr inbounds %struct.MWAVHeader, ptr %7, i32 0, i32 4
  store i16 %56, ptr %57, align 4, !tbaa !22
  %58 = getelementptr inbounds %struct.MWAVHeader, ptr %7, i32 0, i32 5
  store i16 16, ptr %58, align 2, !tbaa !23
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = call i64 @fwrite(ptr noundef @.str.2, i64 noundef 1, i64 noundef 4, ptr noundef %59)
  %61 = load i32, ptr %6, align 4, !tbaa !14
  %62 = add nsw i32 %61, 36
  store i32 %62, ptr %8, align 4, !tbaa !14
  %63 = load ptr, ptr %4, align 8, !tbaa !5
  %64 = call i64 @fwrite(ptr noundef %8, i64 noundef 4, i64 noundef 1, ptr noundef %63)
  %65 = load ptr, ptr %4, align 8, !tbaa !5
  %66 = call i64 @fwrite(ptr noundef @.str.4, i64 noundef 1, i64 noundef 4, ptr noundef %65)
  %67 = load ptr, ptr %4, align 8, !tbaa !5
  %68 = call i64 @fwrite(ptr noundef @.str.7, i64 noundef 1, i64 noundef 4, ptr noundef %67)
  store i32 16, ptr %8, align 4, !tbaa !14
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = call i64 @fwrite(ptr noundef %8, i64 noundef 4, i64 noundef 1, ptr noundef %69)
  %71 = load ptr, ptr %4, align 8, !tbaa !5
  %72 = call i64 @fwrite(ptr noundef %7, i64 noundef 16, i64 noundef 1, ptr noundef %71)
  %73 = load ptr, ptr %4, align 8, !tbaa !5
  %74 = call i64 @fwrite(ptr noundef @.str.9, i64 noundef 1, i64 noundef 4, ptr noundef %73)
  %75 = load ptr, ptr %4, align 8, !tbaa !5
  %76 = call i64 @fwrite(ptr noundef %6, i64 noundef 4, i64 noundef 1, ptr noundef %75)
  %77 = load ptr, ptr %3, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.MWAVInfo, ptr %77, i32 0, i32 0
  %79 = load ptr, ptr %78, align 8, !tbaa !9
  %80 = call i32 @fclose(ptr noundef %79)
  %81 = load ptr, ptr %3, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.MWAVInfo, ptr %81, i32 0, i32 5
  %83 = load ptr, ptr %82, align 8, !tbaa !24
  %84 = icmp ne ptr %83, null
  br i1 %84, label %85, label %89

85:                                               ; preds = %24
  %86 = load ptr, ptr %3, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.MWAVInfo, ptr %86, i32 0, i32 5
  %88 = load ptr, ptr %87, align 8, !tbaa !24
  call void @m_Free(ptr noundef %88)
  br label %89

89:                                               ; preds = %85, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  store i32 0, ptr %5, align 4
  br label %90

90:                                               ; preds = %89, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  %91 = load i32, ptr %5, align 4
  switch i32 %91, label %93 [
    i32 0, label %92
    i32 1, label %92
  ]

92:                                               ; preds = %90, %90
  ret void

93:                                               ; preds = %90
  unreachable
}

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


; 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.MWAVHeader = type { i16, i16, i32, i32, i16, i16 }

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

; Function Attrs: nofree nounwind
declare noundef i32 @fseek(ptr nocapture noundef, i64 noundef, i32 noundef) local_unnamed_addr #1

declare void @m_Free(ptr noundef) local_unnamed_addr #2

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

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

; Function Attrs: nounwind uwtable
define dso_local void @endWAVWrite(ptr nocapture noundef readonly %0) local_unnamed_addr #3 {
  %2 = alloca i32, align 4
  %3 = alloca %struct.MWAVHeader, align 4
  %4 = alloca i32, align 4
  %5 = load ptr, ptr %0, align 8, !tbaa !5
  %6 = tail call i32 @fseek(ptr noundef %5, i64 noundef 0, i32 noundef 0)
  %7 = getelementptr inbounds i8, ptr %0, i64 16
  %8 = load i32, ptr %7, align 8, !tbaa !11
  %9 = icmp slt i32 %8, 1
  br i1 %9, label %10, label %13

10:                                               ; preds = %1
  %11 = load ptr, ptr %0, align 8, !tbaa !5
  %12 = tail call i32 @fclose(ptr noundef %11)
  br label %44

13:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  %14 = shl nuw nsw i32 %8, 1
  %15 = getelementptr inbounds i8, ptr %0, i64 12
  %16 = load i32, ptr %15, align 4, !tbaa !12
  %17 = mul nsw i32 %16, %14
  store i32 %17, ptr %2, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  store i16 1, ptr %3, align 4, !tbaa !14
  %18 = trunc i32 %16 to i16
  %19 = getelementptr inbounds i8, ptr %3, i64 2
  store i16 %18, ptr %19, align 2, !tbaa !17
  %20 = getelementptr inbounds i8, ptr %0, i64 8
  %21 = load i32, ptr %20, align 8, !tbaa !18
  %22 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %21, ptr %22, align 4, !tbaa !19
  %23 = shl i32 %16, 1
  %24 = mul nsw i32 %23, %21
  %25 = getelementptr inbounds i8, ptr %3, i64 8
  store i32 %24, ptr %25, align 4, !tbaa !20
  %26 = shl i16 %18, 1
  %27 = getelementptr inbounds i8, ptr %3, i64 12
  store i16 %26, ptr %27, align 4, !tbaa !21
  %28 = getelementptr inbounds i8, ptr %3, i64 14
  store i16 16, ptr %28, align 2, !tbaa !22
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  %29 = tail call i64 @fwrite(ptr noundef nonnull @.str.2, i64 noundef 1, i64 noundef 4, ptr noundef %5)
  %30 = add nsw i32 %17, 36
  store i32 %30, ptr %4, align 4, !tbaa !13
  %31 = call i64 @fwrite(ptr noundef nonnull %4, i64 noundef 4, i64 noundef 1, ptr noundef %5)
  %32 = tail call i64 @fwrite(ptr noundef nonnull @.str.4, i64 noundef 1, i64 noundef 4, ptr noundef %5)
  %33 = tail call i64 @fwrite(ptr noundef nonnull @.str.7, i64 noundef 1, i64 noundef 4, ptr noundef %5)
  store i32 16, ptr %4, align 4, !tbaa !13
  %34 = call i64 @fwrite(ptr noundef nonnull %4, i64 noundef 4, i64 noundef 1, ptr noundef %5)
  %35 = call i64 @fwrite(ptr noundef nonnull %3, i64 noundef 16, i64 noundef 1, ptr noundef %5)
  %36 = tail call i64 @fwrite(ptr noundef nonnull @.str.9, i64 noundef 1, i64 noundef 4, ptr noundef %5)
  %37 = call i64 @fwrite(ptr noundef nonnull %2, i64 noundef 4, i64 noundef 1, ptr noundef %5)
  %38 = load ptr, ptr %0, align 8, !tbaa !5
  %39 = tail call i32 @fclose(ptr noundef %38)
  %40 = getelementptr inbounds i8, ptr %0, i64 24
  %41 = load ptr, ptr %40, align 8, !tbaa !23
  %.not = icmp eq ptr %41, null
  br i1 %.not, label %43, label %42

42:                                               ; preds = %13
  tail call void @m_Free(ptr noundef nonnull %41) #4
  br label %43

43:                                               ; preds = %42, %13
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  br label %44

44:                                               ; preds = %43, %10
  ret void
}

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


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