; LLVM IR from facebook/hermes :: external/llvh/lib/Support (regexec)

; 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.llvm_regex = type { i32, i64, ptr, ptr }
%struct.re_guts = type { i32, ptr, i32, i32, ptr, ptr, i32, i64, i64, i64, i32, i32, i32, i32, ptr, ptr, i32, i64, i32, i64, [1 x i8] }

; Function Attrs: nounwind uwtable
define dso_local i32 @llvh_regexec(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i32 noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #2
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.llvm_regex, ptr %14, i32 0, i32 3
  %16 = load ptr, ptr %15, align 8, !tbaa !13
  store ptr %16, ptr %12, align 8, !tbaa !5
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.llvm_regex, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !15
  %20 = icmp ne i32 %19, 62053
  br i1 %20, label %26, label %21

21:                                               ; preds = %5
  %22 = load ptr, ptr %12, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.re_guts, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %23, align 8, !tbaa !16
  %25 = icmp ne i32 %24, 53829
  br i1 %25, label %26, label %27

26:                                               ; preds = %21, %5
  store i32 2, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %59

27:                                               ; preds = %21
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.re_guts, ptr %28, i32 0, i32 10
  %30 = load i32, ptr %29, align 8, !tbaa !18
  %31 = and i32 %30, 4
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %27
  store i32 2, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %59

34:                                               ; preds = %27
  %35 = load i32, ptr %11, align 4, !tbaa !11
  %36 = and i32 %35, 7
  store i32 %36, ptr %11, align 4, !tbaa !11
  %37 = load ptr, ptr %12, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.re_guts, ptr %37, i32 0, i32 7
  %39 = load i64, ptr %38, align 8, !tbaa !19
  %40 = icmp sle i64 %39, 64
  br i1 %40, label %41, label %52

41:                                               ; preds = %34
  %42 = load i32, ptr %11, align 4, !tbaa !11
  %43 = and i32 %42, 512
  %44 = icmp ne i32 %43, 0
  br i1 %44, label %52, label %45

45:                                               ; preds = %41
  %46 = load ptr, ptr %12, align 8, !tbaa !5
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i64, ptr %9, align 8, !tbaa !9
  %49 = load ptr, ptr %10, align 8, !tbaa !5
  %50 = load i32, ptr %11, align 4, !tbaa !11
  %51 = call i32 @smatcher(ptr noundef %46, ptr noundef %47, i64 noundef %48, ptr noundef %49, i32 noundef %50)
  store i32 %51, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %59

52:                                               ; preds = %41, %34
  %53 = load ptr, ptr %12, align 8, !tbaa !5
  %54 = load ptr, ptr %8, align 8, !tbaa !5
  %55 = load i64, ptr %9, align 8, !tbaa !9
  %56 = load ptr, ptr %10, align 8, !tbaa !5
  %57 = load i32, ptr %11, align 4, !tbaa !11
  %58 = call i32 @lmatcher(ptr noundef %53, ptr noundef %54, i64 noundef %55, ptr noundef %56, i32 noundef %57)
  store i32 %58, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %59

59:                                               ; preds = %52, %45, %33, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #2
  %60 = load i32, ptr %6, align 4
  ret i32 %60
}

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

; Function Attrs: nounwind uwtable
declare hidden i32 @smatcher(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @lmatcher(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i32 noundef) #0

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

!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 = !{!"int", !7, i64 0}
!13 = !{!14, !6, i64 24}
!14 = !{!"llvm_regex", !12, i64 0, !10, i64 8, !6, i64 16, !6, i64 24}
!15 = !{!14, !12, i64 0}
!16 = !{!17, !12, i64 0}
!17 = !{!"re_guts", !12, i64 0, !6, i64 8, !12, i64 16, !12, i64 20, !6, i64 24, !6, i64 32, !12, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !12, i64 72, !12, i64 76, !12, i64 80, !12, i64 84, !6, i64 88, !6, i64 96, !12, i64 104, !10, i64 112, !12, i64 120, !10, i64 128, !7, i64 136}
!18 = !{!17, !12, i64 72}
!19 = !{!17, !10, i64 48}


; 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 i32 @llvh_regexec(ptr nocapture noundef readonly %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = getelementptr inbounds i8, ptr %0, i64 24
  %7 = load ptr, ptr %6, align 8, !tbaa !5
  %8 = load i32, ptr %0, align 8, !tbaa !12
  %.not = icmp eq i32 %8, 62053
  br i1 %.not, label %9, label %24

9:                                                ; preds = %5
  %10 = load i32, ptr %7, align 8, !tbaa !13
  %.not17 = icmp eq i32 %10, 53829
  br i1 %.not17, label %11, label %24

11:                                               ; preds = %9
  %12 = getelementptr inbounds i8, ptr %7, i64 72
  %13 = load i32, ptr %12, align 8, !tbaa !15
  %14 = and i32 %13, 4
  %.not18 = icmp eq i32 %14, 0
  br i1 %.not18, label %15, label %24

15:                                               ; preds = %11
  %16 = and i32 %4, 7
  %17 = getelementptr inbounds i8, ptr %7, i64 48
  %18 = load i64, ptr %17, align 8, !tbaa !16
  %19 = icmp slt i64 %18, 65
  br i1 %19, label %20, label %22

20:                                               ; preds = %15
  %21 = tail call i32 @smatcher(ptr noundef nonnull %7, ptr noundef %1, i64 noundef %2, ptr noundef %3, i32 noundef %16)
  br label %24

22:                                               ; preds = %15
  %23 = tail call i32 @lmatcher(ptr noundef nonnull %7, ptr noundef %1, i64 noundef %2, ptr noundef %3, i32 noundef %16)
  br label %24

24:                                               ; preds = %11, %5, %9, %22, %20
  %.0 = phi i32 [ %23, %22 ], [ %21, %20 ], [ 2, %9 ], [ 2, %5 ], [ 2, %11 ]
  ret i32 %.0
}

; Function Attrs: nounwind uwtable
declare hidden i32 @smatcher(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @lmatcher(ptr noundef, ptr noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

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

!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, !11, i64 24}
!6 = !{!"llvm_regex", !7, i64 0, !10, i64 8, !11, i64 16, !11, i64 24}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"long", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !7, i64 0}
!13 = !{!14, !7, i64 0}
!14 = !{!"re_guts", !7, i64 0, !11, i64 8, !7, i64 16, !7, i64 20, !11, i64 24, !11, i64 32, !7, i64 40, !10, i64 48, !10, i64 56, !10, i64 64, !7, i64 72, !7, i64 76, !7, i64 80, !7, i64 84, !11, i64 88, !11, i64 96, !7, i64 104, !10, i64 112, !7, i64 120, !10, i64 128, !8, i64 136}
!15 = !{!14, !7, i64 72}
!16 = !{!14, !10, i64 48}


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