; LLVM IR from Morpho-lang/morpho :: src/support/format.ll (format_parse)

; 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.fformat = type { i32, i32, i8 }

; Function Attrs: nounwind uwtable
define dso_local zeroext i1 @_format_parse(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3) #0 {
  %5 = alloca i1, align 1
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store ptr %2, ptr %8, align 8, !tbaa !5
  store ptr %3, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %9, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.fformat, ptr %12, i32 0, i32 0
  store i32 -1, ptr %13, align 4, !tbaa !9
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.fformat, ptr %14, i32 0, i32 1
  store i32 -1, ptr %15, align 4, !tbaa !12
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.fformat, ptr %16, i32 0, i32 2
  store i8 32, ptr %17, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  store ptr %18, ptr %10, align 8, !tbaa !5
  %19 = load ptr, ptr %10, align 8, !tbaa !5
  %20 = load i8, ptr %19, align 1, !tbaa !14
  %21 = sext i8 %20 to i32
  %22 = icmp eq i32 %21, 37
  br i1 %22, label %23, label %26

23:                                               ; preds = %4
  %24 = load ptr, ptr %10, align 8, !tbaa !5
  %25 = getelementptr inbounds i8, ptr %24, i32 1
  store ptr %25, ptr %10, align 8, !tbaa !5
  br label %27

26:                                               ; preds = %4
  store i1 false, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %93

27:                                               ; preds = %23
  %28 = call ptr @__ctype_b_loc() #6
  %29 = load ptr, ptr %28, align 8, !tbaa !5
  %30 = load ptr, ptr %10, align 8, !tbaa !5
  %31 = load i8, ptr %30, align 1, !tbaa !14
  %32 = sext i8 %31 to i32
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds i16, ptr %29, i64 %33
  %35 = load i16, ptr %34, align 2, !tbaa !15
  %36 = zext i16 %35 to i32
  %37 = and i32 %36, 2048
  %38 = icmp ne i32 %37, 0
  br i1 %38, label %39, label %45

39:                                               ; preds = %27
  %40 = load ptr, ptr %10, align 8, !tbaa !5
  %41 = call i64 @strtol(ptr noundef %40, ptr noundef %10, i32 noundef 10) #5
  %42 = trunc i64 %41 to i32
  %43 = load ptr, ptr %9, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.fformat, ptr %43, i32 0, i32 0
  store i32 %42, ptr %44, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %39, %27
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = load i8, ptr %46, align 1, !tbaa !14
  %48 = sext i8 %47 to i32
  %49 = icmp eq i32 %48, 46
  br i1 %49, label %50, label %72

50:                                               ; preds = %45
  %51 = load ptr, ptr %10, align 8, !tbaa !5
  %52 = getelementptr inbounds i8, ptr %51, i32 1
  store ptr %52, ptr %10, align 8, !tbaa !5
  %53 = call ptr @__ctype_b_loc() #6
  %54 = load ptr, ptr %53, align 8, !tbaa !5
  %55 = load ptr, ptr %10, align 8, !tbaa !5
  %56 = load i8, ptr %55, align 1, !tbaa !14
  %57 = sext i8 %56 to i32
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i16, ptr %54, i64 %58
  %60 = load i16, ptr %59, align 2, !tbaa !15
  %61 = zext i16 %60 to i32
  %62 = and i32 %61, 2048
  %63 = icmp ne i32 %62, 0
  br i1 %63, label %64, label %70

64:                                               ; preds = %50
  %65 = load ptr, ptr %10, align 8, !tbaa !5
  %66 = call i64 @strtol(ptr noundef %65, ptr noundef %10, i32 noundef 10) #5
  %67 = trunc i64 %66 to i32
  %68 = load ptr, ptr %9, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.fformat, ptr %68, i32 0, i32 1
  store i32 %67, ptr %69, align 4, !tbaa !12
  br label %71

70:                                               ; preds = %50
  store i1 false, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %93

71:                                               ; preds = %64
  br label %72

72:                                               ; preds = %71, %45
  %73 = load ptr, ptr %7, align 8, !tbaa !5
  %74 = load ptr, ptr %10, align 8, !tbaa !5
  %75 = load i8, ptr %74, align 1, !tbaa !14
  %76 = sext i8 %75 to i32
  %77 = call ptr @strchr(ptr noundef %73, i32 noundef %76) #7
  %78 = icmp ne ptr %77, null
  br i1 %78, label %80, label %79

79:                                               ; preds = %72
  store i1 false, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %93

80:                                               ; preds = %72
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = load i8, ptr %81, align 1, !tbaa !14
  %83 = load ptr, ptr %9, align 8, !tbaa !5
  %84 = getelementptr inbounds %struct.fformat, ptr %83, i32 0, i32 2
  store i8 %82, ptr %84, align 4, !tbaa !13
  %85 = load ptr, ptr %10, align 8, !tbaa !5
  %86 = getelementptr inbounds i8, ptr %85, i32 1
  store ptr %86, ptr %10, align 8, !tbaa !5
  %87 = load ptr, ptr %8, align 8, !tbaa !5
  %88 = icmp ne ptr %87, null
  br i1 %88, label %89, label %92

89:                                               ; preds = %80
  %90 = load ptr, ptr %10, align 8, !tbaa !5
  %91 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %90, ptr %91, align 8, !tbaa !5
  br label %92

92:                                               ; preds = %89, %80
  store i1 true, ptr %5, align 1
  store i32 1, ptr %11, align 4
  br label %93

93:                                               ; preds = %92, %79, %70, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %94 = load i1, ptr %5, align 1
  ret i1 %94
}

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

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

; Function Attrs: nounwind
declare i64 @strtol(ptr noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare ptr @strchr(ptr noundef, i32 noundef) #4

; 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 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 "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 willreturn memory(read) "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 }
attributes #6 = { nounwind willreturn memory(none) }
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 = !{!10, !11, i64 0}
!10 = !{!"fformat", !11, i64 0, !11, i64 4, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 4}
!13 = !{!10, !7, i64 8}
!14 = !{!7, !7, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !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"

; Function Attrs: mustprogress nofree nounwind willreturn uwtable
define dso_local noundef zeroext i1 @_format_parse(ptr noundef %0, ptr noundef readonly %1, ptr noundef writeonly %2, ptr nocapture noundef writeonly %3) local_unnamed_addr #0 {
  %5 = alloca ptr, align 8
  store i32 -1, ptr %3, align 4, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 -1, ptr %6, align 4, !tbaa !10
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  store i8 32, ptr %7, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  %8 = load i8, ptr %0, align 1, !tbaa !12
  %9 = icmp eq i8 %8, 37
  br i1 %9, label %10, label %45

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

19:                                               ; preds = %10
  %20 = call i64 @strtol(ptr noundef nonnull %11, ptr noundef nonnull %5, i32 noundef 10) #5
  %21 = trunc i64 %20 to i32
  store i32 %21, ptr %3, align 4, !tbaa !5
  %.pre = load ptr, ptr %5, align 8, !tbaa !13
  %.pre15 = load i8, ptr %.pre, align 1, !tbaa !12
  br label %22

22:                                               ; preds = %19, %10
  %23 = phi i8 [ %.pre15, %19 ], [ %14, %10 ]
  %24 = phi ptr [ %.pre, %19 ], [ %11, %10 ]
  %25 = icmp eq i8 %23, 46
  br i1 %25, label %26, label %37

26:                                               ; preds = %22
  %27 = getelementptr inbounds i8, ptr %24, i64 1
  store ptr %27, ptr %5, align 8, !tbaa !13
  %28 = load ptr, ptr %12, align 8, !tbaa !13
  %29 = load i8, ptr %27, align 1, !tbaa !12
  %30 = sext i8 %29 to i64
  %31 = getelementptr inbounds i16, ptr %28, i64 %30
  %32 = load i16, ptr %31, align 2, !tbaa !15
  %33 = and i16 %32, 2048
  %.not12 = icmp eq i16 %33, 0
  br i1 %.not12, label %45, label %34

34:                                               ; preds = %26
  %35 = call i64 @strtol(ptr noundef nonnull %27, ptr noundef nonnull %5, i32 noundef 10) #5
  %36 = trunc i64 %35 to i32
  store i32 %36, ptr %6, align 4, !tbaa !10
  %.pre16 = load ptr, ptr %5, align 8, !tbaa !13
  %.pre17 = load i8, ptr %.pre16, align 1, !tbaa !12
  br label %37

37:                                               ; preds = %34, %22
  %38 = phi i8 [ %.pre17, %34 ], [ %23, %22 ]
  %39 = phi ptr [ %.pre16, %34 ], [ %24, %22 ]
  %40 = sext i8 %38 to i32
  %41 = tail call ptr @strchr(ptr noundef nonnull dereferenceable(1) %1, i32 noundef %40) #7
  %.not13 = icmp eq ptr %41, null
  br i1 %.not13, label %45, label %42

42:                                               ; preds = %37
  store i8 %38, ptr %7, align 4, !tbaa !11
  %.not14 = icmp eq ptr %2, null
  br i1 %.not14, label %45, label %43

43:                                               ; preds = %42
  %44 = getelementptr inbounds i8, ptr %39, i64 1
  store ptr %44, ptr %2, align 8, !tbaa !13
  br label %45

45:                                               ; preds = %42, %43, %37, %26, %4
  %.0 = phi i1 [ false, %4 ], [ false, %26 ], [ false, %37 ], [ true, %43 ], [ true, %42 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  ret i1 %.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: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__ctype_b_loc() local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn
declare i64 @strtol(ptr noundef readonly, ptr nocapture noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare ptr @strchr(ptr noundef, i32 noundef) local_unnamed_addr #4

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

attributes #0 = { mustprogress nofree nounwind willreturn 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 = { 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 = { mustprogress nofree nounwind willreturn "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 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 }
attributes #6 = { nounwind willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"fformat", !7, i64 0, !7, i64 4, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !8, i64 8}
!12 = !{!8, !8, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!16, !16, i64 0}
!16 = !{!"short", !8, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass