; LLVM IR from kaynewbie/algorithm :: algorithm/CodingInterviews (question-20)

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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @isNumeric(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #2
  %4 = call zeroext i1 @scanInteger(ptr noundef %2)
  %5 = zext i1 %4 to i8
  store i8 %5, ptr %3, align 1, !tbaa !9
  %6 = load ptr, ptr %2, align 8, !tbaa !5
  %7 = load i8, ptr %6, align 1, !tbaa !11
  %8 = sext i8 %7 to i32
  %9 = icmp eq i32 %8, 46
  br i1 %9, label %10, label %20

10:                                               ; preds = %1
  %11 = load ptr, ptr %2, align 8, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %11, i32 1
  store ptr %12, ptr %2, align 8, !tbaa !5
  %13 = call zeroext i1 @scanUnsignInteger(ptr noundef %2)
  br i1 %13, label %17, label %14

14:                                               ; preds = %10
  %15 = load i8, ptr %3, align 1, !tbaa !9, !range !12, !noundef !13
  %16 = trunc i8 %15 to i1
  br label %17

17:                                               ; preds = %14, %10
  %18 = phi i1 [ true, %10 ], [ %16, %14 ]
  %19 = zext i1 %18 to i8
  store i8 %19, ptr %3, align 1, !tbaa !9
  br label %20

20:                                               ; preds = %17, %1
  %21 = load ptr, ptr %2, align 8, !tbaa !5
  %22 = load i8, ptr %21, align 1, !tbaa !11
  %23 = sext i8 %22 to i32
  %24 = icmp eq i32 %23, 101
  br i1 %24, label %30, label %25

25:                                               ; preds = %20
  %26 = load ptr, ptr %2, align 8, !tbaa !5
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = sext i8 %27 to i32
  %29 = icmp eq i32 %28, 69
  br i1 %29, label %30, label %40

30:                                               ; preds = %25, %20
  %31 = load ptr, ptr %2, align 8, !tbaa !5
  %32 = getelementptr inbounds i8, ptr %31, i32 1
  store ptr %32, ptr %2, align 8, !tbaa !5
  %33 = load i8, ptr %3, align 1, !tbaa !9, !range !12, !noundef !13
  %34 = trunc i8 %33 to i1
  br i1 %34, label %35, label %37

35:                                               ; preds = %30
  %36 = call zeroext i1 @scanInteger(ptr noundef %2)
  br label %37

37:                                               ; preds = %35, %30
  %38 = phi i1 [ false, %30 ], [ %36, %35 ]
  %39 = zext i1 %38 to i8
  store i8 %39, ptr %3, align 1, !tbaa !9
  br label %40

40:                                               ; preds = %37, %25
  %41 = load i8, ptr %3, align 1, !tbaa !9, !range !12, !noundef !13
  %42 = trunc i8 %41 to i1
  br i1 %42, label %43, label %48

43:                                               ; preds = %40
  %44 = load ptr, ptr %2, align 8, !tbaa !5
  %45 = load i8, ptr %44, align 1, !tbaa !11
  %46 = sext i8 %45 to i32
  %47 = icmp eq i32 %46, 0
  br label %48

48:                                               ; preds = %43, %40
  %49 = phi i1 [ false, %40 ], [ %47, %43 ]
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #2
  ret i1 %49
}

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @scanInteger(ptr noundef) #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @scanUnsignInteger(ptr noundef) #0

; 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 = !{!"_Bool", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{i8 0, i8 2}
!13 = !{}


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

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @isNumeric(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = call zeroext i1 @scanInteger(ptr noundef nonnull %2)
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = load i8, ptr %4, align 1, !tbaa !9
  %6 = icmp eq i8 %5, 46
  br i1 %6, label %7, label %11

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %4, i64 1
  store ptr %8, ptr %2, align 8, !tbaa !5
  %9 = call zeroext i1 @scanUnsignInteger(ptr noundef nonnull %2)
  %10 = select i1 %9, i1 true, i1 %3
  %.pre = load ptr, ptr %2, align 8, !tbaa !5
  %.pre4 = load i8, ptr %.pre, align 1, !tbaa !9
  br label %11

11:                                               ; preds = %7, %1
  %12 = phi i8 [ %.pre4, %7 ], [ %5, %1 ]
  %13 = phi ptr [ %.pre, %7 ], [ %4, %1 ]
  %.0.in = phi i1 [ %10, %7 ], [ %3, %1 ]
  switch i8 %12, label %18 [
    i8 101, label %14
    i8 69, label %14
  ]

14:                                               ; preds = %11, %11
  %15 = getelementptr inbounds i8, ptr %13, i64 1
  store ptr %15, ptr %2, align 8, !tbaa !5
  br i1 %.0.in, label %16, label %.critedge

16:                                               ; preds = %14
  %17 = call zeroext i1 @scanInteger(ptr noundef nonnull %2)
  br i1 %17, label %._crit_edge, label %.critedge

._crit_edge:                                      ; preds = %16
  %.pre5 = load ptr, ptr %2, align 8, !tbaa !5
  %.pre6 = load i8, ptr %.pre5, align 1, !tbaa !9
  br label %19

18:                                               ; preds = %11
  br i1 %.0.in, label %19, label %.critedge

19:                                               ; preds = %._crit_edge, %18
  %20 = phi i8 [ %.pre6, %._crit_edge ], [ %12, %18 ]
  %21 = icmp eq i8 %20, 0
  br label %.critedge

.critedge:                                        ; preds = %16, %14, %19, %18
  %22 = phi i1 [ false, %18 ], [ %21, %19 ], [ false, %14 ], [ false, %16 ]
  ret i1 %22
}

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @scanInteger(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local zeroext i1 @scanUnsignInteger(ptr noundef) local_unnamed_addr #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" }

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


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,SROAPass,SimplifyCFGPass