; LLVM IR from niuyishuai/PDCABB :: LAPACK_BLAS/LIBF2C/libf2c (getarg_)

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

@xargc = external global i32, align 4
@xargv = external global ptr, align 8
@.str = external hidden unnamed_addr constant [1 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @getarg_(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = load i64, ptr %9, align 8, !tbaa !9
  %11 = icmp sge i64 %10, 0
  br i1 %11, label %12, label %24

12:                                               ; preds = %3
  %13 = load ptr, ptr %4, align 8, !tbaa !5
  %14 = load i64, ptr %13, align 8, !tbaa !9
  %15 = load i32, ptr @xargc, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = icmp slt i64 %14, %16
  br i1 %17, label %18, label %24

18:                                               ; preds = %12
  %19 = load ptr, ptr @xargv, align 8, !tbaa !5
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i64, ptr %20, align 8, !tbaa !9
  %22 = getelementptr inbounds ptr, ptr %19, i64 %21
  %23 = load ptr, ptr %22, align 8, !tbaa !5
  store ptr %23, ptr %7, align 8, !tbaa !5
  br label %25

24:                                               ; preds = %12, %3
  store ptr @.str, ptr %7, align 8, !tbaa !5
  br label %25

25:                                               ; preds = %24, %18
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %26

26:                                               ; preds = %44, %25
  %27 = load i32, ptr %8, align 4, !tbaa !11
  %28 = sext i32 %27 to i64
  %29 = load i64, ptr %6, align 8, !tbaa !9
  %30 = icmp slt i64 %28, %29
  br i1 %30, label %31, label %36

31:                                               ; preds = %26
  %32 = load ptr, ptr %7, align 8, !tbaa !5
  %33 = load i8, ptr %32, align 1, !tbaa !13
  %34 = sext i8 %33 to i32
  %35 = icmp ne i32 %34, 0
  br label %36

36:                                               ; preds = %31, %26
  %37 = phi i1 [ false, %26 ], [ %35, %31 ]
  br i1 %37, label %38, label %47

38:                                               ; preds = %36
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = getelementptr inbounds i8, ptr %39, i32 1
  store ptr %40, ptr %7, align 8, !tbaa !5
  %41 = load i8, ptr %39, align 1, !tbaa !13
  %42 = load ptr, ptr %5, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i32 1
  store ptr %43, ptr %5, align 8, !tbaa !5
  store i8 %41, ptr %42, align 1, !tbaa !13
  br label %44

44:                                               ; preds = %38
  %45 = load i32, ptr %8, align 4, !tbaa !11
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr %8, align 4, !tbaa !11
  br label %26, !llvm.loop !14

47:                                               ; preds = %36
  br label %48

48:                                               ; preds = %56, %47
  %49 = load i32, ptr %8, align 4, !tbaa !11
  %50 = sext i32 %49 to i64
  %51 = load i64, ptr %6, align 8, !tbaa !9
  %52 = icmp slt i64 %50, %51
  br i1 %52, label %53, label %59

53:                                               ; preds = %48
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds i8, ptr %54, i32 1
  store ptr %55, ptr %5, align 8, !tbaa !5
  store i8 32, ptr %54, align 1, !tbaa !13
  br label %56

56:                                               ; preds = %53
  %57 = load i32, ptr %8, align 4, !tbaa !11
  %58 = add nsw i32 %57, 1
  store i32 %58, ptr %8, align 4, !tbaa !11
  br label %48, !llvm.loop !16

59:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret void
}

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

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

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


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

@xargc = external local_unnamed_addr global i32, align 4
@xargv = external local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [1 x i8], align 1

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) uwtable
define dso_local void @getarg_(ptr nocapture noundef readonly %0, ptr nocapture noundef writeonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = load i64, ptr %0, align 8, !tbaa !5
  %5 = icmp sgt i64 %4, -1
  %6 = load i32, ptr @xargc, align 4
  %7 = sext i32 %6 to i64
  %8 = icmp slt i64 %4, %7
  %or.cond = select i1 %5, i1 %8, i1 false
  br i1 %or.cond, label %9, label %13

9:                                                ; preds = %3
  %10 = load ptr, ptr @xargv, align 8, !tbaa !9
  %11 = getelementptr inbounds ptr, ptr %10, i64 %4
  %12 = load ptr, ptr %11, align 8, !tbaa !9
  br label %13

13:                                               ; preds = %3, %9
  %.012 = phi ptr [ %12, %9 ], [ @.str, %3 ]
  %14 = icmp sgt i64 %2, 0
  br i1 %14, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %13, %16
  %indvars.iv = phi i64 [ %indvars.iv.next, %16 ], [ 0, %13 ]
  %.11320 = phi ptr [ %17, %16 ], [ %.012, %13 ]
  %.01419 = phi ptr [ %18, %16 ], [ %1, %13 ]
  %15 = load i8, ptr %.11320, align 1, !tbaa !11
  %.not = icmp eq i8 %15, 0
  br i1 %.not, label %.critedge.loopexit, label %16

16:                                               ; preds = %.lr.ph
  %17 = getelementptr inbounds i8, ptr %.11320, i64 1
  %18 = getelementptr inbounds i8, ptr %.01419, i64 1
  store i8 %15, ptr %.01419, align 1, !tbaa !11
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %2
  br i1 %exitcond.not, label %.critedge.loopexit, label %.lr.ph, !llvm.loop !12

.critedge.loopexit:                               ; preds = %16, %.lr.ph
  %.014.lcssa.ph = phi ptr [ %.01419, %.lr.ph ], [ %18, %16 ]
  %.0.lcssa.ph.in = phi i64 [ %indvars.iv, %.lr.ph ], [ %2, %16 ]
  %.0.lcssa.ph = trunc i64 %.0.lcssa.ph.in to i32
  br label %.critedge

.critedge:                                        ; preds = %.critedge.loopexit, %13
  %.014.lcssa = phi ptr [ %1, %13 ], [ %.014.lcssa.ph, %.critedge.loopexit ]
  %.0.lcssa = phi i32 [ 0, %13 ], [ %.0.lcssa.ph, %.critedge.loopexit ]
  %19 = zext nneg i32 %.0.lcssa to i64
  %20 = icmp slt i64 %19, %2
  br i1 %20, label %.lr.ph28.preheader, label %._crit_edge

.lr.ph28.preheader:                               ; preds = %.critedge
  %21 = add i32 %.0.lcssa, 1
  %22 = zext i32 %21 to i64
  %23 = tail call i64 @llvm.umax.i64(i64 %2, i64 %22)
  %24 = add nuw i64 %23, 1
  %25 = sub i64 %24, %22
  tail call void @llvm.memset.p0.i64(ptr align 1 %.014.lcssa, i8 32, i64 %25, i1 false), !tbaa !11
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph28.preheader, %.critedge
  ret void
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #1

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

attributes #0 = { nofree norecurse nosync nounwind memory(readwrite, inaccessiblemem: none) 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 nounwind willreturn memory(argmem: write) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass