; LLVM IR from Tencent-RoboticsX/jbdl :: src/jbdl/experimental/qpoases/src/SubjectTo.ll (ZN7qpOASES9SubjectTo4initEi)

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

%"class.qpOASES::SubjectTo" = type { ptr, i32, ptr, ptr, i32, i32 }

@.str = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [104 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7qpOASES9SubjectTo4initEi(ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %1) #0 align 2 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %8 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %9 = load i32, ptr %5, align 4, !tbaa !9
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %11, label %14

11:                                               ; preds = %2
  %12 = call noundef ptr @_ZN7qpOASES23getGlobalMessageHandlerEv()
  %13 = call noundef i32 @_ZN7qpOASES15MessageHandling10throwErrorENS_11returnValueEPKcS3_S3_mNS_16VisibilityStatusE(ptr noundef nonnull align 8 dereferenceable(28) %12, i32 noundef 3, ptr noundef null, ptr noundef @.str, ptr noundef @.str.1, i64 noundef 113, i32 noundef 1)
  store i32 %13, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %63

14:                                               ; preds = %2
  %15 = call noundef i32 @_ZN7qpOASES9SubjectTo5clearEv(ptr noundef nonnull align 8 dereferenceable(40) %8)
  %16 = load i32, ptr %5, align 4, !tbaa !9
  %17 = getelementptr inbounds %"class.qpOASES::SubjectTo", ptr %8, i32 0, i32 1
  store i32 %16, ptr %17, align 8, !tbaa !11
  %18 = getelementptr inbounds %"class.qpOASES::SubjectTo", ptr %8, i32 0, i32 4
  store i32 1, ptr %18, align 8, !tbaa !14
  %19 = getelementptr inbounds %"class.qpOASES::SubjectTo", ptr %8, i32 0, i32 5
  store i32 1, ptr %19, align 4, !tbaa !15
  %20 = getelementptr inbounds %"class.qpOASES::SubjectTo", ptr %8, i32 0, i32 1
  %21 = load i32, ptr %20, align 8, !tbaa !11
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %23, label %62

23:                                               ; preds = %14
  %24 = getelementptr inbounds %"class.qpOASES::SubjectTo", ptr %8, i32 0, i32 1
  %25 = load i32, ptr %24, align 8, !tbaa !11
  %26 = sext i32 %25 to i64
  %27 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %26, i64 4)
  %28 = extractvalue { i64, i1 } %27, 1
  %29 = extractvalue { i64, i1 } %27, 0
  %30 = select i1 %28, i64 -1, i64 %29
  %31 = call noalias noundef nonnull ptr @_Znam(i64 noundef %30) #7
  %32 = getelementptr inbounds %"class.qpOASES::SubjectTo", ptr %8, i32 0, i32 2
  store ptr %31, ptr %32, align 8, !tbaa !16
  %33 = getelementptr inbounds %"class.qpOASES::SubjectTo", ptr %8, i32 0, i32 1
  %34 = load i32, ptr %33, align 8, !tbaa !11
  %35 = sext i32 %34 to i64
  %36 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %35, i64 4)
  %37 = extractvalue { i64, i1 } %36, 1
  %38 = extractvalue { i64, i1 } %36, 0
  %39 = select i1 %37, i64 -1, i64 %38
  %40 = call noalias noundef nonnull ptr @_Znam(i64 noundef %39) #7
  %41 = getelementptr inbounds %"class.qpOASES::SubjectTo", ptr %8, i32 0, i32 3
  store ptr %40, ptr %41, align 8, !tbaa !17
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %58, %23
  %43 = load i32, ptr %6, align 4, !tbaa !9
  %44 = getelementptr inbounds %"class.qpOASES::SubjectTo", ptr %8, i32 0, i32 1
  %45 = load i32, ptr %44, align 8, !tbaa !11
  %46 = icmp slt i32 %43, %45
  br i1 %46, label %47, label %61

47:                                               ; preds = %42
  %48 = getelementptr inbounds %"class.qpOASES::SubjectTo", ptr %8, i32 0, i32 2
  %49 = load ptr, ptr %48, align 8, !tbaa !16
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr %49, i64 %51
  store i32 4, ptr %52, align 4, !tbaa !18
  %53 = getelementptr inbounds %"class.qpOASES::SubjectTo", ptr %8, i32 0, i32 3
  %54 = load ptr, ptr %53, align 8, !tbaa !17
  %55 = load i32, ptr %6, align 4, !tbaa !9
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i32, ptr %54, i64 %56
  store i32 4, ptr %57, align 4, !tbaa !20
  br label %58

58:                                               ; preds = %47
  %59 = load i32, ptr %6, align 4, !tbaa !9
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %6, align 4, !tbaa !9
  br label %42, !llvm.loop !22

61:                                               ; preds = %42
  br label %62

62:                                               ; preds = %61, %14
  store i32 0, ptr %3, align 4
  store i32 1, ptr %7, align 4
  br label %63

63:                                               ; preds = %62, %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  %64 = load i32, ptr %3, align 4
  ret i32 %64
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7qpOASES9SubjectTo5clearEv(ptr noundef nonnull align 8 dereferenceable(40)) #1 align 2

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

declare noundef ptr @_ZN7qpOASES23getGlobalMessageHandlerEv() #3

declare noundef i32 @_ZN7qpOASES15MessageHandling10throwErrorENS_11returnValueEPKcS3_S3_mNS_16VisibilityStatusE(ptr noundef nonnull align 8 dereferenceable(28), i32 noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, i32 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #4

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #5

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nobuiltin 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 #6 = { nounwind }
attributes #7 = { builtin 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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !10, i64 8}
!12 = !{!"_ZTSN7qpOASES9SubjectToE", !10, i64 8, !6, i64 16, !6, i64 24, !13, i64 32, !13, i64 36}
!13 = !{!"_ZTSN7qpOASES11BooleanTypeE", !7, i64 0}
!14 = !{!12, !13, i64 32}
!15 = !{!12, !13, i64 36}
!16 = !{!12, !6, i64 16}
!17 = !{!12, !6, i64 24}
!18 = !{!19, !19, i64 0}
!19 = !{!"_ZTSN7qpOASES13SubjectToTypeE", !7, i64 0}
!20 = !{!21, !21, i64 0}
!21 = !{!"_ZTSN7qpOASES15SubjectToStatusE", !7, i64 0}
!22 = distinct !{!22, !23}
!23 = !{!"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"

@.str = external hidden unnamed_addr constant [28 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [104 x i8], align 1

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7qpOASES9SubjectTo4initEi(ptr noundef nonnull align 8 dereferenceable(40) %0, i32 noundef %1) local_unnamed_addr #0 align 2 {
  %3 = icmp slt i32 %1, 0
  br i1 %3, label %4, label %7

4:                                                ; preds = %2
  %5 = tail call noundef ptr @_ZN7qpOASES23getGlobalMessageHandlerEv()
  %6 = tail call noundef i32 @_ZN7qpOASES15MessageHandling10throwErrorENS_11returnValueEPKcS3_S3_mNS_16VisibilityStatusE(ptr noundef nonnull align 8 dereferenceable(28) %5, i32 noundef 3, ptr noundef null, ptr noundef nonnull @.str, ptr noundef nonnull @.str.1, i64 noundef 113, i32 noundef 1)
  br label %.loopexit

7:                                                ; preds = %2
  %8 = tail call noundef i32 @_ZN7qpOASES9SubjectTo5clearEv(ptr noundef nonnull align 8 dereferenceable(40) %0)
  %9 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %1, ptr %9, align 8, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 1, ptr %10, align 8, !tbaa !12
  %11 = getelementptr inbounds i8, ptr %0, i64 36
  store i32 1, ptr %11, align 4, !tbaa !13
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %7
  %12 = zext nneg i32 %1 to i64
  %13 = shl nuw nsw i64 %12, 2
  %14 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %13) #4
  %15 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %14, ptr %15, align 8, !tbaa !14
  %16 = tail call noalias noundef nonnull ptr @_Znam(i64 noundef %13) #4
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  store ptr %16, ptr %17, align 8, !tbaa !15
  %min.iters.check = icmp ult i32 %1, 8
  br i1 %min.iters.check, label %.lr.ph.preheader12, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.preheader
  %n.vec = and i64 %12, 2147483640
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %18 = getelementptr inbounds i32, ptr %14, i64 %index
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  store <4 x i32> <i32 4, i32 4, i32 4, i32 4>, ptr %18, align 4, !tbaa !16
  store <4 x i32> <i32 4, i32 4, i32 4, i32 4>, ptr %19, align 4, !tbaa !16
  %20 = getelementptr inbounds i32, ptr %16, i64 %index
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  store <4 x i32> <i32 4, i32 4, i32 4, i32 4>, ptr %20, align 4, !tbaa !18
  store <4 x i32> <i32 4, i32 4, i32 4, i32 4>, ptr %21, align 4, !tbaa !18
  %index.next = add nuw i64 %index, 8
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !20

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %12
  br i1 %cmp.n, label %.loopexit, label %.lr.ph.preheader12

.lr.ph.preheader12:                               ; preds = %middle.block, %.lr.ph.preheader
  %indvars.iv.ph = phi i64 [ 0, %.lr.ph.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader12, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ %indvars.iv.ph, %.lr.ph.preheader12 ]
  %23 = getelementptr inbounds i32, ptr %14, i64 %indvars.iv
  store i32 4, ptr %23, align 4, !tbaa !16
  %24 = getelementptr inbounds i32, ptr %16, i64 %indvars.iv
  store i32 4, ptr %24, align 4, !tbaa !18
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %12
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !24

.loopexit:                                        ; preds = %.lr.ph, %middle.block, %7, %4
  %.07 = phi i32 [ %6, %4 ], [ 0, %7 ], [ 0, %middle.block ], [ 0, %.lr.ph ]
  ret i32 %.07
}

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZN7qpOASES9SubjectTo5clearEv(ptr noundef nonnull align 8 dereferenceable(40)) local_unnamed_addr #1 align 2

declare noundef ptr @_ZN7qpOASES23getGlobalMessageHandlerEv() local_unnamed_addr #2

declare noundef i32 @_ZN7qpOASES15MessageHandling10throwErrorENS_11returnValueEPKcS3_S3_mNS_16VisibilityStatusE(ptr noundef nonnull align 8 dereferenceable(28), i32 noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #3

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 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 = { "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 = { nobuiltin 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 #4 = { builtin 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 8}
!6 = !{!"_ZTSN7qpOASES9SubjectToE", !7, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !11, i64 36}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"_ZTSN7qpOASES11BooleanTypeE", !8, i64 0}
!12 = !{!6, !11, i64 32}
!13 = !{!6, !11, i64 36}
!14 = !{!6, !10, i64 16}
!15 = !{!6, !10, i64 24}
!16 = !{!17, !17, i64 0}
!17 = !{!"_ZTSN7qpOASES13SubjectToTypeE", !8, i64 0}
!18 = !{!19, !19, i64 0}
!19 = !{!"_ZTSN7qpOASES15SubjectToStatusE", !8, i64 0}
!20 = distinct !{!20, !21, !22, !23}
!21 = !{!"llvm.loop.mustprogress"}
!22 = !{!"llvm.loop.isvectorized", i32 1}
!23 = !{!"llvm.loop.unroll.runtime.disable"}
!24 = distinct !{!24, !21, !23, !22}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass