; LLVM IR from interpretml/interpret :: shared/libebm/unzoned (unzoned)

; 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

; Function Attrs: mustprogress nounwind uwtable
define dso_local i32 @CheckForIllegalCharacters(ptr noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i8, align 1
  %5 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp ne ptr null, %6
  br i1 %7, label %8, label %53

8:                                                ; preds = %1
  br label %9

9:                                                ; preds = %51, %8
  call void @llvm.lifetime.start.p0(i64 1, ptr %4) #2
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = load i8, ptr %10, align 1, !tbaa !9
  store i8 %11, ptr %4, align 1, !tbaa !9
  %12 = load i8, ptr %4, align 1, !tbaa !9
  %13 = sext i8 %12 to i32
  %14 = icmp eq i32 0, %13
  br i1 %14, label %15, label %16

15:                                               ; preds = %9
  store i32 0, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %49

16:                                               ; preds = %9
  %17 = load i8, ptr %4, align 1, !tbaa !9
  %18 = sext i8 %17 to i32
  %19 = icmp eq i32 32, %18
  br i1 %19, label %28, label %20

20:                                               ; preds = %16
  %21 = load i8, ptr %4, align 1, !tbaa !9
  %22 = sext i8 %21 to i32
  %23 = icmp sle i32 9, %22
  br i1 %23, label %24, label %29

24:                                               ; preds = %20
  %25 = load i8, ptr %4, align 1, !tbaa !9
  %26 = sext i8 %25 to i32
  %27 = icmp sle i32 %26, 13
  br i1 %27, label %28, label %29

28:                                               ; preds = %24, %16
  store i32 3, ptr %5, align 4
  br label %49

29:                                               ; preds = %24, %20
  %30 = load i8, ptr %4, align 1, !tbaa !9
  %31 = sext i8 %30 to i32
  %32 = icmp eq i32 44, %31
  br i1 %32, label %45, label %33

33:                                               ; preds = %29
  %34 = load i8, ptr %4, align 1, !tbaa !9
  %35 = sext i8 %34 to i32
  %36 = icmp eq i32 59, %35
  br i1 %36, label %45, label %37

37:                                               ; preds = %33
  %38 = load i8, ptr %4, align 1, !tbaa !9
  %39 = sext i8 %38 to i32
  %40 = icmp eq i32 61, %39
  br i1 %40, label %45, label %41

41:                                               ; preds = %37
  %42 = load i8, ptr %4, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  %44 = icmp eq i32 58, %43
  br i1 %44, label %45, label %46

45:                                               ; preds = %41, %37, %33, %29
  store i32 3, ptr %5, align 4
  br label %49

46:                                               ; preds = %41
  %47 = load ptr, ptr %3, align 8, !tbaa !5
  %48 = getelementptr inbounds i8, ptr %47, i32 1
  store ptr %48, ptr %3, align 8, !tbaa !5
  store i32 0, ptr %5, align 4
  br label %49

49:                                               ; preds = %46, %45, %28, %15
  call void @llvm.lifetime.end.p0(i64 1, ptr %4) #2
  %50 = load i32, ptr %5, align 4
  switch i32 %50, label %56 [
    i32 0, label %51
    i32 1, label %54
    i32 3, label %52
  ]

51:                                               ; preds = %49
  br label %9, !llvm.loop !10

52:                                               ; preds = %49
  br label %53

53:                                               ; preds = %52, %1
  store i32 1, ptr %2, align 4
  br label %54

54:                                               ; preds = %53, %49
  %55 = load i32, ptr %2, align 4
  ret i32 %55

56:                                               ; preds = %49
  unreachable
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { 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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"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: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i32 @CheckForIllegalCharacters(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not = icmp eq ptr %0, null
  br i1 %.not, label %.thread30, label %.preheader

.preheader:                                       ; preds = %1, %6
  %.024 = phi ptr [ %7, %6 ], [ %0, %1 ]
  %2 = load i8, ptr %.024, align 1, !tbaa !5
  switch i8 %2, label %3 [
    i8 0, label %.thread30.loopexit
    i8 32, label %.thread30
  ]

3:                                                ; preds = %.preheader
  %4 = add i8 %2, -9
  %or.cond = icmp ult i8 %4, 5
  br i1 %or.cond, label %.thread30, label %5

5:                                                ; preds = %3
  switch i8 %2, label %6 [
    i8 61, label %.thread30
    i8 59, label %.thread30
    i8 58, label %.thread30
    i8 44, label %.thread30
  ]

6:                                                ; preds = %5
  %7 = getelementptr inbounds i8, ptr %.024, i64 1
  br label %.preheader

.thread30.loopexit:                               ; preds = %.preheader
  br label %.thread30

.thread30:                                        ; preds = %3, %.preheader, %5, %5, %5, %5, %.thread30.loopexit, %1
  %.2 = phi i32 [ 1, %1 ], [ 0, %.thread30.loopexit ], [ 1, %5 ], [ 1, %5 ], [ 1, %5 ], [ 1, %5 ], [ 1, %.preheader ], [ 1, %3 ]
  ret i32 %.2
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) 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++ TBAA"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass