; LLVM IR from Montimage/mmt-security :: src/lib/expression.ll (parse_a_number)

; 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: 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 willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

declare ptr @mmt_mem_alloc(i64 noundef) #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @mmt_mem_free(ptr noundef) #2

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() #3

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

; Function Attrs: nounwind uwtable
define dso_local i64 @_parse_a_number(ptr noundef %0, ptr noundef %1, i64 noundef %2) #4 {
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i8, align 1
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store i64 %2, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  store i64 0, ptr %8, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  store i64 0, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #6
  store i8 0, ptr %10, align 1, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #6
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr null, ptr %14, align 8, !tbaa !5
  %15 = load ptr, ptr %6, align 8, !tbaa !5
  %16 = icmp eq ptr %15, null
  br i1 %16, label %20, label %17

17:                                               ; preds = %3
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %20, label %21

20:                                               ; preds = %17, %3
  store i64 0, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %108

21:                                               ; preds = %17
  %22 = load ptr, ptr %6, align 8, !tbaa !5
  %23 = load i64, ptr %7, align 8, !tbaa !9
  %24 = call i64 @_jump_space(ptr noundef %22, i64 noundef %23)
  store i64 %24, ptr %9, align 8, !tbaa !9
  %25 = load i64, ptr %9, align 8, !tbaa !9
  %26 = load i64, ptr %7, align 8, !tbaa !9
  %27 = icmp eq i64 %25, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %21
  %29 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %29, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %108

30:                                               ; preds = %21
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = load i64, ptr %9, align 8, !tbaa !9
  %33 = getelementptr inbounds i8, ptr %31, i64 %32
  store ptr %33, ptr %11, align 8, !tbaa !5
  %34 = call ptr @__ctype_b_loc() #7
  %35 = load ptr, ptr %34, align 8, !tbaa !5
  %36 = load ptr, ptr %11, align 8, !tbaa !5
  %37 = load i8, ptr %36, align 1, !tbaa !13
  %38 = sext i8 %37 to i32
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i16, ptr %35, i64 %39
  %41 = load i16, ptr %40, align 2, !tbaa !14
  %42 = zext i16 %41 to i32
  %43 = and i32 %42, 2048
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %47, label %45

45:                                               ; preds = %30
  %46 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %46, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %108

47:                                               ; preds = %30
  br label %48

48:                                               ; preds = %90, %47
  %49 = call ptr @__ctype_b_loc() #7
  %50 = load ptr, ptr %49, align 8, !tbaa !5
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = load i64, ptr %8, align 8, !tbaa !9
  %53 = getelementptr inbounds i8, ptr %51, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !13
  %55 = sext i8 %54 to i32
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds i16, ptr %50, i64 %56
  %58 = load i16, ptr %57, align 2, !tbaa !14
  %59 = zext i16 %58 to i32
  %60 = and i32 %59, 2048
  %61 = icmp ne i32 %60, 0
  br i1 %61, label %69, label %62

62:                                               ; preds = %48
  %63 = load ptr, ptr %11, align 8, !tbaa !5
  %64 = load i64, ptr %8, align 8, !tbaa !9
  %65 = getelementptr inbounds i8, ptr %63, i64 %64
  %66 = load i8, ptr %65, align 1, !tbaa !13
  %67 = sext i8 %66 to i32
  %68 = icmp eq i32 %67, 46
  br i1 %68, label %69, label %73

69:                                               ; preds = %62, %48
  %70 = load i64, ptr %9, align 8, !tbaa !9
  %71 = load i64, ptr %7, align 8, !tbaa !9
  %72 = icmp ult i64 %70, %71
  br label %73

73:                                               ; preds = %69, %62
  %74 = phi i1 [ false, %62 ], [ %72, %69 ]
  br i1 %74, label %75, label %95

75:                                               ; preds = %73
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = load i64, ptr %8, align 8, !tbaa !9
  %78 = getelementptr inbounds i8, ptr %76, i64 %77
  %79 = load i8, ptr %78, align 1, !tbaa !13
  %80 = sext i8 %79 to i32
  %81 = icmp eq i32 %80, 46
  br i1 %81, label %82, label %90

82:                                               ; preds = %75
  %83 = load i8, ptr %10, align 1, !tbaa !11, !range !16, !noundef !17
  %84 = trunc i8 %83 to i1
  %85 = zext i1 %84 to i32
  %86 = icmp eq i32 %85, 1
  br i1 %86, label %87, label %88

87:                                               ; preds = %82
  br label %95

88:                                               ; preds = %82
  store i8 1, ptr %10, align 1, !tbaa !11
  br label %89

89:                                               ; preds = %88
  br label %90

90:                                               ; preds = %89, %75
  %91 = load i64, ptr %8, align 8, !tbaa !9
  %92 = add i64 %91, 1
  store i64 %92, ptr %8, align 8, !tbaa !9
  %93 = load i64, ptr %9, align 8, !tbaa !9
  %94 = add i64 %93, 1
  store i64 %94, ptr %9, align 8, !tbaa !9
  br label %48, !llvm.loop !18

95:                                               ; preds = %87, %73
  %96 = load ptr, ptr %11, align 8, !tbaa !5
  %97 = load i64, ptr %8, align 8, !tbaa !9
  %98 = call ptr @mmt_mem_dup(ptr noundef %96, i64 noundef %97)
  store ptr %98, ptr %12, align 8, !tbaa !5
  %99 = call ptr @mmt_mem_alloc(i64 noundef 8)
  %100 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %99, ptr %100, align 8, !tbaa !5
  %101 = load ptr, ptr %12, align 8, !tbaa !5
  %102 = call double @atof(ptr noundef %101) #8
  %103 = load ptr, ptr %5, align 8, !tbaa !5
  %104 = load ptr, ptr %103, align 8, !tbaa !5
  store double %102, ptr %104, align 8, !tbaa !20
  %105 = load ptr, ptr %12, align 8, !tbaa !5
  %106 = call i64 @mmt_mem_free(ptr noundef %105)
  %107 = load i64, ptr %9, align 8, !tbaa !9
  store i64 %107, ptr %4, align 8
  store i32 1, ptr %13, align 4
  br label %108

108:                                              ; preds = %95, %45, %28, %20
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  %109 = load i64, ptr %4, align 8
  ret i64 %109
}

; Function Attrs: inlinehint nounwind willreturn memory(read) uwtable
declare double @atof(ptr noundef nonnull) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { "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 #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 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 #5 = { inlinehint nounwind willreturn memory(read) 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 #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(none) }
attributes #8 = { nounwind willreturn memory(read) }

!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 = !{!"_Bool", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"short", !7, i64 0}
!16 = !{i8 0, i8 2}
!17 = !{}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!21, !21, i64 0}
!21 = !{!"double", !7, i64 0}


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

declare ptr @mmt_mem_alloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @mmt_mem_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: inlinehint nounwind uwtable
declare hidden i64 @_jump_space(ptr noundef, i64 noundef) local_unnamed_addr #1

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

; Function Attrs: inlinehint nounwind uwtable
declare hidden ptr @mmt_mem_dup(ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i64 @_parse_a_number(ptr nocapture noundef writeonly %0, ptr noundef %1, i64 noundef %2) local_unnamed_addr #3 {
  store ptr null, ptr %0, align 8, !tbaa !5
  %4 = icmp eq ptr %1, null
  %5 = icmp eq i64 %2, 0
  %or.cond = or i1 %4, %5
  br i1 %or.cond, label %37, label %6

6:                                                ; preds = %3
  %7 = tail call i64 @_jump_space(ptr noundef nonnull %1, i64 noundef %2)
  %8 = icmp eq i64 %7, %2
  br i1 %8, label %37, label %9

9:                                                ; preds = %6
  %10 = getelementptr inbounds i8, ptr %1, i64 %7
  %11 = tail call ptr @__ctype_b_loc() #5
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %13 = load i8, ptr %10, align 1, !tbaa !9
  %14 = sext i8 %13 to i64
  %15 = getelementptr inbounds i16, ptr %12, i64 %14
  %16 = load i16, ptr %15, align 2, !tbaa !10
  %17 = and i16 %16, 2048
  %.not = icmp eq i16 %17, 0
  br i1 %.not, label %37, label %.preheader

.preheader:                                       ; preds = %9
  %18 = icmp ult i64 %7, %2
  br i1 %18, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %.preheader
  %19 = icmp eq i8 %13, 46
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %22
  %20 = phi i1 [ %31, %22 ], [ %19, %.lr.ph.preheader ]
  %.03147 = phi i64 [ %23, %22 ], [ 0, %.lr.ph.preheader ]
  %.03246 = phi i1 [ %.032.mux, %22 ], [ false, %.lr.ph.preheader ]
  %.03345 = phi i64 [ %24, %22 ], [ %7, %.lr.ph.preheader ]
  %21 = select i1 %20, i1 %.03246, i1 false
  br i1 %21, label %.critedge, label %22

22:                                               ; preds = %.lr.ph
  %.032.mux = select i1 %20, i1 true, i1 %.03246
  %23 = add i64 %.03147, 1
  %24 = add nuw i64 %.03345, 1
  %25 = getelementptr inbounds i8, ptr %10, i64 %23
  %26 = load i8, ptr %25, align 1, !tbaa !9
  %27 = sext i8 %26 to i64
  %28 = getelementptr inbounds i16, ptr %12, i64 %27
  %29 = load i16, ptr %28, align 2, !tbaa !10
  %30 = and i16 %29, 2048
  %.not38 = icmp ne i16 %30, 0
  %31 = icmp eq i8 %26, 46
  %or.cond39 = or i1 %31, %.not38
  %32 = icmp ult i64 %24, %2
  %or.cond40 = select i1 %or.cond39, i1 %32, i1 false
  br i1 %or.cond40, label %.lr.ph, label %.critedge, !llvm.loop !12

.critedge:                                        ; preds = %22, %.lr.ph, %.preheader
  %.033.lcssa = phi i64 [ %7, %.preheader ], [ %.03345, %.lr.ph ], [ %24, %22 ]
  %.031.lcssa = phi i64 [ 0, %.preheader ], [ %.03147, %.lr.ph ], [ %23, %22 ]
  %33 = tail call ptr @mmt_mem_dup(ptr noundef nonnull %10, i64 noundef %.031.lcssa)
  %34 = tail call ptr @mmt_mem_alloc(i64 noundef 8) #6
  store ptr %34, ptr %0, align 8, !tbaa !5
  %35 = tail call double @atof(ptr noundef %33) #7
  store double %35, ptr %34, align 8, !tbaa !14
  %36 = tail call i64 @mmt_mem_free(ptr noundef nonnull %33)
  br label %37

37:                                               ; preds = %9, %6, %3, %.critedge
  %.0 = phi i64 [ %.033.lcssa, %.critedge ], [ 0, %3 ], [ %2, %6 ], [ %7, %9 ]
  ret i64 %.0
}

; Function Attrs: inlinehint mustprogress nofree nounwind willreturn memory(read) uwtable
declare double @atof(ptr nocapture noundef nonnull) local_unnamed_addr #4

attributes #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 = { 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 #2 = { 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 #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 = { inlinehint mustprogress nofree nounwind willreturn memory(read) 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 #5 = { nounwind willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { nounwind willreturn memory(read) }

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


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