; LLVM IR from hoytech/vmtouch :: vmtouch (parse_range)

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

@offset = external dso_local global i64, align 8
@max_len = external dso_local global i64, align 8
@pagesize = external dso_local global i64, align 8
@.str.33 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden void @fatal(ptr noundef, ...) #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @parse_size(ptr noundef) #0

; 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

; Function Attrs: nounwind uwtable
define dso_local void @parse_range(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  store i64 0, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store i64 0, ptr %5, align 8, !tbaa !9
  %6 = call ptr @strsep(ptr noundef %2, ptr noundef @.str.33) #3
  store ptr %6, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %2, align 8, !tbaa !5
  %8 = icmp eq ptr %7, null
  br i1 %8, label %9, label %12

9:                                                ; preds = %1
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = call i64 @parse_size(ptr noundef %10)
  store i64 %11, ptr %4, align 8, !tbaa !9
  br label %34

12:                                               ; preds = %1
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = load i8, ptr %13, align 1, !tbaa !11
  %15 = sext i8 %14 to i32
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %20

17:                                               ; preds = %12
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = call i64 @parse_size(ptr noundef %18)
  store i64 %19, ptr %5, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %17, %12
  %21 = call ptr @strsep(ptr noundef %2, ptr noundef @.str.33) #3
  store ptr %21, ptr %3, align 8, !tbaa !5
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = load i8, ptr %22, align 1, !tbaa !11
  %24 = sext i8 %23 to i32
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %20
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = call i64 @parse_size(ptr noundef %27)
  store i64 %28, ptr %4, align 8, !tbaa !9
  br label %29

29:                                               ; preds = %26, %20
  %30 = call ptr @strsep(ptr noundef %2, ptr noundef @.str.33) #3
  store ptr %30, ptr %3, align 8, !tbaa !5
  %31 = icmp ne ptr %30, null
  br i1 %31, label %32, label %33

32:                                               ; preds = %29
  call void (ptr, ...) @fatal(ptr noundef @.str.34)
  br label %33

33:                                               ; preds = %32, %29
  br label %34

34:                                               ; preds = %33, %9
  %35 = load i64, ptr %5, align 8, !tbaa !9
  %36 = load i64, ptr @pagesize, align 8, !tbaa !9
  %37 = sdiv i64 %35, %36
  %38 = load i64, ptr @pagesize, align 8, !tbaa !9
  %39 = mul nsw i64 %37, %38
  store i64 %39, ptr @offset, align 8, !tbaa !9
  %40 = load i64, ptr %4, align 8, !tbaa !9
  %41 = icmp ne i64 %40, 0
  br i1 %41, label %42, label %51

42:                                               ; preds = %34
  %43 = load i64, ptr %4, align 8, !tbaa !9
  %44 = load i64, ptr @offset, align 8, !tbaa !9
  %45 = icmp sle i64 %43, %44
  br i1 %45, label %46, label %47

46:                                               ; preds = %42
  call void (ptr, ...) @fatal(ptr noundef @.str.35)
  br label %47

47:                                               ; preds = %46, %42
  %48 = load i64, ptr %4, align 8, !tbaa !9
  %49 = load i64, ptr @offset, align 8, !tbaa !9
  %50 = sub nsw i64 %48, %49
  store i64 %50, ptr @max_len, align 8, !tbaa !9
  br label %51

51:                                               ; preds = %47, %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret void
}

; Function Attrs: nounwind
declare ptr @strsep(ptr noundef, ptr noundef) #2

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

!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}


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

@offset = external dso_local local_unnamed_addr global i64, align 8
@max_len = external dso_local local_unnamed_addr global i64, align 8
@pagesize = external dso_local local_unnamed_addr global i64, align 8
@.str.33 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.34 = external hidden unnamed_addr constant [34 x i8], align 1
@.str.35 = external hidden unnamed_addr constant [26 x i8], align 1

; Function Attrs: nounwind uwtable
declare hidden void @fatal(ptr noundef, ...) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local i64 @parse_size(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @parse_range(ptr noundef %0) local_unnamed_addr #0 {
  %2 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  %3 = call ptr @strsep(ptr noundef nonnull %2, ptr noundef nonnull @.str.33) #2
  %4 = load ptr, ptr %2, align 8, !tbaa !5
  %5 = icmp eq ptr %4, null
  br i1 %5, label %6, label %8

6:                                                ; preds = %1
  %7 = call i64 @parse_size(ptr noundef %3)
  br label %20

8:                                                ; preds = %1
  %9 = load i8, ptr %3, align 1, !tbaa !9
  %.not = icmp eq i8 %9, 0
  br i1 %.not, label %12, label %10

10:                                               ; preds = %8
  %11 = call i64 @parse_size(ptr noundef nonnull %3)
  br label %12

12:                                               ; preds = %10, %8
  %.0 = phi i64 [ %11, %10 ], [ 0, %8 ]
  %13 = call ptr @strsep(ptr noundef nonnull %2, ptr noundef nonnull @.str.33) #2
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %.not10 = icmp eq i8 %14, 0
  br i1 %.not10, label %17, label %15

15:                                               ; preds = %12
  %16 = call i64 @parse_size(ptr noundef nonnull %13)
  br label %17

17:                                               ; preds = %15, %12
  %.08 = phi i64 [ %16, %15 ], [ 0, %12 ]
  %18 = call ptr @strsep(ptr noundef nonnull %2, ptr noundef nonnull @.str.33) #2
  %.not11 = icmp eq ptr %18, null
  br i1 %.not11, label %20, label %19

19:                                               ; preds = %17
  call void (ptr, ...) @fatal(ptr noundef nonnull @.str.34)
  br label %20

20:                                               ; preds = %17, %19, %6
  %.19 = phi i64 [ %7, %6 ], [ %.08, %19 ], [ %.08, %17 ]
  %.1 = phi i64 [ 0, %6 ], [ %.0, %19 ], [ %.0, %17 ]
  %21 = load i64, ptr @pagesize, align 8, !tbaa !10
  %.1.fr = freeze i64 %.1
  %22 = srem i64 %.1.fr, %21
  %23 = sub nsw i64 %.1.fr, %22
  store i64 %23, ptr @offset, align 8, !tbaa !10
  %.not12 = icmp eq i64 %.19, 0
  br i1 %.not12, label %29, label %24

24:                                               ; preds = %20
  %.not13 = icmp sgt i64 %.19, %23
  br i1 %.not13, label %26, label %25

25:                                               ; preds = %24
  call void (ptr, ...) @fatal(ptr noundef nonnull @.str.35)
  %.pre = load i64, ptr @offset, align 8, !tbaa !10
  br label %26

26:                                               ; preds = %25, %24
  %27 = phi i64 [ %.pre, %25 ], [ %23, %24 ]
  %28 = sub nsw i64 %.19, %27
  store i64 %28, ptr @max_len, align 8, !tbaa !10
  br label %29

29:                                               ; preds = %26, %20
  ret void
}

; Function Attrs: nounwind
declare ptr @strsep(ptr noundef, ptr noundef) local_unnamed_addr #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 = { 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 #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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"long", !7, i64 0}


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