; LLVM IR from OpenMathLib/OpenBLAS :: relapack/src (dgetrf)

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

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@__const.RELAPACK_dgetrf.ONE = external hidden unnamed_addr constant [1 x double], align 8
@__const.RELAPACK_dgetrf.iONE = external hidden unnamed_addr constant [1 x i32], align 4
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @RELAPACK_dgetrf(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #0 {
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca [1 x double], align 8
  %16 = alloca [1 x i32], align 4
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store ptr %3, ptr %10, align 8, !tbaa !5
  store ptr %4, ptr %11, align 8, !tbaa !5
  store ptr %5, ptr %12, align 8, !tbaa !5
  %20 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 0, ptr %20, align 4, !tbaa !9
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = load i32, ptr %21, align 4, !tbaa !9
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %24, label %26

24:                                               ; preds = %6
  %25 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 -1, ptr %25, align 4, !tbaa !9
  br label %49

26:                                               ; preds = %6
  %27 = load ptr, ptr %8, align 8, !tbaa !5
  %28 = load i32, ptr %27, align 4, !tbaa !9
  %29 = icmp slt i32 %28, 0
  br i1 %29, label %30, label %32

30:                                               ; preds = %26
  %31 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 -2, ptr %31, align 4, !tbaa !9
  br label %48

32:                                               ; preds = %26
  %33 = load ptr, ptr %10, align 8, !tbaa !5
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = icmp sgt i32 1, %36
  br i1 %37, label %38, label %39

38:                                               ; preds = %32
  br label %42

39:                                               ; preds = %32
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  %41 = load i32, ptr %40, align 4, !tbaa !9
  br label %42

42:                                               ; preds = %39, %38
  %43 = phi i32 [ 1, %38 ], [ %41, %39 ]
  %44 = icmp slt i32 %34, %43
  br i1 %44, label %45, label %47

45:                                               ; preds = %42
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 -4, ptr %46, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %45, %42
  br label %48

48:                                               ; preds = %47, %30
  br label %49

49:                                               ; preds = %48, %24
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = load i32, ptr %50, align 4, !tbaa !9
  %52 = icmp ne i32 %51, 0
  br i1 %52, label %53, label %58

53:                                               ; preds = %49
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = sub nsw i32 0, %55
  store i32 %56, ptr %13, align 4, !tbaa !9
  %57 = call i32 @xerbla_(ptr noundef @.str, ptr noundef %13, i32 noundef 6)
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %119

58:                                               ; preds = %49
  %59 = load ptr, ptr %7, align 8, !tbaa !5
  %60 = load i32, ptr %59, align 4, !tbaa !9
  %61 = icmp eq i32 %60, 0
  br i1 %61, label %66, label %62

62:                                               ; preds = %58
  %63 = load ptr, ptr %8, align 8, !tbaa !5
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = icmp eq i32 %64, 0
  br i1 %65, label %66, label %67

66:                                               ; preds = %62, %58
  br label %119

67:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %68 = load ptr, ptr %7, align 8, !tbaa !5
  %69 = load i32, ptr %68, align 4, !tbaa !9
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = load i32, ptr %70, align 4, !tbaa !9
  %72 = icmp slt i32 %69, %71
  br i1 %72, label %73, label %76

73:                                               ; preds = %67
  %74 = load ptr, ptr %7, align 8, !tbaa !5
  %75 = load i32, ptr %74, align 4, !tbaa !9
  br label %79

76:                                               ; preds = %67
  %77 = load ptr, ptr %8, align 8, !tbaa !5
  %78 = load i32, ptr %77, align 4, !tbaa !9
  br label %79

79:                                               ; preds = %76, %73
  %80 = phi i32 [ %75, %73 ], [ %78, %76 ]
  store i32 %80, ptr %14, align 4, !tbaa !9
  %81 = load ptr, ptr %7, align 8, !tbaa !5
  %82 = load ptr, ptr %9, align 8, !tbaa !5
  %83 = load ptr, ptr %10, align 8, !tbaa !5
  %84 = load ptr, ptr %11, align 8, !tbaa !5
  %85 = load ptr, ptr %12, align 8, !tbaa !5
  call void @RELAPACK_dgetrf_rec(ptr noundef %81, ptr noundef %14, ptr noundef %82, ptr noundef %83, ptr noundef %84, ptr noundef %85)
  %86 = load ptr, ptr %7, align 8, !tbaa !5
  %87 = load i32, ptr %86, align 4, !tbaa !9
  %88 = load ptr, ptr %8, align 8, !tbaa !5
  %89 = load i32, ptr %88, align 4, !tbaa !9
  %90 = icmp slt i32 %87, %89
  br i1 %90, label %91, label %118

91:                                               ; preds = %79
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %15, ptr align 8 @__const.RELAPACK_dgetrf.ONE, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 @__const.RELAPACK_dgetrf.iONE, i64 4, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  %92 = load ptr, ptr %8, align 8, !tbaa !5
  %93 = load i32, ptr %92, align 4, !tbaa !9
  %94 = load ptr, ptr %7, align 8, !tbaa !5
  %95 = load i32, ptr %94, align 4, !tbaa !9
  %96 = sub nsw i32 %93, %95
  store i32 %96, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %97 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %97, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %98 = load ptr, ptr %9, align 8, !tbaa !5
  %99 = load ptr, ptr %10, align 8, !tbaa !5
  %100 = load i32, ptr %99, align 4, !tbaa !9
  %101 = load ptr, ptr %7, align 8, !tbaa !5
  %102 = load i32, ptr %101, align 4, !tbaa !9
  %103 = mul nsw i32 %100, %102
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds double, ptr %98, i64 %104
  store ptr %105, ptr %19, align 8, !tbaa !5
  %106 = load ptr, ptr %19, align 8, !tbaa !5
  %107 = load ptr, ptr %10, align 8, !tbaa !5
  %108 = getelementptr inbounds [1 x i32], ptr %16, i64 0, i64 0
  %109 = load ptr, ptr %7, align 8, !tbaa !5
  %110 = load ptr, ptr %11, align 8, !tbaa !5
  %111 = getelementptr inbounds [1 x i32], ptr %16, i64 0, i64 0
  call void @dlaswp_(ptr noundef %17, ptr noundef %106, ptr noundef %107, ptr noundef %108, ptr noundef %109, ptr noundef %110, ptr noundef %111)
  %112 = load ptr, ptr %7, align 8, !tbaa !5
  %113 = getelementptr inbounds [1 x double], ptr %15, i64 0, i64 0
  %114 = load ptr, ptr %18, align 8, !tbaa !5
  %115 = load ptr, ptr %10, align 8, !tbaa !5
  %116 = load ptr, ptr %19, align 8, !tbaa !5
  %117 = load ptr, ptr %10, align 8, !tbaa !5
  call void @dtrsm_(ptr noundef @.str.1, ptr noundef @.str.1, ptr noundef @.str.2, ptr noundef @.str.3, ptr noundef %112, ptr noundef %17, ptr noundef %113, ptr noundef %114, ptr noundef %115, ptr noundef %116, ptr noundef %117)
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #4
  br label %118

118:                                              ; preds = %91, %79
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %119

119:                                              ; preds = %118, %66, %53
  ret void
}

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

declare i32 @xerbla_(ptr noundef, ptr noundef, i32 noundef) #2

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

; Function Attrs: nounwind uwtable
declare hidden void @RELAPACK_dgetrf_rec(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

declare void @dlaswp_(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #2

declare void @dtrsm_(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !10, i64 0}
!10 = !{!"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"

@.str = external hidden unnamed_addr constant [7 x i8], align 1
@__const.RELAPACK_dgetrf.ONE = external hidden unnamed_addr constant [1 x double], align 8
@__const.RELAPACK_dgetrf.iONE = external hidden unnamed_addr constant [1 x i32], align 4
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @RELAPACK_dgetrf(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) local_unnamed_addr #0 {
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca [1 x double], align 8
  %10 = alloca [1 x i32], align 4
  %11 = alloca i32, align 4
  store i32 0, ptr %5, align 4, !tbaa !5
  %12 = load i32, ptr %0, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %.thread, label %14

14:                                               ; preds = %6
  %15 = load i32, ptr %1, align 4, !tbaa !5
  %16 = icmp slt i32 %15, 0
  br i1 %16, label %.thread, label %17

17:                                               ; preds = %14
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %spec.select = tail call i32 @llvm.umax.i32(i32 %12, i32 1)
  %19 = icmp slt i32 %18, %spec.select
  br i1 %19, label %.thread, label %21

.thread:                                          ; preds = %17, %14, %6
  %.sink = phi i32 [ -1, %6 ], [ -2, %14 ], [ -4, %17 ]
  %.neg = phi i32 [ 1, %6 ], [ 2, %14 ], [ 4, %17 ]
  store i32 %.sink, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %7) #4
  store i32 %.neg, ptr %7, align 4, !tbaa !5
  %20 = call i32 @xerbla_(ptr noundef nonnull @.str, ptr noundef nonnull %7, i32 noundef 6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #4
  br label %38

21:                                               ; preds = %17
  %22 = icmp eq i32 %12, 0
  %23 = icmp eq i32 %15, 0
  %or.cond = or i1 %22, %23
  br i1 %or.cond, label %38, label %24

24:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #4
  %25 = tail call i32 @llvm.umin.i32(i32 %12, i32 %15)
  store i32 %25, ptr %8, align 4, !tbaa !5
  call void @RELAPACK_dgetrf_rec(ptr noundef nonnull %0, ptr noundef nonnull %8, ptr noundef %2, ptr noundef nonnull %3, ptr noundef %4, ptr noundef nonnull %5)
  %26 = load i32, ptr %0, align 4, !tbaa !5
  %27 = load i32, ptr %1, align 4, !tbaa !5
  %28 = icmp slt i32 %26, %27
  br i1 %28, label %29, label %37

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #4
  %30 = load i64, ptr @__const.RELAPACK_dgetrf.ONE, align 8
  store i64 %30, ptr %9, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %10) #4
  %31 = load i32, ptr @__const.RELAPACK_dgetrf.iONE, align 4
  store i32 %31, ptr %10, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %11) #4
  %32 = sub nsw i32 %27, %26
  store i32 %32, ptr %11, align 4, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = mul nsw i32 %33, %26
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds double, ptr %2, i64 %35
  call void @dlaswp_(ptr noundef nonnull %11, ptr noundef %36, ptr noundef nonnull %3, ptr noundef nonnull %10, ptr noundef nonnull %0, ptr noundef %4, ptr noundef nonnull %10) #4
  call void @dtrsm_(ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.1, ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, ptr noundef nonnull %0, ptr noundef nonnull %11, ptr noundef nonnull %9, ptr noundef %2, ptr noundef nonnull %3, ptr noundef %36, ptr noundef nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #4
  br label %37

37:                                               ; preds = %29, %24
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #4
  br label %38

38:                                               ; preds = %21, %37, %.thread
  ret void
}

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

declare i32 @xerbla_(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #2

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

; Function Attrs: nounwind uwtable
declare hidden void @RELAPACK_dgetrf_rec(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

declare void @dlaswp_(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

declare void @dtrsm_(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umin.i32(i32, i32) #3

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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/C++ TBAA"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass