; LLVM IR from ponylang/ponyc :: src/libponyrt/lang (stdfd)

; 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 signext i8 @ansi_parse(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i32, align 4
  %13 = alloca i8, align 1
  %14 = alloca i8, align 1
  %15 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store ptr %4, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #2
  store i32 -1, ptr %12, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %13) #2
  store i8 -1, ptr %13, align 1, !tbaa !13
  %16 = load ptr, ptr %7, align 8, !tbaa !5
  %17 = load i64, ptr %16, align 8, !tbaa !9
  store i64 %17, ptr %11, align 8, !tbaa !9
  br label %18

18:                                               ; preds = %71, %5
  %19 = load i64, ptr %11, align 8, !tbaa !9
  %20 = load i64, ptr %8, align 8, !tbaa !9
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %22, label %74

22:                                               ; preds = %18
  call void @llvm.lifetime.start.p0(i64 1, ptr %14) #2
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = load i64, ptr %11, align 8, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %23, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !13
  store i8 %26, ptr %14, align 1, !tbaa !13
  %27 = load i8, ptr %14, align 1, !tbaa !13
  %28 = sext i8 %27 to i32
  %29 = icmp sge i32 %28, 48
  br i1 %29, label %30, label %53

30:                                               ; preds = %22
  %31 = load i8, ptr %14, align 1, !tbaa !13
  %32 = sext i8 %31 to i32
  %33 = icmp sle i32 %32, 57
  br i1 %33, label %34, label %53

34:                                               ; preds = %30
  %35 = load i32, ptr %12, align 4, !tbaa !11
  %36 = icmp slt i32 %35, 0
  br i1 %36, label %37, label %38

37:                                               ; preds = %34
  store i32 0, ptr %12, align 4, !tbaa !11
  br label %38

38:                                               ; preds = %37, %34
  %39 = load ptr, ptr %10, align 8, !tbaa !5
  %40 = load i32, ptr %12, align 4, !tbaa !11
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr %39, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !11
  %44 = mul nsw i32 %43, 10
  %45 = load i8, ptr %14, align 1, !tbaa !13
  %46 = sext i8 %45 to i32
  %47 = sub nsw i32 %46, 48
  %48 = add nsw i32 %44, %47
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = load i32, ptr %12, align 4, !tbaa !11
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr %49, i64 %51
  store i32 %48, ptr %52, align 4, !tbaa !11
  br label %67

53:                                               ; preds = %30, %22
  %54 = load i8, ptr %14, align 1, !tbaa !13
  %55 = sext i8 %54 to i32
  %56 = icmp eq i32 %55, 59
  br i1 %56, label %57, label %64

57:                                               ; preds = %53
  %58 = load i32, ptr %12, align 4, !tbaa !11
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %12, align 4, !tbaa !11
  %60 = load i32, ptr %12, align 4, !tbaa !11
  %61 = icmp sgt i32 %60, 5
  br i1 %61, label %62, label %63

62:                                               ; preds = %57
  store i32 2, ptr %15, align 4
  br label %68

63:                                               ; preds = %57
  br label %66

64:                                               ; preds = %53
  %65 = load i8, ptr %14, align 1, !tbaa !13
  store i8 %65, ptr %13, align 1, !tbaa !13
  store i32 2, ptr %15, align 4
  br label %68

66:                                               ; preds = %63
  br label %67

67:                                               ; preds = %66, %38
  store i32 0, ptr %15, align 4
  br label %68

68:                                               ; preds = %67, %64, %62
  call void @llvm.lifetime.end.p0(i64 1, ptr %14) #2
  %69 = load i32, ptr %15, align 4
  switch i32 %69, label %82 [
    i32 0, label %70
    i32 2, label %74
  ]

70:                                               ; preds = %68
  br label %71

71:                                               ; preds = %70
  %72 = load i64, ptr %11, align 8, !tbaa !9
  %73 = add i64 %72, 1
  store i64 %73, ptr %11, align 8, !tbaa !9
  br label %18, !llvm.loop !14

74:                                               ; preds = %68, %18
  %75 = load i64, ptr %11, align 8, !tbaa !9
  %76 = add i64 %75, 1
  %77 = load ptr, ptr %7, align 8, !tbaa !5
  store i64 %76, ptr %77, align 8, !tbaa !9
  %78 = load i32, ptr %12, align 4, !tbaa !11
  %79 = add nsw i32 %78, 1
  %80 = load ptr, ptr %9, align 8, !tbaa !5
  store i32 %79, ptr %80, align 4, !tbaa !11
  %81 = load i8, ptr %13, align 1, !tbaa !13
  store i32 1, ptr %15, align 4
  call void @llvm.lifetime.end.p0(i64 1, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #2
  ret i8 %81

82:                                               ; preds = %68
  unreachable
}

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


; 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: nofree norecurse nosync nounwind memory(argmem: readwrite) uwtable
define dso_local signext i8 @ansi_parse(ptr nocapture noundef readonly %0, ptr nocapture noundef %1, i64 noundef %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef %4) local_unnamed_addr #0 {
  %6 = load i64, ptr %1, align 8, !tbaa !5
  %7 = icmp ult i64 %6, %2
  br i1 %7, label %.lr.ph, label %select.unfold

.lr.ph:                                           ; preds = %5, %24
  %.02540 = phi i64 [ %25, %24 ], [ %6, %5 ]
  %.02739 = phi i32 [ %.229.ph, %24 ], [ -1, %5 ]
  %8 = getelementptr inbounds i8, ptr %0, i64 %.02540
  %9 = load i8, ptr %8, align 1, !tbaa !9
  %10 = add i8 %9, -48
  %or.cond = icmp ult i8 %10, 10
  br i1 %or.cond, label %11, label %19

11:                                               ; preds = %.lr.ph
  %12 = zext nneg i8 %9 to i32
  %spec.store.select = tail call i32 @llvm.smax.i32(i32 %.02739, i32 0)
  %13 = zext nneg i32 %spec.store.select to i64
  %14 = getelementptr inbounds i32, ptr %4, i64 %13
  %15 = load i32, ptr %14, align 4, !tbaa !10
  %16 = mul nsw i32 %15, 10
  %17 = add nsw i32 %12, -48
  %18 = add nsw i32 %17, %16
  store i32 %18, ptr %14, align 4, !tbaa !10
  br label %24

19:                                               ; preds = %.lr.ph
  %20 = icmp eq i8 %9, 59
  br i1 %20, label %21, label %select.unfold.loopexit

21:                                               ; preds = %19
  %22 = add nsw i32 %.02739, 1
  %23 = icmp sgt i32 %.02739, 4
  br i1 %23, label %select.unfold.loopexit, label %24

24:                                               ; preds = %11, %21
  %.229.ph = phi i32 [ %22, %21 ], [ %spec.store.select, %11 ]
  %25 = add i64 %.02540, 1
  %exitcond.not = icmp eq i64 %25, %2
  br i1 %exitcond.not, label %select.unfold.loopexit, label %.lr.ph, !llvm.loop !12

select.unfold.loopexit:                           ; preds = %21, %19, %24
  %.025.lcssa.ph = phi i64 [ %2, %24 ], [ %.02540, %19 ], [ %.02540, %21 ]
  %.3.ph = phi i32 [ %.229.ph, %24 ], [ %.02739, %19 ], [ %22, %21 ]
  %.2.ph = phi i8 [ -1, %24 ], [ %9, %19 ], [ -1, %21 ]
  %26 = add nsw i32 %.3.ph, 1
  br label %select.unfold

select.unfold:                                    ; preds = %select.unfold.loopexit, %5
  %.025.lcssa = phi i64 [ %6, %5 ], [ %.025.lcssa.ph, %select.unfold.loopexit ]
  %.3 = phi i32 [ 0, %5 ], [ %26, %select.unfold.loopexit ]
  %.2 = phi i8 [ -1, %5 ], [ %.2.ph, %select.unfold.loopexit ]
  %27 = add i64 %.025.lcssa, 1
  store i64 %27, ptr %1, align 8, !tbaa !5
  store i32 %.3, ptr %3, align 4, !tbaa !10
  ret i8 %.2
}

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

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


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