; LLVM IR from Derek-TH-Wang/quadruped_ctrl :: src/JCQP/amd/src (SuiteSparse_config)

; 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: nounwind allocsize(1)
declare ptr @realloc(ptr noundef, i64 noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local ptr @SuiteSparse_malloc(i64 noundef, i64 noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @SuiteSparse_realloc(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #1 {
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  store i64 %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !9
  store ptr %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #3
  %13 = load i64, ptr %7, align 8, !tbaa !5
  %14 = icmp ult i64 %13, 1
  br i1 %14, label %15, label %16

15:                                               ; preds = %5
  store i64 1, ptr %7, align 8, !tbaa !5
  br label %16

16:                                               ; preds = %15, %5
  %17 = load i64, ptr %6, align 8, !tbaa !5
  %18 = icmp ult i64 %17, 1
  br i1 %18, label %19, label %20

19:                                               ; preds = %16
  store i64 1, ptr %6, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %19, %16
  %21 = load i64, ptr %8, align 8, !tbaa !5
  %22 = icmp ult i64 %21, 1
  br i1 %22, label %23, label %24

23:                                               ; preds = %20
  store i64 1, ptr %8, align 8, !tbaa !5
  br label %24

24:                                               ; preds = %23, %20
  %25 = load i64, ptr %6, align 8, !tbaa !5
  %26 = load i64, ptr %8, align 8, !tbaa !5
  %27 = mul i64 %25, %26
  store i64 %27, ptr %11, align 8, !tbaa !5
  %28 = load i64, ptr %11, align 8, !tbaa !5
  %29 = uitofp i64 %28 to double
  %30 = load i64, ptr %6, align 8, !tbaa !5
  %31 = uitofp i64 %30 to double
  %32 = load i64, ptr %8, align 8, !tbaa !5
  %33 = uitofp i64 %32 to double
  %34 = fmul double %31, %33
  %35 = fcmp une double %29, %34
  br i1 %35, label %36, label %38

36:                                               ; preds = %24
  %37 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 0, ptr %37, align 4, !tbaa !11
  br label %76

38:                                               ; preds = %24
  %39 = load ptr, ptr %9, align 8, !tbaa !9
  %40 = icmp eq ptr %39, null
  br i1 %40, label %41, label %49

41:                                               ; preds = %38
  %42 = load i64, ptr %6, align 8, !tbaa !5
  %43 = load i64, ptr %8, align 8, !tbaa !5
  %44 = call ptr @SuiteSparse_malloc(i64 noundef %42, i64 noundef %43)
  store ptr %44, ptr %9, align 8, !tbaa !9
  %45 = load ptr, ptr %9, align 8, !tbaa !9
  %46 = icmp ne ptr %45, null
  %47 = zext i1 %46 to i32
  %48 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 %47, ptr %48, align 4, !tbaa !11
  br label %75

49:                                               ; preds = %38
  %50 = load i64, ptr %7, align 8, !tbaa !5
  %51 = load i64, ptr %6, align 8, !tbaa !5
  %52 = icmp eq i64 %50, %51
  br i1 %52, label %53, label %55

53:                                               ; preds = %49
  %54 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 1, ptr %54, align 4, !tbaa !11
  br label %74

55:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %56 = load ptr, ptr %9, align 8, !tbaa !9
  %57 = load i64, ptr %11, align 8, !tbaa !5
  %58 = call ptr @realloc(ptr noundef %56, i64 noundef %57) #4
  store ptr %58, ptr %12, align 8, !tbaa !9
  %59 = load ptr, ptr %12, align 8, !tbaa !9
  %60 = icmp eq ptr %59, null
  br i1 %60, label %61, label %70

61:                                               ; preds = %55
  %62 = load i64, ptr %6, align 8, !tbaa !5
  %63 = load i64, ptr %7, align 8, !tbaa !5
  %64 = icmp ult i64 %62, %63
  br i1 %64, label %65, label %67

65:                                               ; preds = %61
  %66 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 1, ptr %66, align 4, !tbaa !11
  br label %69

67:                                               ; preds = %61
  %68 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 0, ptr %68, align 4, !tbaa !11
  br label %69

69:                                               ; preds = %67, %65
  br label %73

70:                                               ; preds = %55
  %71 = load ptr, ptr %12, align 8, !tbaa !9
  store ptr %71, ptr %9, align 8, !tbaa !9
  %72 = load ptr, ptr %10, align 8, !tbaa !9
  store i32 1, ptr %72, align 4, !tbaa !11
  br label %73

73:                                               ; preds = %70, %69
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  br label %74

74:                                               ; preds = %73, %53
  br label %75

75:                                               ; preds = %74, %41
  br label %76

76:                                               ; preds = %75, %36
  %77 = load ptr, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #3
  ret ptr %77
}

attributes #0 = { nounwind allocsize(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 = { 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 = { nounwind }
attributes #4 = { nounwind allocsize(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 = !{!"long", !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, !12, i64 0}
!12 = !{!"int", !7, i64 0}


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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @SuiteSparse_realloc(i64 noundef %0, i64 noundef %1, i64 noundef %2, ptr noundef %3, ptr nocapture noundef writeonly %4) local_unnamed_addr #1 {
  %spec.store.select = tail call i64 @llvm.umax.i64(i64 %1, i64 1)
  %spec.store.select2 = tail call i64 @llvm.umax.i64(i64 %0, i64 1)
  %spec.store.select1 = tail call i64 @llvm.umax.i64(i64 %2, i64 1)
  %6 = mul i64 %spec.store.select1, %spec.store.select2
  %7 = uitofp i64 %6 to double
  %8 = uitofp i64 %spec.store.select2 to double
  %9 = uitofp i64 %spec.store.select1 to double
  %10 = fmul double %8, %9
  %11 = fcmp une double %10, %7
  br i1 %11, label %23, label %12

12:                                               ; preds = %5
  %13 = icmp eq ptr %3, null
  br i1 %13, label %14, label %17

14:                                               ; preds = %12
  %15 = tail call ptr @SuiteSparse_malloc(i64 noundef %spec.store.select2, i64 noundef %spec.store.select1)
  %16 = icmp ne ptr %15, null
  br label %23

17:                                               ; preds = %12
  %18 = icmp eq i64 %spec.store.select, %spec.store.select2
  br i1 %18, label %23, label %19

19:                                               ; preds = %17
  %20 = tail call ptr @realloc(ptr noundef nonnull %3, i64 noundef %6) #3
  %21 = icmp ne ptr %20, null
  %22 = icmp ult i64 %spec.store.select2, %1
  %spec.select = or i1 %21, %22
  %spec.select30 = select i1 %21, ptr %20, ptr %3
  br label %23

23:                                               ; preds = %19, %17, %5, %14
  %.sink.shrunk = phi i1 [ %16, %14 ], [ false, %5 ], [ true, %17 ], [ %spec.select, %19 ]
  %.1 = phi ptr [ %15, %14 ], [ %3, %5 ], [ %3, %17 ], [ %spec.select30, %19 ]
  %.sink = zext i1 %.sink.shrunk to i32
  store i32 %.sink, ptr %4, align 4, !tbaa !5
  ret ptr %.1
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umax.i64(i64, i64) #2

attributes #0 = { mustprogress nounwind willreturn allockind("realloc") allocsize(1) memory(argmem: readwrite, 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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nounwind allocsize(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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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