; LLVM IR from nickmqb/muon :: bootstrap/mu.ll_ulong (tryParse__)

; 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.string__ = type { ptr, i32 }
%struct.tag_____Maybe__ulong____ = type { i64, i8 }

@mu_____string0 = external dso_local global %struct.string__, align 8
@top_____abandonFn__ = external dso_local thread_local global ptr, align 8

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @string__equals__(ptr, i32, ptr, i32) #3

; Function Attrs: nounwind uwtable
declare dso_local { i64, i8 } @Maybe__from__ulong____(i64 noundef) #3

; Function Attrs: nounwind uwtable
define dso_local { i64, i8 } @ulong__tryParse__(ptr %0, i32 %1) #3 {
  %3 = alloca %struct.tag_____Maybe__ulong____, align 8
  %4 = alloca %struct.string__, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca i8, align 1
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = getelementptr inbounds { ptr, i32 }, ptr %4, i32 0, i32 0
  store ptr %0, ptr %14, align 8
  %15 = getelementptr inbounds { ptr, i32 }, ptr %4, i32 0, i32 1
  store i32 %1, ptr %15, align 8
  %16 = getelementptr inbounds { ptr, i32 }, ptr %4, i32 0, i32 0
  %17 = load ptr, ptr %16, align 8
  %18 = getelementptr inbounds { ptr, i32 }, ptr %4, i32 0, i32 1
  %19 = load i32, ptr %18, align 8
  %20 = load ptr, ptr @mu_____string0, align 8
  %21 = load i32, ptr getelementptr inbounds ({ ptr, i32 }, ptr @mu_____string0, i32 0, i32 1), align 8
  %22 = call zeroext i8 @string__equals__(ptr %17, i32 %19, ptr %20, i32 %21)
  %23 = icmp ne i8 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %2
  call void @llvm.memset.p0.i64(ptr align 8 %3, i8 0, i64 16, i1 false)
  br label %107

25:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #4
  store i64 0, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 1844674407370955161, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %95, %25
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = getelementptr inbounds %struct.string__, ptr %4, i32 0, i32 1
  %29 = load i32, ptr %28, align 8, !tbaa !11
  %30 = icmp slt i32 %27, %29
  br i1 %30, label %31, label %96

31:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store ptr %4, ptr %8, align 8, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %32 = load i32, ptr %7, align 4, !tbaa !9
  store i32 %32, ptr %9, align 4, !tbaa !9
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = load ptr, ptr %8, align 8, !tbaa !14
  %35 = getelementptr inbounds %struct.string__, ptr %34, i32 0, i32 1
  %36 = load i32, ptr %35, align 8, !tbaa !11
  %37 = icmp ult i32 %33, %36
  br i1 %37, label %41, label %38

38:                                               ; preds = %31
  %39 = call align 8 ptr @llvm.threadlocal.address.p0(ptr align 8 @top_____abandonFn__)
  %40 = load ptr, ptr %39, align 8, !tbaa !14
  call void %40(i32 noundef -3)
  br label %41

41:                                               ; preds = %38, %31
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  %42 = load ptr, ptr %8, align 8, !tbaa !14
  %43 = getelementptr inbounds %struct.string__, ptr %42, i32 0, i32 0
  %44 = load ptr, ptr %43, align 8, !tbaa !15
  %45 = load i32, ptr %9, align 4, !tbaa !9
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %44, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !16
  store i8 %48, ptr %10, align 1, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 1, ptr %11) #4
  %49 = load i8, ptr %10, align 1, !tbaa !16
  %50 = zext i8 %49 to i32
  %51 = icmp sge i32 %50, 48
  %52 = zext i1 %51 to i32
  %53 = trunc i32 %52 to i8
  store i8 %53, ptr %11, align 1, !tbaa !16
  %54 = load i8, ptr %11, align 1, !tbaa !16
  %55 = icmp ne i8 %54, 0
  br i1 %55, label %56, label %62

56:                                               ; preds = %41
  %57 = load i8, ptr %10, align 1, !tbaa !16
  %58 = zext i8 %57 to i32
  %59 = icmp sle i32 %58, 57
  %60 = zext i1 %59 to i32
  %61 = trunc i32 %60 to i8
  store i8 %61, ptr %11, align 1, !tbaa !16
  br label %62

62:                                               ; preds = %56, %41
  %63 = load i8, ptr %11, align 1, !tbaa !16
  %64 = icmp ne i8 %63, 0
  br i1 %64, label %66, label %65

65:                                               ; preds = %62
  call void @llvm.memset.p0.i64(ptr align 8 %3, i8 0, i64 16, i1 false)
  store i32 1, ptr %12, align 4
  br label %93

66:                                               ; preds = %62
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %67 = load i8, ptr %10, align 1, !tbaa !16
  %68 = sext i8 %67 to i32
  %69 = sub nsw i32 %68, 48
  store i32 %69, ptr %13, align 4, !tbaa !9
  %70 = load i64, ptr %5, align 8, !tbaa !5
  %71 = load i64, ptr %6, align 8, !tbaa !5
  %72 = icmp uge i64 %70, %71
  br i1 %72, label %73, label %84

73:                                               ; preds = %66
  %74 = load i32, ptr %13, align 4, !tbaa !9
  %75 = icmp sgt i32 %74, 5
  br i1 %75, label %76, label %77

76:                                               ; preds = %73
  call void @llvm.memset.p0.i64(ptr align 8 %3, i8 0, i64 16, i1 false)
  store i32 1, ptr %12, align 4
  br label %92

77:                                               ; preds = %73
  %78 = load i64, ptr %5, align 8, !tbaa !5
  %79 = load i64, ptr %6, align 8, !tbaa !5
  %80 = icmp ugt i64 %78, %79
  br i1 %80, label %81, label %82

81:                                               ; preds = %77
  call void @llvm.memset.p0.i64(ptr align 8 %3, i8 0, i64 16, i1 false)
  store i32 1, ptr %12, align 4
  br label %92

82:                                               ; preds = %77
  br label %83

83:                                               ; preds = %82
  br label %84

84:                                               ; preds = %83, %66
  %85 = load i64, ptr %5, align 8, !tbaa !5
  %86 = mul i64 %85, 10
  %87 = load i32, ptr %13, align 4, !tbaa !9
  %88 = sext i32 %87 to i64
  %89 = add i64 %86, %88
  store i64 %89, ptr %5, align 8, !tbaa !5
  %90 = load i32, ptr %7, align 4, !tbaa !9
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %7, align 4, !tbaa !9
  store i32 0, ptr %12, align 4
  br label %92

92:                                               ; preds = %84, %81, %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %93

93:                                               ; preds = %92, %65
  call void @llvm.lifetime.end.p0(i64 1, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %94 = load i32, ptr %12, align 4
  switch i32 %94, label %97 [
    i32 0, label %95
  ]

95:                                               ; preds = %93
  br label %26, !llvm.loop !17

96:                                               ; preds = %26
  store i32 0, ptr %12, align 4
  br label %97

97:                                               ; preds = %96, %93
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  %98 = load i32, ptr %12, align 4
  switch i32 %98, label %106 [
    i32 0, label %99
  ]

99:                                               ; preds = %97
  %100 = load i64, ptr %5, align 8, !tbaa !5
  %101 = call { i64, i8 } @Maybe__from__ulong____(i64 noundef %100)
  %102 = getelementptr inbounds { i64, i8 }, ptr %3, i32 0, i32 0
  %103 = extractvalue { i64, i8 } %101, 0
  store i64 %103, ptr %102, align 8
  %104 = getelementptr inbounds { i64, i8 }, ptr %3, i32 0, i32 1
  %105 = extractvalue { i64, i8 } %101, 1
  store i8 %105, ptr %104, align 8
  store i32 1, ptr %12, align 4
  br label %106

106:                                              ; preds = %99, %97
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  br label %107

107:                                              ; preds = %106, %24
  %108 = load { i64, i8 }, ptr %3, align 8
  ret { i64, i8 } %108
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 = !{!"long", !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, !10, i64 8}
!12 = !{!"", !13, i64 0, !10, i64 8}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!12, !13, i64 0}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"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"

%struct.string__ = type { ptr, i32 }

@mu_____string0 = external dso_local local_unnamed_addr global %struct.string__, align 8

; Function Attrs: nounwind uwtable
declare dso_local zeroext i8 @string__equals__(ptr, i32, ptr, i32) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local { i64, i8 } @Maybe__from__ulong____(i64 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local { i64, i8 } @ulong__tryParse__(ptr %0, i32 %1) local_unnamed_addr #0 {
  %3 = load ptr, ptr @mu_____string0, align 8
  %4 = load i32, ptr getelementptr inbounds (i8, ptr @mu_____string0, i64 8), align 8
  %5 = tail call zeroext i8 @string__equals__(ptr %0, i32 %1, ptr %3, i32 %4)
  %.not = icmp eq i8 %5, 0
  br i1 %.not, label %.preheader, label %.thread47

.preheader:                                       ; preds = %2
  %.not4249 = icmp sgt i32 %1, 0
  br i1 %.not4249, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %14
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %14 ]
  %.02951 = phi i64 [ 0, %.lr.ph.preheader ], [ %17, %14 ]
  %6 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = add i8 %7, -58
  %narrow = icmp ult i8 %8, -10
  br i1 %narrow, label %.thread47, label %9

9:                                                ; preds = %.lr.ph
  %10 = zext nneg i8 %7 to i64
  %11 = icmp ugt i64 %.02951, 1844674407370955160
  br i1 %11, label %12, label %14

12:                                               ; preds = %9
  %13 = icmp ult i8 %7, 54
  %.not41 = icmp eq i64 %.02951, 1844674407370955161
  %or.cond = select i1 %13, i1 %.not41, i1 false
  br i1 %or.cond, label %14, label %.thread47

14:                                               ; preds = %9, %12
  %15 = mul nuw i64 %.02951, 10
  %16 = add i64 %15, -48
  %17 = add i64 %16, %10
  %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 %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %14, %.preheader
  %.029.lcssa = phi i64 [ 0, %.preheader ], [ %17, %14 ]
  %18 = tail call { i64, i8 } @Maybe__from__ulong____(i64 noundef %.029.lcssa)
  %19 = extractvalue { i64, i8 } %18, 0
  %20 = extractvalue { i64, i8 } %18, 1
  br label %.thread47

.thread47:                                        ; preds = %.lr.ph, %12, %._crit_edge, %2
  %.sroa.6.5 = phi i8 [ 0, %2 ], [ %20, %._crit_edge ], [ 0, %12 ], [ 0, %.lr.ph ]
  %.sroa.0.5 = phi i64 [ 0, %2 ], [ %19, %._crit_edge ], [ 0, %12 ], [ 0, %.lr.ph ]
  %.fca.0.insert = insertvalue { i64, i8 } poison, i64 %.sroa.0.5, 0
  %.fca.1.insert = insertvalue { i64, i8 } %.fca.0.insert, i8 %.sroa.6.5, 1
  ret { i64, i8 } %.fca.1.insert
}

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


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