; LLVM IR from Tencent-RoboticsX/jbdl :: src/jbdl/experimental/qpoases/src (Utils)

; 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.qpOASES::MatMatrixHeader" = type { i64, i64, i64, i64, i64 }

; 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

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_ZN7qpOASES16writeIntoMatFileEP8_IO_FILEPKdiiPKc(ptr noundef %0, ptr noundef %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) #1 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca %"struct.qpOASES::MatMatrixHeader", align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca double, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i32 %2, ptr %9, align 4, !tbaa !9
  store i32 %3, ptr %10, align 4, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %31, label %19

19:                                               ; preds = %5
  %20 = load ptr, ptr %8, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %31, label %22

22:                                               ; preds = %19
  %23 = load i32, ptr %9, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %31, label %25

25:                                               ; preds = %22
  %26 = load i32, ptr %10, align 4, !tbaa !9
  %27 = icmp slt i32 %26, 0
  br i1 %27, label %31, label %28

28:                                               ; preds = %25
  %29 = load ptr, ptr %11, align 8, !tbaa !5
  %30 = icmp eq ptr %29, null
  br i1 %30, label %31, label %32

31:                                               ; preds = %28, %25, %22, %19, %5
  store i32 3, ptr %6, align 4
  br label %92

32:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 40, ptr %12) #4
  %33 = getelementptr inbounds %"struct.qpOASES::MatMatrixHeader", ptr %12, i32 0, i32 0
  store i64 0, ptr %33, align 8, !tbaa !11
  %34 = load i32, ptr %9, align 4, !tbaa !9
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds %"struct.qpOASES::MatMatrixHeader", ptr %12, i32 0, i32 1
  store i64 %35, ptr %36, align 8, !tbaa !14
  %37 = load i32, ptr %10, align 4, !tbaa !9
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds %"struct.qpOASES::MatMatrixHeader", ptr %12, i32 0, i32 2
  store i64 %38, ptr %39, align 8, !tbaa !15
  %40 = getelementptr inbounds %"struct.qpOASES::MatMatrixHeader", ptr %12, i32 0, i32 3
  store i64 0, ptr %40, align 8, !tbaa !16
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = call i64 @strlen(ptr noundef %41) #5
  %43 = add nsw i64 %42, 1
  %44 = getelementptr inbounds %"struct.qpOASES::MatMatrixHeader", ptr %12, i32 0, i32 4
  store i64 %43, ptr %44, align 8, !tbaa !17
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  %46 = call i64 @fwrite(ptr noundef %12, i64 noundef 40, i64 noundef 1, ptr noundef %45)
  %47 = icmp ult i64 %46, 1
  br i1 %47, label %48, label %49

48:                                               ; preds = %32
  store i32 128, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %91

49:                                               ; preds = %32
  %50 = load ptr, ptr %11, align 8, !tbaa !5
  %51 = getelementptr inbounds %"struct.qpOASES::MatMatrixHeader", ptr %12, i32 0, i32 4
  %52 = load i64, ptr %51, align 8, !tbaa !17
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = call i64 @fwrite(ptr noundef %50, i64 noundef 1, i64 noundef %52, ptr noundef %53)
  %55 = icmp ult i64 %54, 1
  br i1 %55, label %56, label %57

56:                                               ; preds = %49
  store i32 128, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %91

57:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  store i32 0, ptr %14, align 4, !tbaa !9
  br label %58

58:                                               ; preds = %86, %57
  %59 = load i32, ptr %14, align 4, !tbaa !9
  %60 = load i32, ptr %10, align 4, !tbaa !9
  %61 = icmp slt i32 %59, %60
  br i1 %61, label %62, label %89

62:                                               ; preds = %58
  store i32 0, ptr %15, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %82, %62
  %64 = load i32, ptr %15, align 4, !tbaa !9
  %65 = load i32, ptr %9, align 4, !tbaa !9
  %66 = icmp slt i32 %64, %65
  br i1 %66, label %67, label %85

67:                                               ; preds = %63
  %68 = load ptr, ptr %8, align 8, !tbaa !5
  %69 = load i32, ptr %15, align 4, !tbaa !9
  %70 = load i32, ptr %10, align 4, !tbaa !9
  %71 = mul nsw i32 %69, %70
  %72 = load i32, ptr %14, align 4, !tbaa !9
  %73 = add nsw i32 %71, %72
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds double, ptr %68, i64 %74
  %76 = load double, ptr %75, align 8, !tbaa !18
  store double %76, ptr %16, align 8, !tbaa !18
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  %78 = call i64 @fwrite(ptr noundef %16, i64 noundef 8, i64 noundef 1, ptr noundef %77)
  %79 = icmp ult i64 %78, 1
  br i1 %79, label %80, label %81

80:                                               ; preds = %67
  store i32 128, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %90

81:                                               ; preds = %67
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %15, align 4, !tbaa !9
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %15, align 4, !tbaa !9
  br label %63, !llvm.loop !20

85:                                               ; preds = %63
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %14, align 4, !tbaa !9
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %14, align 4, !tbaa !9
  br label %58, !llvm.loop !22

89:                                               ; preds = %58
  store i32 0, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %90

90:                                               ; preds = %89, %80
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %91

91:                                               ; preds = %90, %56, %48
  call void @llvm.lifetime.end.p0(i64 40, ptr %12) #4
  br label %92

92:                                               ; preds = %91, %31
  %93 = load i32, ptr %6, align 4
  ret i32 %93
}

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #2

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nounwind willreturn memory(read) "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 = { "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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, !13, i64 0}
!12 = !{!"_ZTSN7qpOASES15MatMatrixHeaderE", !13, i64 0, !13, i64 8, !13, i64 16, !13, i64 24, !13, i64 32}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!12, !13, i64 16}
!16 = !{!12, !13, i64 24}
!17 = !{!12, !13, i64 32}
!18 = !{!19, !19, i64 0}
!19 = !{!"double", !7, i64 0}
!20 = distinct !{!20, !21}
!21 = !{!"llvm.loop.mustprogress"}
!22 = distinct !{!22, !21}


; 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.qpOASES::MatMatrixHeader" = type { i64, i64, i64, i64, i64 }

; 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: mustprogress nofree nounwind uwtable
define dso_local noundef range(i32 0, 129) i32 @_ZN7qpOASES16writeIntoMatFileEP8_IO_FILEPKdiiPKc(ptr noundef %0, ptr noundef readonly %1, i32 noundef %2, i32 noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = alloca %"struct.qpOASES::MatMatrixHeader", align 8
  %7 = alloca double, align 8
  %8 = icmp eq ptr %0, null
  %9 = icmp eq ptr %1, null
  %or.cond = or i1 %8, %9
  %10 = or i32 %3, %2
  %11 = icmp slt i32 %10, 0
  %or.cond5 = or i1 %or.cond, %11
  %12 = icmp eq ptr %4, null
  %or.cond7 = or i1 %12, %or.cond5
  br i1 %or.cond7, label %38, label %13

13:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 40, ptr nonnull %6) #4
  store i64 0, ptr %6, align 8, !tbaa !5
  %14 = zext i32 %2 to i64
  %15 = getelementptr inbounds i8, ptr %6, i64 8
  store i64 %14, ptr %15, align 8, !tbaa !10
  %16 = zext i32 %3 to i64
  %17 = getelementptr inbounds i8, ptr %6, i64 16
  store i64 %16, ptr %17, align 8, !tbaa !11
  %18 = getelementptr inbounds i8, ptr %6, i64 24
  store i64 0, ptr %18, align 8, !tbaa !12
  %19 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %4) #5
  %20 = add nsw i64 %19, 1
  %21 = getelementptr inbounds i8, ptr %6, i64 32
  store i64 %20, ptr %21, align 8, !tbaa !13
  %22 = call i64 @fwrite(ptr noundef nonnull %6, i64 noundef 40, i64 noundef 1, ptr noundef nonnull %0)
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %37, label %24

24:                                               ; preds = %13
  %25 = load i64, ptr %21, align 8, !tbaa !13
  %26 = tail call i64 @fwrite(ptr noundef nonnull %4, i64 noundef 1, i64 noundef %25, ptr noundef nonnull %0)
  %27 = icmp eq i64 %26, 0
  br i1 %27, label %37, label %28

28:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #4
  %29 = icmp sgt i32 %3, 0
  %30 = icmp sgt i32 %2, 0
  %or.cond47 = and i1 %29, %30
  br i1 %or.cond47, label %.preheader.us, label %.loopexit

.preheader.us:                                    ; preds = %28, %._crit_edge.us
  %indvars.iv41 = phi i64 [ %indvars.iv.next42, %._crit_edge.us ], [ 0, %28 ]
  %invariant.gep = getelementptr inbounds double, ptr %1, i64 %indvars.iv41
  br label %32

31:                                               ; preds = %32
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %14
  br i1 %exitcond.not, label %._crit_edge.us, label %32, !llvm.loop !14

32:                                               ; preds = %.preheader.us, %31
  %indvars.iv = phi i64 [ 0, %.preheader.us ], [ %indvars.iv.next, %31 ]
  %33 = mul nuw nsw i64 %indvars.iv, %16
  %gep = getelementptr inbounds double, ptr %invariant.gep, i64 %33
  %34 = load double, ptr %gep, align 8, !tbaa !16
  store double %34, ptr %7, align 8, !tbaa !16
  %35 = call i64 @fwrite(ptr noundef nonnull %7, i64 noundef 8, i64 noundef 1, ptr noundef %0)
  %36 = icmp eq i64 %35, 0
  br i1 %36, label %.loopexit, label %31

._crit_edge.us:                                   ; preds = %31
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %exitcond45.not = icmp eq i64 %indvars.iv.next42, %16
  br i1 %exitcond45.not, label %.loopexit, label %.preheader.us, !llvm.loop !18

.loopexit:                                        ; preds = %._crit_edge.us, %32, %28
  %.030 = phi i32 [ 0, %28 ], [ 128, %32 ], [ 0, %._crit_edge.us ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #4
  br label %37

37:                                               ; preds = %24, %13, %.loopexit
  %.1 = phi i32 [ %.030, %.loopexit ], [ 128, %13 ], [ 128, %24 ]
  call void @llvm.lifetime.end.p0(i64 40, ptr nonnull %6) #4
  br label %38

38:                                               ; preds = %5, %37
  %.2 = phi i32 [ %.1, %37 ], [ 3, %5 ]
  ret i32 %.2
}

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nofree 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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 "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 }
attributes #5 = { nounwind willreturn memory(read) }

!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 = !{!"_ZTSN7qpOASES15MatMatrixHeaderE", !7, i64 0, !7, i64 8, !7, i64 16, !7, i64 24, !7, i64 32}
!7 = !{!"long", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!6, !7, i64 8}
!11 = !{!6, !7, i64 16}
!12 = !{!6, !7, i64 24}
!13 = !{!6, !7, i64 32}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!17, !17, i64 0}
!17 = !{!"double", !8, i64 0}
!18 = distinct !{!18, !15}


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