; LLVM IR from cvxgrp/scs :: src/cones.ll (scs_init_cone)

; 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.SCS_CONE_WORK = type { ptr, ptr, i32, i32, ptr, i32, double }
%struct.ScsCone = type { i32, i32, ptr, ptr, i32, ptr, i32, ptr, i32, i32, i32, ptr, i32 }

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #0

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

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

; Function Attrs: nounwind uwtable
declare dso_local void @set_cone_boundaries(ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare dso_local void @_scs_finish_cone(ptr noundef) #2

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

28:                                               ; preds = %2
  %29 = load ptr, ptr %4, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.ScsCone, ptr %29, i32 0, i32 7
  %31 = load ptr, ptr %30, align 8, !tbaa !19
  %32 = icmp ne ptr %31, null
  br i1 %32, label %33, label %41

33:                                               ; preds = %28
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = load ptr, ptr %4, align 8, !tbaa !5
  %36 = call i32 @set_up_sd_cone_work_space(ptr noundef %34, ptr noundef %35)
  %37 = icmp slt i32 %36, 0
  br i1 %37, label %38, label %40

38:                                               ; preds = %33
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_scs_finish_cone(ptr noundef %39)
  store ptr null, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %43

40:                                               ; preds = %33
  br label %41

41:                                               ; preds = %40, %28, %2
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %42, ptr %3, align 8
  store i32 1, ptr %7, align 4
  br label %43

43:                                               ; preds = %41, %38
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %44 = load ptr, ptr %3, align 8
  ret ptr %44
}

; Function Attrs: nounwind uwtable
declare hidden i32 @set_up_sd_cone_work_space(ptr noundef, ptr noundef) #2

attributes #0 = { nounwind allocsize(0,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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }
attributes #4 = { nounwind allocsize(0,1) }

!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, !6, i64 0}
!12 = !{!"SCS_CONE_WORK", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !6, i64 24, !10, i64 32, !13, i64 40}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !10, i64 32}
!15 = !{!12, !10, i64 20}
!16 = !{!12, !6, i64 24}
!17 = !{!18, !10, i64 56}
!18 = !{!"", !10, i64 0, !10, i64 4, !6, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !10, i64 40, !6, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !6, i64 72, !10, i64 80}
!19 = !{!18, !6, i64 48}


; 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 nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @set_cone_boundaries(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @_scs_finish_cone(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @_scs_init_cone(ptr noundef %0, i32 noundef %1) local_unnamed_addr #1 {
  %3 = tail call noalias dereferenceable_or_null(48) ptr @calloc(i64 noundef 1, i64 noundef 48) #2
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 32
  store i32 %1, ptr %4, align 8, !tbaa !12
  tail call void @set_cone_boundaries(ptr noundef %0, ptr noundef nonnull %3)
  %5 = sext i32 %1 to i64
  %6 = tail call noalias ptr @calloc(i64 noundef %5, i64 noundef 8) #2
  %7 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr %6, ptr %7, align 8, !tbaa !13
  %8 = getelementptr inbounds i8, ptr %0, i64 56
  %9 = load i32, ptr %8, align 8, !tbaa !14
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %17, label %10

10:                                               ; preds = %2
  %11 = getelementptr inbounds i8, ptr %0, i64 48
  %12 = load ptr, ptr %11, align 8, !tbaa !16
  %.not15 = icmp eq ptr %12, null
  br i1 %.not15, label %17, label %13

13:                                               ; preds = %10
  %14 = tail call i32 @set_up_sd_cone_work_space(ptr noundef nonnull %3, ptr noundef nonnull %0)
  %15 = icmp slt i32 %14, 0
  br i1 %15, label %16, label %17

16:                                               ; preds = %13
  tail call void @_scs_finish_cone(ptr noundef nonnull %3)
  br label %17

17:                                               ; preds = %2, %10, %13, %16
  %.0 = phi ptr [ null, %16 ], [ %3, %13 ], [ %3, %10 ], [ %3, %2 ]
  ret ptr %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @set_up_sd_cone_work_space(ptr noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) 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 #1 = { 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 #2 = { nounwind allocsize(0,1) }

!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 = !{!"SCS_CONE_WORK", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !7, i64 24, !10, i64 32, !11, i64 40}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"double", !8, i64 0}
!12 = !{!6, !10, i64 32}
!13 = !{!6, !7, i64 24}
!14 = !{!15, !10, i64 56}
!15 = !{!"", !10, i64 0, !10, i64 4, !7, i64 8, !7, i64 16, !10, i64 24, !7, i64 32, !10, i64 40, !7, i64 48, !10, i64 56, !10, i64 60, !10, i64 64, !7, i64 72, !10, i64 80}
!16 = !{!15, !7, i64 48}


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