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

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

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

33:                                               ; preds = %6
  %34 = load i32, ptr %14, align 4, !tbaa !9
  %35 = icmp ne i32 %34, 0
  br i1 %35, label %38, label %36

36:                                               ; preds = %33
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 -1, ptr %37, align 4, !tbaa !9
  br label %70

38:                                               ; preds = %33, %6
  %39 = load i32, ptr %15, align 4, !tbaa !9
  %40 = icmp ne i32 %39, 0
  br i1 %40, label %46, label %41

41:                                               ; preds = %38
  %42 = load i32, ptr %16, align 4, !tbaa !9
  %43 = icmp ne i32 %42, 0
  br i1 %43, label %46, label %44

44:                                               ; preds = %41
  %45 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 -2, ptr %45, align 4, !tbaa !9
  br label %69

46:                                               ; preds = %41, %38
  %47 = load ptr, ptr %9, align 8, !tbaa !5
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = icmp slt i32 %48, 0
  br i1 %49, label %50, label %52

50:                                               ; preds = %46
  %51 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 -3, ptr %51, align 4, !tbaa !9
  br label %68

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

58:                                               ; preds = %52
  br label %62

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

62:                                               ; preds = %59, %58
  %63 = phi i32 [ 1, %58 ], [ %61, %59 ]
  %64 = icmp slt i32 %54, %63
  br i1 %64, label %65, label %67

65:                                               ; preds = %62
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 -5, ptr %66, align 4, !tbaa !9
  br label %67

67:                                               ; preds = %65, %62
  br label %68

68:                                               ; preds = %67, %50
  br label %69

69:                                               ; preds = %68, %44
  br label %70

70:                                               ; preds = %69, %36
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  %72 = load i32, ptr %71, align 4, !tbaa !9
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %74, label %79

74:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #3
  %75 = load ptr, ptr %12, align 8, !tbaa !5
  %76 = load i32, ptr %75, align 4, !tbaa !9
  %77 = sub nsw i32 0, %76
  store i32 %77, ptr %17, align 4, !tbaa !9
  %78 = call i32 @xerbla_(ptr noundef @.str.3, ptr noundef %17, i32 noundef 6)
  store i32 1, ptr %18, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #3
  br label %142

79:                                               ; preds = %70
  call void @llvm.lifetime.start.p0(i64 1, ptr %19) #3
  %80 = load i32, ptr %13, align 4, !tbaa !9
  %81 = icmp ne i32 %80, 0
  %82 = zext i1 %81 to i64
  %83 = select i1 %81, i32 76, i32 85
  %84 = trunc i32 %83 to i8
  store i8 %84, ptr %19, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %20) #3
  %85 = load i32, ptr %15, align 4, !tbaa !9
  %86 = icmp ne i32 %85, 0
  %87 = zext i1 %86 to i64
  %88 = select i1 %86, i32 78, i32 85
  %89 = trunc i32 %88 to i8
  store i8 %89, ptr %20, align 1, !tbaa !11
  %90 = load i32, ptr %15, align 4, !tbaa !9
  %91 = icmp ne i32 %90, 0
  br i1 %91, label %92, label %136

92:                                               ; preds = %79
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #3
  store i32 0, ptr %21, align 4, !tbaa !9
  br label %93

93:                                               ; preds = %129, %92
  %94 = load i32, ptr %21, align 4, !tbaa !9
  %95 = load ptr, ptr %9, align 8, !tbaa !5
  %96 = load i32, ptr %95, align 4, !tbaa !9
  %97 = icmp slt i32 %94, %96
  br i1 %97, label %98, label %132

98:                                               ; preds = %93
  %99 = load ptr, ptr %10, align 8, !tbaa !5
  %100 = load i32, ptr %21, align 4, !tbaa !9
  %101 = load ptr, ptr %11, align 8, !tbaa !5
  %102 = load i32, ptr %101, align 4, !tbaa !9
  %103 = load i32, ptr %21, align 4, !tbaa !9
  %104 = mul nsw i32 %102, %103
  %105 = add nsw i32 %100, %104
  %106 = mul nsw i32 2, %105
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds double, ptr %99, i64 %107
  %109 = load double, ptr %108, align 8, !tbaa !12
  %110 = fcmp oeq double %109, 0.000000e+00
  br i1 %110, label %111, label %128

111:                                              ; preds = %98
  %112 = load ptr, ptr %10, align 8, !tbaa !5
  %113 = load i32, ptr %21, align 4, !tbaa !9
  %114 = load ptr, ptr %11, align 8, !tbaa !5
  %115 = load i32, ptr %114, align 4, !tbaa !9
  %116 = load i32, ptr %21, align 4, !tbaa !9
  %117 = mul nsw i32 %115, %116
  %118 = add nsw i32 %113, %117
  %119 = mul nsw i32 2, %118
  %120 = add nsw i32 %119, 1
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds double, ptr %112, i64 %121
  %123 = load double, ptr %122, align 8, !tbaa !12
  %124 = fcmp oeq double %123, 0.000000e+00
  br i1 %124, label %125, label %128

125:                                              ; preds = %111
  %126 = load i32, ptr %21, align 4, !tbaa !9
  %127 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 %126, ptr %127, align 4, !tbaa !9
  store i32 1, ptr %18, align 4
  br label %133

128:                                              ; preds = %111, %98
  br label %129

129:                                              ; preds = %128
  %130 = load i32, ptr %21, align 4, !tbaa !9
  %131 = add nsw i32 %130, 1
  store i32 %131, ptr %21, align 4, !tbaa !9
  br label %93, !llvm.loop !14

132:                                              ; preds = %93
  store i32 0, ptr %18, align 4
  br label %133

133:                                              ; preds = %132, %125
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #3
  %134 = load i32, ptr %18, align 4
  switch i32 %134, label %141 [
    i32 0, label %135
  ]

135:                                              ; preds = %133
  br label %136

136:                                              ; preds = %135, %79
  %137 = load ptr, ptr %9, align 8, !tbaa !5
  %138 = load ptr, ptr %10, align 8, !tbaa !5
  %139 = load ptr, ptr %11, align 8, !tbaa !5
  %140 = load ptr, ptr %12, align 8, !tbaa !5
  call void @RELAPACK_ztrtri_rec(ptr noundef %19, ptr noundef %20, ptr noundef %137, ptr noundef %138, ptr noundef %139, ptr noundef %140)
  store i32 0, ptr %18, align 4
  br label %141

141:                                              ; preds = %136, %133
  call void @llvm.lifetime.end.p0(i64 1, ptr %20) #3
  call void @llvm.lifetime.end.p0(i64 1, ptr %19) #3
  br label %142

142:                                              ; preds = %141, %74
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #3
  %143 = load i32, ptr %18, align 4
  switch i32 %143, label %145 [
    i32 0, label %144
    i32 1, label %144
  ]

144:                                              ; preds = %142, %142
  ret void

145:                                              ; preds = %142
  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 uwtable
declare hidden void @RELAPACK_ztrtri_rec(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) #0

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 }

!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}
!12 = !{!13, !13, i64 0}
!13 = !{!"double", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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

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

16:                                               ; preds = %6
  %17 = icmp ne i32 %12, 0
  %18 = icmp ne i32 %13, 0
  %or.cond3 = select i1 %17, i1 true, i1 %18
  br i1 %or.cond3, 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 %26

.thread:                                          ; preds = %22, %19, %16, %6
  %.sink = phi i32 [ -1, %6 ], [ -2, %16 ], [ -3, %19 ], [ -5, %22 ]
  %.neg = phi i32 [ 1, %6 ], [ 2, %16 ], [ 3, %19 ], [ 5, %22 ]
  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
  %25 = call i32 @xerbla_(ptr noundef nonnull @.str.3, ptr noundef nonnull %7, i32 noundef 6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %7) #4
  br label %45

26:                                               ; preds = %22
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %8) #4
  %27 = select i1 %14, i8 76, i8 85
  store i8 %27, ptr %8, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %9) #4
  %.not44 = icmp eq i32 %12, 0
  %28 = select i1 %.not44, i8 85, i8 78
  store i8 %28, ptr %9, align 1, !tbaa !9
  %.not4548.not = icmp eq i32 %20, 0
  %or.cond53 = or i1 %.not44, %.not4548.not
  br i1 %or.cond53, label %.critedge, label %.lr.ph

.lr.ph:                                           ; preds = %26
  %29 = shl nuw i32 %23, 1
  %factor.op.mul = add i32 %29, 2
  %wide.trip.count = zext nneg i32 %20 to i64
  br label %30

30:                                               ; preds = %.lr.ph, %43
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %43 ]
  %31 = trunc nuw nsw i64 %indvars.iv to i32
  %.reass = mul i32 %factor.op.mul, %31
  %32 = sext i32 %.reass to i64
  %33 = getelementptr inbounds double, ptr %3, i64 %32
  %34 = load double, ptr %33, align 8, !tbaa !10
  %35 = fcmp oeq double %34, 0.000000e+00
  br i1 %35, label %36, label %43

36:                                               ; preds = %30
  %37 = or disjoint i32 %.reass, 1
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds double, ptr %3, i64 %38
  %40 = load double, ptr %39, align 8, !tbaa !10
  %41 = fcmp oeq double %40, 0.000000e+00
  br i1 %41, label %42, label %43

42:                                               ; preds = %36
  store i32 %31, ptr %5, align 4, !tbaa !5
  br label %44

43:                                               ; preds = %30, %36
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge, label %30, !llvm.loop !12

.critedge:                                        ; preds = %43, %26
  call void @RELAPACK_ztrtri_rec(ptr noundef nonnull %8, ptr noundef nonnull %9, ptr noundef nonnull %2, ptr noundef %3, ptr noundef nonnull %4, ptr noundef nonnull %5)
  br label %44

44:                                               ; preds = %42, %.critedge
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %9) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %8) #4
  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: nounwind uwtable
declare hidden void @RELAPACK_ztrtri_rec(ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.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"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"double", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass