; LLVM IR from dbry/wavpack-stream :: src (open_raw)

; 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.WavpackReader64 = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
%struct.WavpackRawContext = type { ptr, i32, i32, i8, i8 }
%struct.RawSegment = type { ptr, ptr, ptr, i8 }

@raw_reader = external hidden global %struct.WavpackReader64, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @WavpackStreamOpenRawDecoder(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i16 noundef signext %4, ptr noundef %5, i32 noundef %6, i32 noundef %7) #0 {
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca i32, align 4
  %13 = alloca i16, align 2
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store i32 %1, ptr %10, align 4, !tbaa !9
  store ptr %2, ptr %11, align 8, !tbaa !5
  store i32 %3, ptr %12, align 4, !tbaa !9
  store i16 %4, ptr %13, align 2, !tbaa !11
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i32 %6, ptr %15, align 4, !tbaa !9
  store i32 %7, ptr %16, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #5
  store ptr null, ptr %17, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #5
  store ptr null, ptr %18, align 8, !tbaa !5
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = icmp ne ptr %19, null
  br i1 %20, label %21, label %64

21:                                               ; preds = %8
  %22 = call noalias ptr @malloc(i64 noundef 24) #6
  store ptr %22, ptr %17, align 8, !tbaa !5
  %23 = load ptr, ptr %17, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %23, i8 0, i64 24, i1 false)
  %24 = load ptr, ptr %17, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.WavpackRawContext, ptr %24, i32 0, i32 1
  store i32 1, ptr %25, align 8, !tbaa !13
  %26 = load ptr, ptr %17, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.WavpackRawContext, ptr %26, i32 0, i32 1
  %28 = load i32, ptr %27, align 8, !tbaa !13
  %29 = sext i32 %28 to i64
  %30 = mul i64 32, %29
  %31 = call noalias ptr @malloc(i64 noundef %30) #6
  %32 = load ptr, ptr %17, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.WavpackRawContext, ptr %32, i32 0, i32 0
  store ptr %31, ptr %33, align 8, !tbaa !15
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = load ptr, ptr %17, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.WavpackRawContext, ptr %35, i32 0, i32 0
  %37 = load ptr, ptr %36, align 8, !tbaa !15
  %38 = getelementptr inbounds %struct.RawSegment, ptr %37, i64 0
  %39 = getelementptr inbounds %struct.RawSegment, ptr %38, i32 0, i32 0
  store ptr %34, ptr %39, align 8, !tbaa !16
  %40 = load ptr, ptr %17, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.WavpackRawContext, ptr %40, i32 0, i32 0
  %42 = load ptr, ptr %41, align 8, !tbaa !15
  %43 = getelementptr inbounds %struct.RawSegment, ptr %42, i64 0
  %44 = getelementptr inbounds %struct.RawSegment, ptr %43, i32 0, i32 1
  store ptr %34, ptr %44, align 8, !tbaa !18
  %45 = load ptr, ptr %17, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.WavpackRawContext, ptr %45, i32 0, i32 0
  %47 = load ptr, ptr %46, align 8, !tbaa !15
  %48 = getelementptr inbounds %struct.RawSegment, ptr %47, i64 0
  %49 = getelementptr inbounds %struct.RawSegment, ptr %48, i32 0, i32 1
  %50 = load ptr, ptr %49, align 8, !tbaa !18
  %51 = load i32, ptr %10, align 4, !tbaa !9
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds i8, ptr %50, i64 %52
  %54 = load ptr, ptr %17, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.WavpackRawContext, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !15
  %57 = getelementptr inbounds %struct.RawSegment, ptr %56, i64 0
  %58 = getelementptr inbounds %struct.RawSegment, ptr %57, i32 0, i32 2
  store ptr %53, ptr %58, align 8, !tbaa !19
  %59 = load ptr, ptr %17, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.WavpackRawContext, ptr %59, i32 0, i32 0
  %61 = load ptr, ptr %60, align 8, !tbaa !15
  %62 = getelementptr inbounds %struct.RawSegment, ptr %61, i64 0
  %63 = getelementptr inbounds %struct.RawSegment, ptr %62, i32 0, i32 3
  store i8 0, ptr %63, align 8, !tbaa !20
  br label %64

64:                                               ; preds = %21, %8
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  %66 = icmp ne ptr %65, null
  br i1 %66, label %67, label %113

67:                                               ; preds = %64
  %68 = load i32, ptr %12, align 4, !tbaa !9
  %69 = icmp ne i32 %68, 0
  br i1 %69, label %70, label %113

70:                                               ; preds = %67
  %71 = call noalias ptr @malloc(i64 noundef 24) #6
  store ptr %71, ptr %18, align 8, !tbaa !5
  %72 = load ptr, ptr %18, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %72, i8 0, i64 24, i1 false)
  %73 = load ptr, ptr %18, align 8, !tbaa !5
  %74 = getelementptr inbounds %struct.WavpackRawContext, ptr %73, i32 0, i32 1
  store i32 1, ptr %74, align 8, !tbaa !13
  %75 = load ptr, ptr %18, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.WavpackRawContext, ptr %75, i32 0, i32 1
  %77 = load i32, ptr %76, align 8, !tbaa !13
  %78 = sext i32 %77 to i64
  %79 = mul i64 32, %78
  %80 = call noalias ptr @malloc(i64 noundef %79) #6
  %81 = load ptr, ptr %18, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.WavpackRawContext, ptr %81, i32 0, i32 0
  store ptr %80, ptr %82, align 8, !tbaa !15
  %83 = load ptr, ptr %11, align 8, !tbaa !5
  %84 = load ptr, ptr %18, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.WavpackRawContext, ptr %84, i32 0, i32 0
  %86 = load ptr, ptr %85, align 8, !tbaa !15
  %87 = getelementptr inbounds %struct.RawSegment, ptr %86, i64 0
  %88 = getelementptr inbounds %struct.RawSegment, ptr %87, i32 0, i32 0
  store ptr %83, ptr %88, align 8, !tbaa !16
  %89 = load ptr, ptr %18, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.WavpackRawContext, ptr %89, i32 0, i32 0
  %91 = load ptr, ptr %90, align 8, !tbaa !15
  %92 = getelementptr inbounds %struct.RawSegment, ptr %91, i64 0
  %93 = getelementptr inbounds %struct.RawSegment, ptr %92, i32 0, i32 1
  store ptr %83, ptr %93, align 8, !tbaa !18
  %94 = load ptr, ptr %18, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.WavpackRawContext, ptr %94, i32 0, i32 0
  %96 = load ptr, ptr %95, align 8, !tbaa !15
  %97 = getelementptr inbounds %struct.RawSegment, ptr %96, i64 0
  %98 = getelementptr inbounds %struct.RawSegment, ptr %97, i32 0, i32 1
  %99 = load ptr, ptr %98, align 8, !tbaa !18
  %100 = load i32, ptr %12, align 4, !tbaa !9
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds i8, ptr %99, i64 %101
  %103 = load ptr, ptr %18, align 8, !tbaa !5
  %104 = getelementptr inbounds %struct.WavpackRawContext, ptr %103, i32 0, i32 0
  %105 = load ptr, ptr %104, align 8, !tbaa !15
  %106 = getelementptr inbounds %struct.RawSegment, ptr %105, i64 0
  %107 = getelementptr inbounds %struct.RawSegment, ptr %106, i32 0, i32 2
  store ptr %102, ptr %107, align 8, !tbaa !19
  %108 = load ptr, ptr %18, align 8, !tbaa !5
  %109 = getelementptr inbounds %struct.WavpackRawContext, ptr %108, i32 0, i32 0
  %110 = load ptr, ptr %109, align 8, !tbaa !15
  %111 = getelementptr inbounds %struct.RawSegment, ptr %110, i64 0
  %112 = getelementptr inbounds %struct.RawSegment, ptr %111, i32 0, i32 3
  store i8 0, ptr %112, align 8, !tbaa !20
  br label %113

113:                                              ; preds = %70, %67, %64
  %114 = load ptr, ptr %17, align 8, !tbaa !5
  %115 = load ptr, ptr %18, align 8, !tbaa !5
  %116 = load ptr, ptr %14, align 8, !tbaa !5
  %117 = load i32, ptr %15, align 4, !tbaa !9
  %118 = or i32 %117, 2048
  %119 = load i32, ptr %16, align 4, !tbaa !9
  %120 = call ptr @WavpackStreamOpenFileInputEx64(ptr noundef @raw_reader, ptr noundef %114, ptr noundef %115, ptr noundef %116, i32 noundef %118, i32 noundef %119)
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #5
  ret ptr %120
}

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #2

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare ptr @WavpackStreamOpenFileInputEx64(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

attributes #0 = { 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 = { nounwind 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { "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 = { nounwind 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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !10, i64 8}
!14 = !{!"", !6, i64 0, !10, i64 8, !10, i64 12, !7, i64 16, !7, i64 17}
!15 = !{!14, !6, i64 0}
!16 = !{!17, !6, i64 0}
!17 = !{!"", !6, i64 0, !6, i64 8, !6, i64 16, !7, i64 24}
!18 = !{!17, !6, i64 8}
!19 = !{!17, !6, i64 16}
!20 = !{!17, !7, 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.WavpackReader64 = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

@raw_reader = external hidden global %struct.WavpackReader64, align 8

; Function Attrs: nounwind uwtable
define dso_local ptr @WavpackStreamOpenRawDecoder(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3, i16 noundef signext %4, ptr noundef %5, i32 noundef %6, i32 noundef %7) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %17, label %9

9:                                                ; preds = %8
  %calloc34 = tail call dereferenceable_or_null(24) ptr @calloc(i64 1, i64 24)
  %10 = getelementptr inbounds i8, ptr %calloc34, i64 8
  store i32 1, ptr %10, align 8, !tbaa !5
  %11 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #4
  store ptr %11, ptr %calloc34, align 8, !tbaa !11
  store ptr %0, ptr %11, align 8, !tbaa !12
  %12 = getelementptr inbounds i8, ptr %11, i64 8
  store ptr %0, ptr %12, align 8, !tbaa !14
  %13 = sext i32 %1 to i64
  %14 = getelementptr inbounds i8, ptr %0, i64 %13
  %15 = getelementptr inbounds i8, ptr %11, i64 16
  store ptr %14, ptr %15, align 8, !tbaa !15
  %16 = getelementptr inbounds i8, ptr %11, i64 24
  store i8 0, ptr %16, align 8, !tbaa !16
  br label %17

17:                                               ; preds = %9, %8
  %.030 = phi ptr [ %calloc34, %9 ], [ null, %8 ]
  %18 = icmp ne ptr %2, null
  %19 = icmp ne i32 %3, 0
  %or.cond = and i1 %18, %19
  br i1 %or.cond, label %20, label %28

20:                                               ; preds = %17
  %calloc = tail call dereferenceable_or_null(24) ptr @calloc(i64 1, i64 24)
  %21 = getelementptr inbounds i8, ptr %calloc, i64 8
  store i32 1, ptr %21, align 8, !tbaa !5
  %22 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #4
  store ptr %22, ptr %calloc, align 8, !tbaa !11
  store ptr %2, ptr %22, align 8, !tbaa !12
  %23 = getelementptr inbounds i8, ptr %22, i64 8
  store ptr %2, ptr %23, align 8, !tbaa !14
  %24 = sext i32 %3 to i64
  %25 = getelementptr inbounds i8, ptr %2, i64 %24
  %26 = getelementptr inbounds i8, ptr %22, i64 16
  store ptr %25, ptr %26, align 8, !tbaa !15
  %27 = getelementptr inbounds i8, ptr %22, i64 24
  store i8 0, ptr %27, align 8, !tbaa !16
  br label %28

28:                                               ; preds = %20, %17
  %.0 = phi ptr [ %calloc, %20 ], [ null, %17 ]
  %29 = or i32 %6, 2048
  %30 = tail call ptr @WavpackStreamOpenFileInputEx64(ptr noundef nonnull @raw_reader, ptr noundef %.030, ptr noundef %.0, ptr noundef %5, i32 noundef %29, i32 noundef %7) #5
  ret ptr %30
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #1

declare ptr @WavpackStreamOpenFileInputEx64(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #3

attributes #0 = { 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 nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #4 = { nounwind allocsize(0) }
attributes #5 = { 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, !10, i64 8}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 12, !8, i64 16, !8, i64 17}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!13, !7, i64 0}
!13 = !{!"", !7, i64 0, !7, i64 8, !7, i64 16, !8, i64 24}
!14 = !{!13, !7, i64 8}
!15 = !{!13, !7, i64 16}
!16 = !{!13, !8, i64 24}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass,TailCallElimPass