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

; 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 [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @RELAPACK_zhegst(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7) #0 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i8, align 1
  %22 = alloca ptr, align 8
  %23 = alloca i32, align 4
  %24 = alloca i32, align 4
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store ptr %2, ptr %11, align 8, !tbaa !5
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store ptr %6, ptr %15, align 8, !tbaa !5
  store ptr %7, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #5
  %25 = load ptr, ptr %10, align 8, !tbaa !5
  %26 = call i32 @lsame_(ptr noundef %25, ptr noundef @.str)
  store i32 %26, ptr %17, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #5
  %27 = load ptr, ptr %10, align 8, !tbaa !5
  %28 = call i32 @lsame_(ptr noundef %27, ptr noundef @.str.1)
  store i32 %28, ptr %18, align 4, !tbaa !9
  %29 = load ptr, ptr %16, align 8, !tbaa !5
  store i32 0, ptr %29, align 4, !tbaa !9
  %30 = load ptr, ptr %9, align 8, !tbaa !5
  %31 = load i32, ptr %30, align 4, !tbaa !9
  %32 = icmp slt i32 %31, 1
  br i1 %32, label %37, label %33

33:                                               ; preds = %8
  %34 = load ptr, ptr %9, align 8, !tbaa !5
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = icmp sgt i32 %35, 3
  br i1 %36, label %37, label %39

37:                                               ; preds = %33, %8
  %38 = load ptr, ptr %16, align 8, !tbaa !5
  store i32 -1, ptr %38, align 4, !tbaa !9
  br label %87

39:                                               ; preds = %33
  %40 = load i32, ptr %17, align 4, !tbaa !9
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %47, label %42

42:                                               ; preds = %39
  %43 = load i32, ptr %18, align 4, !tbaa !9
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %47, label %45

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

47:                                               ; preds = %42, %39
  %48 = load ptr, ptr %11, align 8, !tbaa !5
  %49 = load i32, ptr %48, align 4, !tbaa !9
  %50 = icmp slt i32 %49, 0
  br i1 %50, label %51, label %53

51:                                               ; preds = %47
  %52 = load ptr, ptr %16, align 8, !tbaa !5
  store i32 -3, ptr %52, align 4, !tbaa !9
  br label %85

53:                                               ; preds = %47
  %54 = load ptr, ptr %13, align 8, !tbaa !5
  %55 = load i32, ptr %54, align 4, !tbaa !9
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load i32, ptr %56, align 4, !tbaa !9
  %58 = icmp sgt i32 1, %57
  br i1 %58, label %59, label %60

59:                                               ; preds = %53
  br label %63

60:                                               ; preds = %53
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load i32, ptr %61, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %60, %59
  %64 = phi i32 [ 1, %59 ], [ %62, %60 ]
  %65 = icmp slt i32 %55, %64
  br i1 %65, label %66, label %68

66:                                               ; preds = %63
  %67 = load ptr, ptr %16, align 8, !tbaa !5
  store i32 -5, ptr %67, align 4, !tbaa !9
  br label %84

68:                                               ; preds = %63
  %69 = load ptr, ptr %15, align 8, !tbaa !5
  %70 = load i32, ptr %69, align 4, !tbaa !9
  %71 = load ptr, ptr %11, align 8, !tbaa !5
  %72 = load i32, ptr %71, align 4, !tbaa !9
  %73 = icmp sgt i32 1, %72
  br i1 %73, label %74, label %75

74:                                               ; preds = %68
  br label %78

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

78:                                               ; preds = %75, %74
  %79 = phi i32 [ 1, %74 ], [ %77, %75 ]
  %80 = icmp slt i32 %70, %79
  br i1 %80, label %81, label %83

81:                                               ; preds = %78
  %82 = load ptr, ptr %16, align 8, !tbaa !5
  store i32 -7, ptr %82, align 4, !tbaa !9
  br label %83

83:                                               ; preds = %81, %78
  br label %84

84:                                               ; preds = %83, %66
  br label %85

85:                                               ; preds = %84, %51
  br label %86

86:                                               ; preds = %85, %45
  br label %87

87:                                               ; preds = %86, %37
  %88 = load ptr, ptr %16, align 8, !tbaa !5
  %89 = load i32, ptr %88, align 4, !tbaa !9
  %90 = icmp ne i32 %89, 0
  br i1 %90, label %91, label %96

91:                                               ; preds = %87
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #5
  %92 = load ptr, ptr %16, align 8, !tbaa !5
  %93 = load i32, ptr %92, align 4, !tbaa !9
  %94 = sub nsw i32 0, %93
  store i32 %94, ptr %19, align 4, !tbaa !9
  %95 = call i32 @xerbla_(ptr noundef @.str.2, ptr noundef %19, i32 noundef 6)
  store i32 1, ptr %20, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #5
  br label %145

96:                                               ; preds = %87
  call void @llvm.lifetime.start.p0(i64 1, ptr %21) #5
  %97 = load i32, ptr %17, align 4, !tbaa !9
  %98 = icmp ne i32 %97, 0
  %99 = zext i1 %98 to i64
  %100 = select i1 %98, i32 76, i32 85
  %101 = trunc i32 %100 to i8
  store i8 %101, ptr %21, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #5
  store ptr null, ptr %22, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #5
  store i32 0, ptr %23, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #5
  %102 = load ptr, ptr %11, align 8, !tbaa !5
  %103 = load i32, ptr %102, align 4, !tbaa !9
  %104 = icmp sge i32 %103, 8
  br i1 %104, label %105, label %111

105:                                              ; preds = %96
  %106 = load ptr, ptr %11, align 8, !tbaa !5
  %107 = load i32, ptr %106, align 4, !tbaa !9
  %108 = add nsw i32 %107, 4
  %109 = sdiv i32 %108, 8
  %110 = mul nsw i32 %109, 4
  br label %115

111:                                              ; preds = %96
  %112 = load ptr, ptr %11, align 8, !tbaa !5
  %113 = load i32, ptr %112, align 4, !tbaa !9
  %114 = sdiv i32 %113, 2
  br label %115

115:                                              ; preds = %111, %105
  %116 = phi i32 [ %110, %105 ], [ %114, %111 ]
  store i32 %116, ptr %24, align 4, !tbaa !9
  %117 = load i32, ptr %24, align 4, !tbaa !9
  %118 = load ptr, ptr %11, align 8, !tbaa !5
  %119 = load i32, ptr %118, align 4, !tbaa !9
  %120 = load i32, ptr %24, align 4, !tbaa !9
  %121 = sub nsw i32 %119, %120
  %122 = mul nsw i32 %117, %121
  store i32 %122, ptr %23, align 4, !tbaa !9
  %123 = load i32, ptr %23, align 4, !tbaa !9
  %124 = mul nsw i32 %123, 2
  %125 = sext i32 %124 to i64
  %126 = mul i64 %125, 8
  %127 = call noalias ptr @malloc(i64 noundef %126) #6
  store ptr %127, ptr %22, align 8, !tbaa !5
  %128 = load ptr, ptr %22, align 8, !tbaa !5
  %129 = icmp ne ptr %128, null
  br i1 %129, label %131, label %130

130:                                              ; preds = %115
  store i32 0, ptr %23, align 4, !tbaa !9
  br label %131

131:                                              ; preds = %130, %115
  %132 = load ptr, ptr %9, align 8, !tbaa !5
  %133 = load ptr, ptr %11, align 8, !tbaa !5
  %134 = load ptr, ptr %12, align 8, !tbaa !5
  %135 = load ptr, ptr %13, align 8, !tbaa !5
  %136 = load ptr, ptr %14, align 8, !tbaa !5
  %137 = load ptr, ptr %15, align 8, !tbaa !5
  %138 = load ptr, ptr %22, align 8, !tbaa !5
  %139 = load ptr, ptr %16, align 8, !tbaa !5
  call void @RELAPACK_zhegst_rec(ptr noundef %132, ptr noundef %21, ptr noundef %133, ptr noundef %134, ptr noundef %135, ptr noundef %136, ptr noundef %137, ptr noundef %138, ptr noundef %23, ptr noundef %139)
  %140 = load ptr, ptr %22, align 8, !tbaa !5
  %141 = icmp ne ptr %140, null
  br i1 %141, label %142, label %144

142:                                              ; preds = %131
  %143 = load ptr, ptr %22, align 8, !tbaa !5
  call void @free(ptr noundef %143) #5
  br label %144

144:                                              ; preds = %142, %131
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #5
  call void @llvm.lifetime.end.p0(i64 1, ptr %21) #5
  store i32 0, ptr %20, align 4
  br label %145

145:                                              ; preds = %144, %91
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #5
  %146 = load i32, ptr %20, align 4
  switch i32 %146, label %148 [
    i32 0, label %147
    i32 1, label %147
  ]

147:                                              ; preds = %145, %145
  ret void

148:                                              ; preds = %145
  unreachable
}

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

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

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 allocsize(0)
declare noalias ptr @malloc(i64 noundef) #3

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

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

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 = { nounwind allocsize(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 #4 = { 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 #5 = { nounwind }
attributes #6 = { nounwind allocsize(0) }

!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}
!11 = !{!7, !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 [2 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @RELAPACK_zhegst(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6, ptr noundef %7) local_unnamed_addr #0 {
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca i32, align 4
  %12 = tail call i32 @lsame_(ptr noundef %1, ptr noundef nonnull @.str) #6
  %13 = tail call i32 @lsame_(ptr noundef %1, ptr noundef nonnull @.str.1) #6
  store i32 0, ptr %7, align 4, !tbaa !5
  %14 = load i32, ptr %0, align 4, !tbaa !5
  %15 = add i32 %14, -4
  %or.cond45 = icmp ult i32 %15, -3
  br i1 %or.cond45, label %.thread, label %16

16:                                               ; preds = %8
  %17 = icmp ne i32 %12, 0
  %18 = icmp ne i32 %13, 0
  %or.cond = select i1 %17, i1 true, i1 %18
  br i1 %or.cond, label %19, label %.thread

19:                                               ; preds = %16
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = icmp slt i32 %20, 0
  br i1 %21, label %.thread, label %22

22:                                               ; preds = %19
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %spec.select = tail call i32 @llvm.umax.i32(i32 %20, i32 1)
  %24 = icmp slt i32 %23, %spec.select
  br i1 %24, label %.thread, label %25

25:                                               ; preds = %22
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = icmp slt i32 %26, %spec.select
  br i1 %27, label %.thread, label %29

.thread:                                          ; preds = %25, %22, %19, %16, %8
  %.sink = phi i32 [ -1, %8 ], [ -2, %16 ], [ -3, %19 ], [ -5, %22 ], [ -7, %25 ]
  %.neg = phi i32 [ 1, %8 ], [ 2, %16 ], [ 3, %19 ], [ 5, %22 ], [ 7, %25 ]
  store i32 %.sink, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #6
  store i32 %.neg, ptr %9, align 4, !tbaa !5
  %28 = call i32 @xerbla_(ptr noundef nonnull @.str.2, ptr noundef nonnull %9, i32 noundef 6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #6
  br label %45

29:                                               ; preds = %25
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %10) #6
  %.not43 = icmp eq i32 %12, 0
  %30 = select i1 %.not43, i8 85, i8 76
  store i8 %30, ptr %10, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %11) #6
  %31 = icmp ugt i32 %20, 7
  %32 = add nuw nsw i32 %20, 4
  %33 = lshr i32 %32, 1
  %34 = and i32 %33, 1073741820
  %35 = lshr i32 %20, 1
  %36 = select i1 %31, i32 %34, i32 %35
  %37 = sub nsw i32 %20, %36
  %38 = mul nsw i32 %37, %36
  store i32 %38, ptr %11, align 4, !tbaa !5
  %39 = shl nsw i32 %38, 1
  %40 = sext i32 %39 to i64
  %41 = shl nsw i64 %40, 3
  %42 = tail call noalias ptr @malloc(i64 noundef %41) #7
  %.not44 = icmp eq ptr %42, null
  br i1 %.not44, label %43, label %.critedge

43:                                               ; preds = %29
  store i32 0, ptr %11, align 4, !tbaa !5
  call void @RELAPACK_zhegst_rec(ptr noundef nonnull %0, ptr noundef nonnull %10, ptr noundef nonnull %2, ptr noundef %3, ptr noundef nonnull %4, ptr noundef %5, ptr noundef nonnull %6, ptr noundef null, ptr noundef nonnull %11, ptr noundef nonnull %7)
  br label %44

.critedge:                                        ; preds = %29
  call void @RELAPACK_zhegst_rec(ptr noundef nonnull %0, ptr noundef nonnull %10, ptr noundef nonnull %2, ptr noundef %3, ptr noundef nonnull %4, ptr noundef %5, ptr noundef nonnull %6, ptr noundef nonnull %42, ptr noundef nonnull %11, ptr noundef nonnull %7)
  call void @free(ptr noundef nonnull %42) #6
  br label %44

44:                                               ; preds = %43, %.critedge
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %11) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %10) #6
  br label %45

45:                                               ; preds = %44, %.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 @lsame_(ptr noundef, ptr noundef) local_unnamed_addr #2

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: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

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

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

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

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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(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 #4 = { 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { nounwind allocsize(0) }

!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"}
!9 = !{!7, !7, i64 0}


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