; LLVM IR from dartsim/dart :: dart/external/odelcpsolver/lcp.ll (ZN4dart8external3ode26dEstimateSolveLCPMemoryReqEib)

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

; 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 i64 @_ZN4dart8external3ode26dEstimateSolveLCPMemoryReqEib(i32 noundef %0, i1 noundef zeroext %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i32 %0, ptr %3, align 4, !tbaa !5
  %8 = zext i1 %1 to i8
  store i8 %8, ptr %4, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, 1
  br i1 %10, label %11, label %16

11:                                               ; preds = %2
  %12 = load i32, ptr %3, align 4, !tbaa !5
  %13 = sub nsw i32 %12, 1
  %14 = or i32 %13, 3
  %15 = add nsw i32 %14, 1
  br label %18

16:                                               ; preds = %2
  %17 = load i32, ptr %3, align 4, !tbaa !5
  br label %18

18:                                               ; preds = %16, %11
  %19 = phi i32 [ %15, %11 ], [ %17, %16 ]
  store i32 %19, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  store i64 0, ptr %6, align 8, !tbaa !11
  %20 = load i32, ptr %3, align 4, !tbaa !5
  %21 = load i32, ptr %5, align 4, !tbaa !5
  %22 = mul nsw i32 %20, %21
  %23 = sext i32 %22 to i64
  %24 = mul i64 8, %23
  %25 = load i64, ptr %6, align 8, !tbaa !11
  %26 = add i64 %25, %24
  store i64 %26, ptr %6, align 8, !tbaa !11
  %27 = load i32, ptr %3, align 4, !tbaa !5
  %28 = sext i32 %27 to i64
  %29 = mul i64 8, %28
  %30 = mul i64 5, %29
  %31 = load i64, ptr %6, align 8, !tbaa !11
  %32 = add i64 %31, %30
  store i64 %32, ptr %6, align 8, !tbaa !11
  %33 = load i8, ptr %4, align 1, !tbaa !9, !range !13, !noundef !14
  %34 = trunc i8 %33 to i1
  br i1 %34, label %41, label %35

35:                                               ; preds = %18
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = mul i64 8, %37
  %39 = load i64, ptr %6, align 8, !tbaa !11
  %40 = add i64 %39, %38
  store i64 %40, ptr %6, align 8, !tbaa !11
  br label %41

41:                                               ; preds = %35, %18
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = mul i64 8, %43
  %45 = load i64, ptr %6, align 8, !tbaa !11
  %46 = add i64 %45, %44
  store i64 %46, ptr %6, align 8, !tbaa !11
  %47 = load i32, ptr %3, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = mul i64 4, %48
  %50 = mul i64 2, %49
  %51 = load i64, ptr %6, align 8, !tbaa !11
  %52 = add i64 %51, %50
  store i64 %52, ptr %6, align 8, !tbaa !11
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = mul i64 1, %54
  %56 = load i64, ptr %6, align 8, !tbaa !11
  %57 = add i64 %56, %55
  store i64 %57, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %58 = load i32, ptr %3, align 4, !tbaa !5
  %59 = load i32, ptr %5, align 4, !tbaa !5
  %60 = call noundef i64 @_ZN4dart8external3ode4dLCP39estimate_transfer_i_from_C_to_N_mem_reqEii(i32 noundef %58, i32 noundef %59)
  store i64 %60, ptr %7, align 8, !tbaa !11
  %61 = load i64, ptr %7, align 8, !tbaa !11
  %62 = load i64, ptr %6, align 8, !tbaa !11
  %63 = add i64 %62, %61
  store i64 %63, ptr %6, align 8, !tbaa !11
  %64 = load i64, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i64 %64
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN4dart8external3ode4dLCP39estimate_transfer_i_from_C_to_N_mem_reqEii(i32 noundef, i32 noundef) #1 align 2

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 }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


; 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 uwtable
define dso_local noundef i64 @_ZN4dart8external3ode26dEstimateSolveLCPMemoryReqEib(i32 noundef %0, i1 noundef zeroext %1) local_unnamed_addr #0 {
  %3 = icmp sgt i32 %0, 1
  %4 = add nsw i32 %0, -1
  %5 = or i32 %4, 3
  %6 = add nuw nsw i32 %5, 1
  %7 = select i1 %3, i32 %6, i32 %0
  %8 = mul nsw i32 %7, %0
  %9 = sext i32 %8 to i64
  %10 = shl nsw i64 %9, 3
  %11 = sext i32 %0 to i64
  %12 = shl nsw i64 %11, 3
  %13 = select i1 %1, i64 0, i64 %12
  %14 = tail call noundef i64 @_ZN4dart8external3ode4dLCP39estimate_transfer_i_from_C_to_N_mem_reqEii(i32 noundef %0, i32 noundef %7)
  %.0 = mul nsw i64 %11, 57
  %15 = add nsw i64 %.0, %13
  %16 = add nsw i64 %15, %10
  %17 = add i64 %16, %14
  ret i64 %17
}

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_ZN4dart8external3ode4dLCP39estimate_transfer_i_from_C_to_N_mem_reqEii(i32 noundef, i32 noundef) local_unnamed_addr #0 align 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" }

!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)"}


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