; LLVM IR from introlab/odas :: src/signal (demixing)

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

; Function Attrs: nounwind uwtable
define dso_local ptr @demixings_construct_zero(i32 noundef %0, i32 noundef %1, i32 noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !5
  store i32 %2, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %9 = call noalias ptr @malloc(i64 noundef 24) #5
  store ptr %9, ptr %7, align 8, !tbaa !9
  %10 = load i32, ptr %5, align 4, !tbaa !5
  %11 = load ptr, ptr %7, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.demixings_obj, ptr %11, i32 0, i32 0
  store i32 %10, ptr %12, align 8, !tbaa !11
  %13 = load i32, ptr %6, align 4, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.demixings_obj, ptr %14, i32 0, i32 1
  store i32 %13, ptr %15, align 4, !tbaa !13
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.demixings_obj, ptr %17, i32 0, i32 2
  store i32 %16, ptr %18, align 8, !tbaa !14
  %19 = load ptr, ptr %7, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.demixings_obj, ptr %19, i32 0, i32 0
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = zext i32 %21 to i64
  %23 = mul i64 8, %22
  %24 = call noalias ptr @malloc(i64 noundef %23) #5
  %25 = load ptr, ptr %7, align 8, !tbaa !9
  %26 = getelementptr inbounds %struct.demixings_obj, ptr %25, i32 0, i32 3
  store ptr %24, ptr %26, align 8, !tbaa !15
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %70, %3
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = load ptr, ptr %7, align 8, !tbaa !9
  %30 = getelementptr inbounds %struct.demixings_obj, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = icmp ult i32 %28, %31
  br i1 %32, label %33, label %73

33:                                               ; preds = %27
  %34 = load ptr, ptr %7, align 8, !tbaa !9
  %35 = getelementptr inbounds %struct.demixings_obj, ptr %34, i32 0, i32 2
  %36 = load i32, ptr %35, align 8, !tbaa !14
  %37 = zext i32 %36 to i64
  %38 = mul i64 4, %37
  %39 = load ptr, ptr %7, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.demixings_obj, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 4, !tbaa !13
  %42 = zext i32 %41 to i64
  %43 = mul i64 %38, %42
  %44 = mul i64 %43, 2
  %45 = call noalias ptr @malloc(i64 noundef %44) #5
  %46 = load ptr, ptr %7, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.demixings_obj, ptr %46, i32 0, i32 3
  %48 = load ptr, ptr %47, align 8, !tbaa !15
  %49 = load i32, ptr %8, align 4, !tbaa !5
  %50 = zext i32 %49 to i64
  %51 = getelementptr inbounds ptr, ptr %48, i64 %50
  store ptr %45, ptr %51, align 8, !tbaa !9
  %52 = load ptr, ptr %7, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.demixings_obj, ptr %52, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !15
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = zext i32 %55 to i64
  %57 = getelementptr inbounds ptr, ptr %54, i64 %56
  %58 = load ptr, ptr %57, align 8, !tbaa !9
  %59 = load ptr, ptr %7, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.demixings_obj, ptr %59, i32 0, i32 2
  %61 = load i32, ptr %60, align 8, !tbaa !14
  %62 = zext i32 %61 to i64
  %63 = mul i64 4, %62
  %64 = load ptr, ptr %7, align 8, !tbaa !9
  %65 = getelementptr inbounds %struct.demixings_obj, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 4, !tbaa !13
  %67 = zext i32 %66 to i64
  %68 = mul i64 %63, %67
  %69 = mul i64 %68, 2
  call void @llvm.memset.p0.i64(ptr align 4 %58, i8 0, i64 %69, i1 false)
  br label %70

70:                                               ; preds = %33
  %71 = load i32, ptr %8, align 4, !tbaa !5
  %72 = add i32 %71, 1
  store i32 %72, ptr %8, align 4, !tbaa !5
  br label %27, !llvm.loop !16

73:                                               ; preds = %27
  %74 = load ptr, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  ret ptr %74
}

; 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

; 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 = { nounwind }
attributes #5 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"demixings_obj", !6, i64 0, !6, i64 4, !6, i64 8, !10, i64 16}
!13 = !{!12, !6, i64 4}
!14 = !{!12, !6, i64 8}
!15 = !{!12, !10, i64 16}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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: nofree nounwind memory(write, argmem: none, inaccessiblemem: readwrite) uwtable
define dso_local noalias noundef ptr @demixings_construct_zero(i32 noundef %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = tail call noalias dereferenceable_or_null(24) ptr @malloc(i64 noundef 24) #3
  store i32 %1, ptr %4, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 %2, ptr %5, align 4, !tbaa !11
  %6 = getelementptr inbounds i8, ptr %4, i64 8
  store i32 %0, ptr %6, align 8, !tbaa !12
  %7 = zext i32 %1 to i64
  %8 = shl nuw nsw i64 %7, 3
  %9 = tail call noalias ptr @malloc(i64 noundef %8) #3
  %10 = getelementptr inbounds i8, ptr %4, i64 16
  store ptr %9, ptr %10, align 8, !tbaa !13
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %11 = zext i32 %0 to i64
  %12 = zext i32 %2 to i64
  %13 = shl nuw nsw i64 %11, 3
  %14 = mul i64 %13, %12
  br label %15

15:                                               ; preds = %.lr.ph, %15
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %15 ]
  %calloc = tail call ptr @calloc(i64 1, i64 %14)
  %16 = getelementptr inbounds ptr, ptr %9, i64 %indvars.iv
  store ptr %calloc, ptr %16, align 8, !tbaa !14
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %7
  br i1 %exitcond.not, label %._crit_edge, label %15, !llvm.loop !15

._crit_edge:                                      ; preds = %15, %3
  ret ptr %4
}

; 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

; 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 #2

attributes #0 = { nofree nounwind memory(write, argmem: none, inaccessiblemem: readwrite) 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 = { nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #3 = { 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, !7, i64 0}
!6 = !{!"demixings_obj", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !7, i64 4}
!12 = !{!6, !7, i64 8}
!13 = !{!6, !10, i64 16}
!14 = !{!10, !10, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass