; LLVM IR from h2o/h2o :: deps/mruby/src (readint)

; 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 i64 @mrb_int_read(ptr noundef %0, ptr noundef %1, ptr noundef %2) #0 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  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 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  br label %11

11:                                               ; preds = %45, %3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = icmp eq ptr %12, null
  br i1 %13, label %18, label %14

14:                                               ; preds = %11
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = icmp ult ptr %15, %16
  br i1 %17, label %18, label %24

18:                                               ; preds = %14, %11
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !11
  %21 = sext i8 %20 to i32
  %22 = sub i32 %21, 48
  %23 = icmp ult i32 %22, 10
  br label %24

24:                                               ; preds = %18, %14
  %25 = phi i1 [ false, %14 ], [ %23, %18 ]
  br i1 %25, label %26, label %48

26:                                               ; preds = %24
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = load i8, ptr %27, align 1, !tbaa !11
  %29 = sext i8 %28 to i32
  %30 = sub nsw i32 %29, 48
  store i32 %30, ptr %9, align 4, !tbaa !12
  %31 = load i64, ptr %8, align 8, !tbaa !9
  %32 = call zeroext i1 @mrb_int_mul_overflow(i64 noundef %31, i64 noundef 10, ptr noundef %8)
  br i1 %32, label %38, label %33

33:                                               ; preds = %26
  %34 = load i64, ptr %8, align 8, !tbaa !9
  %35 = load i32, ptr %9, align 4, !tbaa !12
  %36 = sext i32 %35 to i64
  %37 = call zeroext i1 @mrb_int_add_overflow(i64 noundef %34, i64 noundef %36, ptr noundef %8)
  br i1 %37, label %38, label %45

38:                                               ; preds = %33, %26
  %39 = load ptr, ptr %7, align 8, !tbaa !5
  %40 = icmp ne ptr %39, null
  br i1 %40, label %41, label %43

41:                                               ; preds = %38
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr null, ptr %42, align 8, !tbaa !5
  br label %43

43:                                               ; preds = %41, %38
  %44 = call ptr @__errno_location() #5
  store i32 34, ptr %44, align 4, !tbaa !12
  store i64 9223372036854775807, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %56

45:                                               ; preds = %33
  %46 = load ptr, ptr %5, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr %5, align 8, !tbaa !5
  br label %11, !llvm.loop !14

48:                                               ; preds = %24
  %49 = load ptr, ptr %7, align 8, !tbaa !5
  %50 = icmp ne ptr %49, null
  br i1 %50, label %51, label %54

51:                                               ; preds = %48
  %52 = load ptr, ptr %5, align 8, !tbaa !5
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  store ptr %52, ptr %53, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %51, %48
  %55 = load i64, ptr %8, align 8, !tbaa !9
  store i64 %55, ptr %4, align 8
  store i32 1, ptr %10, align 4
  br label %56

56:                                               ; preds = %54, %43
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %57 = load i64, ptr %4, align 8
  ret i64 %57
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @mrb_int_mul_overflow(i64 noundef, i64 noundef, ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @mrb_int_add_overflow(i64 noundef, i64 noundef, ptr noundef) #2

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #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 = { 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 willreturn memory(none) "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 }
attributes #5 = { nounwind 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 = !{!"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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !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: nounwind uwtable
define dso_local i64 @mrb_int_read(ptr noundef %0, ptr noundef readnone %1, ptr noundef writeonly %2) local_unnamed_addr #0 {
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #4
  store i64 0, ptr %4, align 8, !tbaa !5
  %5 = icmp eq ptr %1, null
  %6 = icmp ult ptr %0, %1
  %or.cond18 = or i1 %5, %6
  br i1 %or.cond18, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %3
  br i1 %5, label %.lr.ph.split.us, label %.lr.ph.split

.lr.ph.split.us:                                  ; preds = %.lr.ph
  %7 = load i8, ptr %0, align 1, !tbaa !9
  %8 = sext i8 %7 to i32
  %9 = add nsw i32 %8, -48
  %10 = icmp ult i32 %9, 10
  br i1 %10, label %.lr.ph23, label %.critedge

.lr.ph23:                                         ; preds = %.lr.ph.split.us, %18
  %11 = phi i32 [ %22, %18 ], [ %9, %.lr.ph.split.us ]
  %.01219.us22 = phi ptr [ %19, %18 ], [ %0, %.lr.ph.split.us ]
  %12 = load i64, ptr %4, align 8, !tbaa !5
  %13 = call zeroext i1 @mrb_int_mul_overflow(i64 noundef %12, i64 noundef 10, ptr noundef nonnull %4)
  br i1 %13, label %.split.us, label %14

14:                                               ; preds = %.lr.ph23
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = zext nneg i32 %11 to i64
  %17 = call zeroext i1 @mrb_int_add_overflow(i64 noundef %15, i64 noundef %16, ptr noundef nonnull %4)
  br i1 %17, label %.split.us, label %18

18:                                               ; preds = %14
  %19 = getelementptr inbounds i8, ptr %.01219.us22, i64 1
  %20 = load i8, ptr %19, align 1, !tbaa !9
  %21 = sext i8 %20 to i32
  %22 = add nsw i32 %21, -48
  %23 = icmp ult i32 %22, 10
  br i1 %23, label %.lr.ph23, label %.critedge

.lr.ph.split:                                     ; preds = %.lr.ph, %38
  %.01219 = phi ptr [ %39, %38 ], [ %0, %.lr.ph ]
  %24 = load i8, ptr %.01219, align 1, !tbaa !9
  %25 = sext i8 %24 to i32
  %26 = add nsw i32 %25, -48
  %27 = icmp ult i32 %26, 10
  br i1 %27, label %28, label %.critedge

28:                                               ; preds = %.lr.ph.split
  %29 = load i64, ptr %4, align 8, !tbaa !5
  %30 = call zeroext i1 @mrb_int_mul_overflow(i64 noundef %29, i64 noundef 10, ptr noundef nonnull %4)
  br i1 %30, label %.split.us, label %31

31:                                               ; preds = %28
  %32 = load i64, ptr %4, align 8, !tbaa !5
  %33 = zext nneg i32 %26 to i64
  %34 = call zeroext i1 @mrb_int_add_overflow(i64 noundef %32, i64 noundef %33, ptr noundef nonnull %4)
  br i1 %34, label %.split.us, label %38

.split.us:                                        ; preds = %28, %31, %.lr.ph23, %14
  %.not16 = icmp eq ptr %2, null
  br i1 %.not16, label %36, label %35

35:                                               ; preds = %.split.us
  store ptr null, ptr %2, align 8, !tbaa !10
  br label %36

36:                                               ; preds = %35, %.split.us
  %37 = tail call ptr @__errno_location() #5
  store i32 34, ptr %37, align 4, !tbaa !12
  br label %44

38:                                               ; preds = %31
  %39 = getelementptr inbounds i8, ptr %.01219, i64 1
  %40 = icmp ult ptr %39, %1
  br i1 %40, label %.lr.ph.split, label %.critedge, !llvm.loop !14

.critedge:                                        ; preds = %.lr.ph.split, %38, %18, %.lr.ph.split.us, %3
  %.012.lcssa = phi ptr [ %0, %3 ], [ %0, %.lr.ph.split.us ], [ %19, %18 ], [ %39, %38 ], [ %.01219, %.lr.ph.split ]
  %.not = icmp eq ptr %2, null
  br i1 %.not, label %42, label %41

41:                                               ; preds = %.critedge
  store ptr %.012.lcssa, ptr %2, align 8, !tbaa !10
  br label %42

42:                                               ; preds = %41, %.critedge
  %43 = load i64, ptr %4, align 8, !tbaa !5
  br label %44

44:                                               ; preds = %42, %36
  %.0 = phi i64 [ 9223372036854775807, %36 ], [ %43, %42 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #4
  ret i64 %.0
}

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @mrb_int_mul_overflow(i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i1 @mrb_int_add_overflow(i64 noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #3

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 }
attributes #5 = { nounwind 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 = !{!"any pointer", !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


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