; LLVM IR from OpenMathLib/OpenBLAS :: lapack-netlib/SRC (izmax1)

; 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.doublecomplex = type { double, double }

; Function Attrs: nounwind uwtable
define dso_local i32 @izmax1_(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca double, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca { double, double }, align 8
  %15 = alloca { double, double }, align 8
  %16 = alloca { double, double }, align 8
  %17 = alloca { double, double }, align 8
  %18 = alloca { double, double }, align 8
  %19 = alloca { double, double }, align 8
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  %20 = load ptr, ptr %6, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.doublecomplex, ptr %20, i32 -1
  store ptr %21, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %8, align 4, !tbaa !9
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i32, ptr %22, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 1
  br i1 %24, label %29, label %25

25:                                               ; preds = %3
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i32, ptr %26, align 4, !tbaa !9
  %28 = icmp sle i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %25, %3
  %30 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %30, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %165

31:                                               ; preds = %25
  store i32 1, ptr %8, align 4, !tbaa !9
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = icmp eq i32 %33, 1
  br i1 %34, label %35, label %37

35:                                               ; preds = %31
  %36 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %36, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %165

37:                                               ; preds = %31
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = icmp eq i32 %39, 1
  br i1 %40, label %41, label %98

41:                                               ; preds = %37
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  %43 = getelementptr inbounds %struct.doublecomplex, ptr %42, i64 1
  %44 = call { double, double } @Cd(ptr noundef %43)
  %45 = extractvalue { double, double } %44, 0
  %46 = extractvalue { double, double } %44, 1
  %47 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %48 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  store double %45, ptr %47, align 8
  store double %46, ptr %48, align 8
  %49 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 0
  %50 = load double, ptr %49, align 8
  %51 = getelementptr inbounds { double, double }, ptr %14, i32 0, i32 1
  %52 = load double, ptr %51, align 8
  %53 = call double @cabs(double noundef %50, double noundef %52) #4
  store double %53, ptr %10, align 8, !tbaa !11
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load i32, ptr %54, align 4, !tbaa !9
  store i32 %55, ptr %9, align 4, !tbaa !9
  store i32 2, ptr %11, align 4, !tbaa !9
  br label %56

56:                                               ; preds = %94, %41
  %57 = load i32, ptr %11, align 4, !tbaa !9
  %58 = load i32, ptr %9, align 4, !tbaa !9
  %59 = icmp sle i32 %57, %58
  br i1 %59, label %60, label %97

60:                                               ; preds = %56
  %61 = load ptr, ptr %6, align 8, !tbaa !5
  %62 = load i32, ptr %11, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds %struct.doublecomplex, ptr %61, i64 %63
  %65 = call { double, double } @Cd(ptr noundef %64)
  %66 = extractvalue { double, double } %65, 0
  %67 = extractvalue { double, double } %65, 1
  %68 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 0
  %69 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 1
  store double %66, ptr %68, align 8
  store double %67, ptr %69, align 8
  %70 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 0
  %71 = load double, ptr %70, align 8
  %72 = getelementptr inbounds { double, double }, ptr %15, i32 0, i32 1
  %73 = load double, ptr %72, align 8
  %74 = call double @cabs(double noundef %71, double noundef %73) #4
  %75 = load double, ptr %10, align 8, !tbaa !11
  %76 = fcmp ogt double %74, %75
  br i1 %76, label %77, label %93

77:                                               ; preds = %60
  %78 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %78, ptr %8, align 4, !tbaa !9
  %79 = load ptr, ptr %6, align 8, !tbaa !5
  %80 = load i32, ptr %11, align 4, !tbaa !9
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds %struct.doublecomplex, ptr %79, i64 %81
  %83 = call { double, double } @Cd(ptr noundef %82)
  %84 = extractvalue { double, double } %83, 0
  %85 = extractvalue { double, double } %83, 1
  %86 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 0
  %87 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 1
  store double %84, ptr %86, align 8
  store double %85, ptr %87, align 8
  %88 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 0
  %89 = load double, ptr %88, align 8
  %90 = getelementptr inbounds { double, double }, ptr %16, i32 0, i32 1
  %91 = load double, ptr %90, align 8
  %92 = call double @cabs(double noundef %89, double noundef %91) #4
  store double %92, ptr %10, align 8, !tbaa !11
  br label %93

93:                                               ; preds = %77, %60
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %11, align 4, !tbaa !9
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %11, align 4, !tbaa !9
  br label %56, !llvm.loop !13

97:                                               ; preds = %56
  br label %163

98:                                               ; preds = %37
  store i32 1, ptr %12, align 4, !tbaa !9
  %99 = load ptr, ptr %6, align 8, !tbaa !5
  %100 = getelementptr inbounds %struct.doublecomplex, ptr %99, i64 1
  %101 = call { double, double } @Cd(ptr noundef %100)
  %102 = extractvalue { double, double } %101, 0
  %103 = extractvalue { double, double } %101, 1
  %104 = getelementptr inbounds { double, double }, ptr %17, i32 0, i32 0
  %105 = getelementptr inbounds { double, double }, ptr %17, i32 0, i32 1
  store double %102, ptr %104, align 8
  store double %103, ptr %105, align 8
  %106 = getelementptr inbounds { double, double }, ptr %17, i32 0, i32 0
  %107 = load double, ptr %106, align 8
  %108 = getelementptr inbounds { double, double }, ptr %17, i32 0, i32 1
  %109 = load double, ptr %108, align 8
  %110 = call double @cabs(double noundef %107, double noundef %109) #4
  store double %110, ptr %10, align 8, !tbaa !11
  %111 = load ptr, ptr %7, align 8, !tbaa !5
  %112 = load i32, ptr %111, align 4, !tbaa !9
  %113 = load i32, ptr %12, align 4, !tbaa !9
  %114 = add nsw i32 %113, %112
  store i32 %114, ptr %12, align 4, !tbaa !9
  %115 = load ptr, ptr %5, align 8, !tbaa !5
  %116 = load i32, ptr %115, align 4, !tbaa !9
  store i32 %116, ptr %9, align 4, !tbaa !9
  store i32 2, ptr %11, align 4, !tbaa !9
  br label %117

117:                                              ; preds = %159, %98
  %118 = load i32, ptr %11, align 4, !tbaa !9
  %119 = load i32, ptr %9, align 4, !tbaa !9
  %120 = icmp sle i32 %118, %119
  br i1 %120, label %121, label %162

121:                                              ; preds = %117
  %122 = load ptr, ptr %6, align 8, !tbaa !5
  %123 = load i32, ptr %12, align 4, !tbaa !9
  %124 = sext i32 %123 to i64
  %125 = getelementptr inbounds %struct.doublecomplex, ptr %122, i64 %124
  %126 = call { double, double } @Cd(ptr noundef %125)
  %127 = extractvalue { double, double } %126, 0
  %128 = extractvalue { double, double } %126, 1
  %129 = getelementptr inbounds { double, double }, ptr %18, i32 0, i32 0
  %130 = getelementptr inbounds { double, double }, ptr %18, i32 0, i32 1
  store double %127, ptr %129, align 8
  store double %128, ptr %130, align 8
  %131 = getelementptr inbounds { double, double }, ptr %18, i32 0, i32 0
  %132 = load double, ptr %131, align 8
  %133 = getelementptr inbounds { double, double }, ptr %18, i32 0, i32 1
  %134 = load double, ptr %133, align 8
  %135 = call double @cabs(double noundef %132, double noundef %134) #4
  %136 = load double, ptr %10, align 8, !tbaa !11
  %137 = fcmp ogt double %135, %136
  br i1 %137, label %138, label %154

138:                                              ; preds = %121
  %139 = load i32, ptr %11, align 4, !tbaa !9
  store i32 %139, ptr %8, align 4, !tbaa !9
  %140 = load ptr, ptr %6, align 8, !tbaa !5
  %141 = load i32, ptr %12, align 4, !tbaa !9
  %142 = sext i32 %141 to i64
  %143 = getelementptr inbounds %struct.doublecomplex, ptr %140, i64 %142
  %144 = call { double, double } @Cd(ptr noundef %143)
  %145 = extractvalue { double, double } %144, 0
  %146 = extractvalue { double, double } %144, 1
  %147 = getelementptr inbounds { double, double }, ptr %19, i32 0, i32 0
  %148 = getelementptr inbounds { double, double }, ptr %19, i32 0, i32 1
  store double %145, ptr %147, align 8
  store double %146, ptr %148, align 8
  %149 = getelementptr inbounds { double, double }, ptr %19, i32 0, i32 0
  %150 = load double, ptr %149, align 8
  %151 = getelementptr inbounds { double, double }, ptr %19, i32 0, i32 1
  %152 = load double, ptr %151, align 8
  %153 = call double @cabs(double noundef %150, double noundef %152) #4
  store double %153, ptr %10, align 8, !tbaa !11
  br label %154

154:                                              ; preds = %138, %121
  %155 = load ptr, ptr %7, align 8, !tbaa !5
  %156 = load i32, ptr %155, align 4, !tbaa !9
  %157 = load i32, ptr %12, align 4, !tbaa !9
  %158 = add nsw i32 %157, %156
  store i32 %158, ptr %12, align 4, !tbaa !9
  br label %159

159:                                              ; preds = %154
  %160 = load i32, ptr %11, align 4, !tbaa !9
  %161 = add nsw i32 %160, 1
  store i32 %161, ptr %11, align 4, !tbaa !9
  br label %117, !llvm.loop !15

162:                                              ; preds = %117
  br label %163

163:                                              ; preds = %162, %97
  %164 = load i32, ptr %8, align 4, !tbaa !9
  store i32 %164, ptr %4, align 4
  store i32 1, ptr %13, align 4
  br label %165

165:                                              ; preds = %163, %35, %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  %166 = load i32, ptr %4, align 4
  ret i32 %166
}

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

; Function Attrs: nounwind
declare double @cabs(double noundef, double noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden { double, double } @Cd(ptr noundef) #3

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

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


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

%struct.doublecomplex = type { double, double }

; Function Attrs: nounwind uwtable
define dso_local i32 @izmax1_(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %1, i64 -16
  %5 = load i32, ptr %0, align 4, !tbaa !5
  %6 = icmp slt i32 %5, 1
  br i1 %6, label %.loopexit, label %7

7:                                                ; preds = %3
  %8 = load i32, ptr %2, align 4, !tbaa !5
  %9 = icmp slt i32 %8, 1
  br i1 %9, label %.loopexit, label %10

10:                                               ; preds = %7
  %11 = icmp eq i32 %5, 1
  br i1 %11, label %.loopexit, label %12

12:                                               ; preds = %10
  %13 = icmp eq i32 %8, 1
  %14 = tail call { double, double } @Cd(ptr noundef %1)
  %15 = extractvalue { double, double } %14, 0
  %16 = extractvalue { double, double } %14, 1
  %17 = tail call double @cabs(double noundef %15, double noundef %16) #3
  %18 = load i32, ptr %0, align 4, !tbaa !5
  %.not5461 = icmp slt i32 %18, 2
  br i1 %13, label %19, label %34

19:                                               ; preds = %12
  br i1 %.not5461, label %.loopexit, label %.lr.ph65.preheader

.lr.ph65.preheader:                               ; preds = %19
  %20 = add nuw i32 %18, 1
  %wide.trip.count = zext i32 %20 to i64
  br label %.lr.ph65

.lr.ph65:                                         ; preds = %.lr.ph65.preheader, %33
  %indvars.iv = phi i64 [ 2, %.lr.ph65.preheader ], [ %indvars.iv.next, %33 ]
  %.04464 = phi i32 [ 1, %.lr.ph65.preheader ], [ %.1, %33 ]
  %.04563 = phi double [ %17, %.lr.ph65.preheader ], [ %.146, %33 ]
  %21 = getelementptr inbounds %struct.doublecomplex, ptr %4, i64 %indvars.iv
  %22 = tail call { double, double } @Cd(ptr noundef nonnull %21)
  %23 = extractvalue { double, double } %22, 0
  %24 = extractvalue { double, double } %22, 1
  %25 = tail call double @cabs(double noundef %23, double noundef %24) #3
  %26 = fcmp ogt double %25, %.04563
  br i1 %26, label %27, label %33

27:                                               ; preds = %.lr.ph65
  %28 = tail call { double, double } @Cd(ptr noundef nonnull %21)
  %29 = extractvalue { double, double } %28, 0
  %30 = extractvalue { double, double } %28, 1
  %31 = tail call double @cabs(double noundef %29, double noundef %30) #3
  %32 = trunc nuw nsw i64 %indvars.iv to i32
  br label %33

33:                                               ; preds = %.lr.ph65, %27
  %.146 = phi double [ %31, %27 ], [ %.04563, %.lr.ph65 ]
  %.1 = phi i32 [ %32, %27 ], [ %.04464, %.lr.ph65 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond69.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond69.not, label %.loopexit, label %.lr.ph65, !llvm.loop !9

34:                                               ; preds = %12
  br i1 %.not5461, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %34
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %49
  %.260 = phi i32 [ %.3, %49 ], [ 1, %.lr.ph.preheader ]
  %.24759 = phi double [ %.348, %49 ], [ %17, %.lr.ph.preheader ]
  %.15058 = phi i32 [ %52, %49 ], [ 2, %.lr.ph.preheader ]
  %.05157 = phi i32 [ %51, %49 ], [ %36, %.lr.ph.preheader ]
  %37 = sext i32 %.05157 to i64
  %38 = getelementptr inbounds %struct.doublecomplex, ptr %4, i64 %37
  %39 = tail call { double, double } @Cd(ptr noundef nonnull %38)
  %40 = extractvalue { double, double } %39, 0
  %41 = extractvalue { double, double } %39, 1
  %42 = tail call double @cabs(double noundef %40, double noundef %41) #3
  %43 = fcmp ogt double %42, %.24759
  br i1 %43, label %44, label %49

44:                                               ; preds = %.lr.ph
  %45 = tail call { double, double } @Cd(ptr noundef nonnull %38)
  %46 = extractvalue { double, double } %45, 0
  %47 = extractvalue { double, double } %45, 1
  %48 = tail call double @cabs(double noundef %46, double noundef %47) #3
  br label %49

49:                                               ; preds = %44, %.lr.ph
  %.348 = phi double [ %48, %44 ], [ %.24759, %.lr.ph ]
  %.3 = phi i32 [ %.15058, %44 ], [ %.260, %.lr.ph ]
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = add nsw i32 %50, %.05157
  %52 = add nuw i32 %.15058, 1
  %exitcond.not = icmp eq i32 %.15058, %18
  br i1 %exitcond.not, label %.loopexit, label %.lr.ph, !llvm.loop !11

.loopexit:                                        ; preds = %49, %33, %34, %19, %10, %3, %7
  %.0 = phi i32 [ 0, %7 ], [ 0, %3 ], [ 1, %10 ], [ 1, %19 ], [ 1, %34 ], [ %.1, %33 ], [ %.3, %49 ]
  ret i32 %.0
}

; Function Attrs: nofree nounwind
declare double @cabs(double noundef, double noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden { double, double } @Cd(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 = { nofree 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 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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