; LLVM IR from cvxgrp/scs :: linsys/gpu/indirect (private)

; 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_LIN_SYS_WORK = type { i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i64, ptr, ptr, ptr, ptr, ptr, ptr, ptr }

; Function Attrs: nounwind uwtable
define dso_local void @scs_free_lin_sys_work(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = icmp ne ptr %3, null
  br i1 %4, label %5, label %115

5:                                                ; preds = %1
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %6, i32 0, i32 3
  %8 = load ptr, ptr %7, align 8, !tbaa !9
  call void @free(ptr noundef %8) #3
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %9, i32 0, i32 24
  %11 = load ptr, ptr %10, align 8, !tbaa !13
  call void @free(ptr noundef %11) #3
  %12 = load ptr, ptr %2, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %12, i32 0, i32 4
  %14 = load ptr, ptr %13, align 8, !tbaa !14
  %15 = call i32 @cudaFree(ptr noundef %14)
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %16, i32 0, i32 5
  %18 = load ptr, ptr %17, align 8, !tbaa !15
  %19 = call i32 @cudaFree(ptr noundef %18)
  %20 = load ptr, ptr %2, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %20, i32 0, i32 6
  %22 = load ptr, ptr %21, align 8, !tbaa !16
  %23 = call i32 @cudaFree(ptr noundef %22)
  %24 = load ptr, ptr %2, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %24, i32 0, i32 7
  %26 = load ptr, ptr %25, align 8, !tbaa !17
  %27 = call i32 @cudaFree(ptr noundef %26)
  %28 = load ptr, ptr %2, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %28, i32 0, i32 8
  %30 = load ptr, ptr %29, align 8, !tbaa !18
  %31 = call i32 @cudaFree(ptr noundef %30)
  %32 = load ptr, ptr %2, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %32, i32 0, i32 9
  %34 = load ptr, ptr %33, align 8, !tbaa !19
  %35 = call i32 @cudaFree(ptr noundef %34)
  %36 = load ptr, ptr %2, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %36, i32 0, i32 10
  %38 = load ptr, ptr %37, align 8, !tbaa !20
  %39 = call i32 @cudaFree(ptr noundef %38)
  %40 = load ptr, ptr %2, align 8, !tbaa !5
  %41 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %40, i32 0, i32 23
  %42 = load ptr, ptr %41, align 8, !tbaa !21
  %43 = call i32 @cudaFree(ptr noundef %42)
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %44, i32 0, i32 25
  %46 = load ptr, ptr %45, align 8, !tbaa !22
  %47 = call i32 @cudaFree(ptr noundef %46)
  %48 = load ptr, ptr %2, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %48, i32 0, i32 15
  %50 = load ptr, ptr %49, align 8, !tbaa !23
  %51 = icmp ne ptr %50, null
  br i1 %51, label %52, label %59

52:                                               ; preds = %5
  %53 = load ptr, ptr %2, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %53, i32 0, i32 15
  %55 = load ptr, ptr %54, align 8, !tbaa !23
  call void @_scs_free_gpu_matrix(ptr noundef %55)
  %56 = load ptr, ptr %2, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %56, i32 0, i32 15
  %58 = load ptr, ptr %57, align 8, !tbaa !23
  call void @free(ptr noundef %58) #3
  br label %59

59:                                               ; preds = %52, %5
  %60 = load ptr, ptr %2, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %60, i32 0, i32 13
  %62 = load ptr, ptr %61, align 8, !tbaa !24
  %63 = icmp ne ptr %62, null
  br i1 %63, label %64, label %71

64:                                               ; preds = %59
  %65 = load ptr, ptr %2, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %65, i32 0, i32 13
  %67 = load ptr, ptr %66, align 8, !tbaa !24
  call void @_scs_free_gpu_matrix(ptr noundef %67)
  %68 = load ptr, ptr %2, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %68, i32 0, i32 13
  %70 = load ptr, ptr %69, align 8, !tbaa !24
  call void @free(ptr noundef %70) #3
  br label %71

71:                                               ; preds = %64, %59
  %72 = load ptr, ptr %2, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %72, i32 0, i32 14
  %74 = load ptr, ptr %73, align 8, !tbaa !25
  %75 = icmp ne ptr %74, null
  br i1 %75, label %76, label %83

76:                                               ; preds = %71
  %77 = load ptr, ptr %2, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %77, i32 0, i32 14
  %79 = load ptr, ptr %78, align 8, !tbaa !25
  call void @_scs_free_gpu_matrix(ptr noundef %79)
  %80 = load ptr, ptr %2, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %80, i32 0, i32 14
  %82 = load ptr, ptr %81, align 8, !tbaa !25
  call void @free(ptr noundef %82) #3
  br label %83

83:                                               ; preds = %76, %71
  %84 = load ptr, ptr %2, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %84, i32 0, i32 19
  %86 = load ptr, ptr %85, align 8, !tbaa !26
  %87 = icmp ne ptr %86, null
  br i1 %87, label %88, label %93

88:                                               ; preds = %83
  %89 = load ptr, ptr %2, align 8, !tbaa !5
  %90 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %89, i32 0, i32 19
  %91 = load ptr, ptr %90, align 8, !tbaa !26
  %92 = call i32 @cudaFree(ptr noundef %91)
  br label %93

93:                                               ; preds = %88, %83
  %94 = load ptr, ptr %2, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %94, i32 0, i32 20
  %96 = load ptr, ptr %95, align 8, !tbaa !27
  %97 = call i32 @cusparseDestroyDnVec(ptr noundef %96)
  %98 = load ptr, ptr %2, align 8, !tbaa !5
  %99 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %98, i32 0, i32 21
  %100 = load ptr, ptr %99, align 8, !tbaa !28
  %101 = call i32 @cusparseDestroyDnVec(ptr noundef %100)
  %102 = load ptr, ptr %2, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %102, i32 0, i32 22
  %104 = load ptr, ptr %103, align 8, !tbaa !29
  %105 = call i32 @cusparseDestroyDnVec(ptr noundef %104)
  %106 = load ptr, ptr %2, align 8, !tbaa !5
  %107 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %106, i32 0, i32 17
  %108 = load ptr, ptr %107, align 8, !tbaa !30
  %109 = call i32 @cusparseDestroy(ptr noundef %108)
  %110 = load ptr, ptr %2, align 8, !tbaa !5
  %111 = getelementptr inbounds %struct.SCS_LIN_SYS_WORK, ptr %110, i32 0, i32 16
  %112 = load ptr, ptr %111, align 8, !tbaa !31
  %113 = call i32 @cublasDestroy_v2(ptr noundef %112)
  %114 = load ptr, ptr %2, align 8, !tbaa !5
  call void @free(ptr noundef %114) #3
  br label %115

115:                                              ; preds = %93, %1
  ret void
}

; Function Attrs: nounwind
declare void @free(ptr noundef) #1

declare i32 @cudaFree(ptr noundef) #2

declare void @_scs_free_gpu_matrix(ptr noundef) #2

declare i32 @cusparseDestroyDnVec(ptr noundef) #2

declare i32 @cusparseDestroy(ptr noundef) #2

declare i32 @cublasDestroy_v2(ptr noundef) #2

attributes #0 = { 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 #1 = { 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 #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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !6, i64 16}
!10 = !{!"SCS_LIN_SYS_WORK", !11, i64 0, !11, i64 4, !11, i64 8, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !6, i64 88, !6, i64 96, !6, i64 104, !6, i64 112, !6, i64 120, !6, i64 128, !12, i64 136, !6, i64 144, !6, i64 152, !6, i64 160, !6, i64 168, !6, i64 176, !6, i64 184, !6, i64 192}
!11 = !{!"int", !7, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!10, !6, i64 184}
!14 = !{!10, !6, i64 24}
!15 = !{!10, !6, i64 32}
!16 = !{!10, !6, i64 40}
!17 = !{!10, !6, i64 48}
!18 = !{!10, !6, i64 56}
!19 = !{!10, !6, i64 64}
!20 = !{!10, !6, i64 72}
!21 = !{!10, !6, i64 176}
!22 = !{!10, !6, i64 192}
!23 = !{!10, !6, i64 112}
!24 = !{!10, !6, i64 96}
!25 = !{!10, !6, i64 104}
!26 = !{!10, !6, i64 144}
!27 = !{!10, !6, i64 152}
!28 = !{!10, !6, i64 160}
!29 = !{!10, !6, i64 168}
!30 = !{!10, !6, i64 128}
!31 = !{!10, !6, i64 120}


; 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: nounwind uwtable
define dso_local void @scs_free_lin_sys_work(ptr noundef %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %69, label %2

2:                                                ; preds = %1
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  tail call void @free(ptr noundef %4) #3
  %5 = getelementptr inbounds i8, ptr %0, i64 184
  %6 = load ptr, ptr %5, align 8, !tbaa !12
  tail call void @free(ptr noundef %6) #3
  %7 = getelementptr inbounds i8, ptr %0, i64 24
  %8 = load ptr, ptr %7, align 8, !tbaa !13
  %9 = tail call i32 @cudaFree(ptr noundef %8) #3
  %10 = getelementptr inbounds i8, ptr %0, i64 32
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  %12 = tail call i32 @cudaFree(ptr noundef %11) #3
  %13 = getelementptr inbounds i8, ptr %0, i64 40
  %14 = load ptr, ptr %13, align 8, !tbaa !15
  %15 = tail call i32 @cudaFree(ptr noundef %14) #3
  %16 = getelementptr inbounds i8, ptr %0, i64 48
  %17 = load ptr, ptr %16, align 8, !tbaa !16
  %18 = tail call i32 @cudaFree(ptr noundef %17) #3
  %19 = getelementptr inbounds i8, ptr %0, i64 56
  %20 = load ptr, ptr %19, align 8, !tbaa !17
  %21 = tail call i32 @cudaFree(ptr noundef %20) #3
  %22 = getelementptr inbounds i8, ptr %0, i64 64
  %23 = load ptr, ptr %22, align 8, !tbaa !18
  %24 = tail call i32 @cudaFree(ptr noundef %23) #3
  %25 = getelementptr inbounds i8, ptr %0, i64 72
  %26 = load ptr, ptr %25, align 8, !tbaa !19
  %27 = tail call i32 @cudaFree(ptr noundef %26) #3
  %28 = getelementptr inbounds i8, ptr %0, i64 176
  %29 = load ptr, ptr %28, align 8, !tbaa !20
  %30 = tail call i32 @cudaFree(ptr noundef %29) #3
  %31 = getelementptr inbounds i8, ptr %0, i64 192
  %32 = load ptr, ptr %31, align 8, !tbaa !21
  %33 = tail call i32 @cudaFree(ptr noundef %32) #3
  %34 = getelementptr inbounds i8, ptr %0, i64 112
  %35 = load ptr, ptr %34, align 8, !tbaa !22
  %.not33 = icmp eq ptr %35, null
  br i1 %.not33, label %38, label %36

36:                                               ; preds = %2
  tail call void @_scs_free_gpu_matrix(ptr noundef nonnull %35) #3
  %37 = load ptr, ptr %34, align 8, !tbaa !22
  tail call void @free(ptr noundef %37) #3
  br label %38

38:                                               ; preds = %36, %2
  %39 = getelementptr inbounds i8, ptr %0, i64 96
  %40 = load ptr, ptr %39, align 8, !tbaa !23
  %.not34 = icmp eq ptr %40, null
  br i1 %.not34, label %43, label %41

41:                                               ; preds = %38
  tail call void @_scs_free_gpu_matrix(ptr noundef nonnull %40) #3
  %42 = load ptr, ptr %39, align 8, !tbaa !23
  tail call void @free(ptr noundef %42) #3
  br label %43

43:                                               ; preds = %41, %38
  %44 = getelementptr inbounds i8, ptr %0, i64 104
  %45 = load ptr, ptr %44, align 8, !tbaa !24
  %.not35 = icmp eq ptr %45, null
  br i1 %.not35, label %48, label %46

46:                                               ; preds = %43
  tail call void @_scs_free_gpu_matrix(ptr noundef nonnull %45) #3
  %47 = load ptr, ptr %44, align 8, !tbaa !24
  tail call void @free(ptr noundef %47) #3
  br label %48

48:                                               ; preds = %46, %43
  %49 = getelementptr inbounds i8, ptr %0, i64 144
  %50 = load ptr, ptr %49, align 8, !tbaa !25
  %.not36 = icmp eq ptr %50, null
  br i1 %.not36, label %53, label %51

51:                                               ; preds = %48
  %52 = tail call i32 @cudaFree(ptr noundef nonnull %50) #3
  br label %53

53:                                               ; preds = %51, %48
  %54 = getelementptr inbounds i8, ptr %0, i64 152
  %55 = load ptr, ptr %54, align 8, !tbaa !26
  %56 = tail call i32 @cusparseDestroyDnVec(ptr noundef %55) #3
  %57 = getelementptr inbounds i8, ptr %0, i64 160
  %58 = load ptr, ptr %57, align 8, !tbaa !27
  %59 = tail call i32 @cusparseDestroyDnVec(ptr noundef %58) #3
  %60 = getelementptr inbounds i8, ptr %0, i64 168
  %61 = load ptr, ptr %60, align 8, !tbaa !28
  %62 = tail call i32 @cusparseDestroyDnVec(ptr noundef %61) #3
  %63 = getelementptr inbounds i8, ptr %0, i64 128
  %64 = load ptr, ptr %63, align 8, !tbaa !29
  %65 = tail call i32 @cusparseDestroy(ptr noundef %64) #3
  %66 = getelementptr inbounds i8, ptr %0, i64 120
  %67 = load ptr, ptr %66, align 8, !tbaa !30
  %68 = tail call i32 @cublasDestroy_v2(ptr noundef %67) #3
  tail call void @free(ptr noundef nonnull %0) #3
  br label %69

69:                                               ; preds = %53, %1
  ret void
}

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

declare i32 @cudaFree(ptr noundef) local_unnamed_addr #2

declare void @_scs_free_gpu_matrix(ptr noundef) local_unnamed_addr #2

declare i32 @cusparseDestroyDnVec(ptr noundef) local_unnamed_addr #2

declare i32 @cusparseDestroy(ptr noundef) local_unnamed_addr #2

declare i32 @cublasDestroy_v2(ptr noundef) local_unnamed_addr #2

attributes #0 = { 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 #1 = { mustprogress nounwind willreturn allockind("free") 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 #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 = { 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, !10, i64 16}
!6 = !{!"SCS_LIN_SYS_WORK", !7, i64 0, !7, i64 4, !7, i64 8, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !10, i64 72, !10, i64 80, !10, i64 88, !10, i64 96, !10, i64 104, !10, i64 112, !10, i64 120, !10, i64 128, !11, i64 136, !10, i64 144, !10, i64 152, !10, i64 160, !10, i64 168, !10, i64 176, !10, i64 184, !10, i64 192}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!6, !10, i64 184}
!13 = !{!6, !10, i64 24}
!14 = !{!6, !10, i64 32}
!15 = !{!6, !10, i64 40}
!16 = !{!6, !10, i64 48}
!17 = !{!6, !10, i64 56}
!18 = !{!6, !10, i64 64}
!19 = !{!6, !10, i64 72}
!20 = !{!6, !10, i64 176}
!21 = !{!6, !10, i64 192}
!22 = !{!6, !10, i64 112}
!23 = !{!6, !10, i64 96}
!24 = !{!6, !10, i64 104}
!25 = !{!6, !10, i64 144}
!26 = !{!6, !10, i64 152}
!27 = !{!6, !10, i64 160}
!28 = !{!6, !10, i64 168}
!29 = !{!6, !10, i64 128}
!30 = !{!6, !10, i64 120}


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