; LLVM IR from 0intro/wmii :: lib/libregexp (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.Reljunk = type { [2 x ptr], [2 x ptr], i32, i32, ptr, ptr, ptr, ptr }
%struct.Relist = type { ptr, %struct.Resublist }
%struct.Resublist = type { [32 x %struct.Resub] }
%struct.Resub = type { %union.anon, %union.anon.0 }
%union.anon = type { ptr }
%union.anon.0 = type { ptr }
%struct.Reprog = type { ptr, [32 x %struct.Reclass], [5 x %struct.Reinst] }
%struct.Reclass = type { ptr, [64 x i32] }
%struct.Reinst = type { i32, %union.anon.1, %union.anon.2 }
%union.anon.1 = type { ptr }
%union.anon.2 = type { ptr }

; Function Attrs: nounwind uwtable
define dso_local i32 @regexec9(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca %struct.Reljunk, align 8
  %11 = alloca [10 x %struct.Relist], align 16
  %12 = alloca [10 x %struct.Relist], align 16
  %13 = alloca i32, align 4
  %14 = 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 i32 %3, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 72, ptr %10) #2
  call void @llvm.lifetime.start.p0(i64 5200, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 5200, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %15 = load ptr, ptr %7, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.Reljunk, ptr %10, i32 0, i32 4
  store ptr %15, ptr %16, align 8, !tbaa !11
  %17 = getelementptr inbounds %struct.Reljunk, ptr %10, i32 0, i32 5
  store ptr null, ptr %17, align 8, !tbaa !13
  %18 = load ptr, ptr %8, align 8, !tbaa !5
  %19 = icmp ne ptr %18, null
  br i1 %19, label %20, label %44

20:                                               ; preds = %4
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp sgt i32 %21, 0
  br i1 %22, label %23, label %44

23:                                               ; preds = %20
  %24 = load ptr, ptr %8, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.Resub, ptr %24, i32 0, i32 0
  %26 = load ptr, ptr %25, align 8, !tbaa !14
  %27 = icmp ne ptr %26, null
  br i1 %27, label %28, label %33

28:                                               ; preds = %23
  %29 = load ptr, ptr %8, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.Resub, ptr %29, i32 0, i32 0
  %31 = load ptr, ptr %30, align 8, !tbaa !14
  %32 = getelementptr inbounds %struct.Reljunk, ptr %10, i32 0, i32 4
  store ptr %31, ptr %32, align 8, !tbaa !11
  br label %33

33:                                               ; preds = %28, %23
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = getelementptr inbounds %struct.Resub, ptr %34, i32 0, i32 1
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = icmp ne ptr %36, null
  br i1 %37, label %38, label %43

38:                                               ; preds = %33
  %39 = load ptr, ptr %8, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.Resub, ptr %39, i32 0, i32 1
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = getelementptr inbounds %struct.Reljunk, ptr %10, i32 0, i32 5
  store ptr %41, ptr %42, align 8, !tbaa !13
  br label %43

43:                                               ; preds = %38, %33
  br label %44

44:                                               ; preds = %43, %20, %4
  %45 = getelementptr inbounds %struct.Reljunk, ptr %10, i32 0, i32 2
  store i32 0, ptr %45, align 8, !tbaa !15
  %46 = getelementptr inbounds %struct.Reljunk, ptr %10, i32 0, i32 3
  store i32 0, ptr %46, align 4, !tbaa !16
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.Reprog, ptr %47, i32 0, i32 0
  %49 = load ptr, ptr %48, align 8, !tbaa !17
  %50 = getelementptr inbounds %struct.Reinst, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !19
  %52 = icmp eq i32 %51, 127
  br i1 %52, label %53, label %68

53:                                               ; preds = %44
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.Reprog, ptr %54, i32 0, i32 0
  %56 = load ptr, ptr %55, align 8, !tbaa !17
  %57 = getelementptr inbounds %struct.Reinst, ptr %56, i32 0, i32 1
  %58 = load i32, ptr %57, align 8, !tbaa !14
  %59 = icmp ult i32 %58, 128
  br i1 %59, label %60, label %68

60:                                               ; preds = %53
  %61 = getelementptr inbounds %struct.Reljunk, ptr %10, i32 0, i32 2
  store i32 127, ptr %61, align 8, !tbaa !15
  %62 = load ptr, ptr %6, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.Reprog, ptr %62, i32 0, i32 0
  %64 = load ptr, ptr %63, align 8, !tbaa !17
  %65 = getelementptr inbounds %struct.Reinst, ptr %64, i32 0, i32 1
  %66 = load i32, ptr %65, align 8, !tbaa !14
  %67 = getelementptr inbounds %struct.Reljunk, ptr %10, i32 0, i32 3
  store i32 %66, ptr %67, align 4, !tbaa !16
  br label %68

68:                                               ; preds = %60, %53, %44
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.Reprog, ptr %69, i32 0, i32 0
  %71 = load ptr, ptr %70, align 8, !tbaa !17
  %72 = getelementptr inbounds %struct.Reinst, ptr %71, i32 0, i32 0
  %73 = load i32, ptr %72, align 8, !tbaa !19
  %74 = icmp eq i32 %73, 195
  br i1 %74, label %75, label %77

75:                                               ; preds = %68
  %76 = getelementptr inbounds %struct.Reljunk, ptr %10, i32 0, i32 2
  store i32 195, ptr %76, align 8, !tbaa !15
  br label %77

77:                                               ; preds = %75, %68
  %78 = getelementptr inbounds [10 x %struct.Relist], ptr %11, i64 0, i64 0
  %79 = getelementptr inbounds %struct.Reljunk, ptr %10, i32 0, i32 0
  %80 = getelementptr inbounds [2 x ptr], ptr %79, i64 0, i64 0
  store ptr %78, ptr %80, align 8, !tbaa !5
  %81 = getelementptr inbounds [10 x %struct.Relist], ptr %12, i64 0, i64 0
  %82 = getelementptr inbounds %struct.Reljunk, ptr %10, i32 0, i32 0
  %83 = getelementptr inbounds [2 x ptr], ptr %82, i64 0, i64 1
  store ptr %81, ptr %83, align 8, !tbaa !5
  %84 = getelementptr inbounds [10 x %struct.Relist], ptr %11, i64 0, i64 0
  %85 = getelementptr inbounds %struct.Relist, ptr %84, i64 10
  %86 = getelementptr inbounds %struct.Relist, ptr %85, i64 -2
  %87 = getelementptr inbounds %struct.Reljunk, ptr %10, i32 0, i32 1
  %88 = getelementptr inbounds [2 x ptr], ptr %87, i64 0, i64 0
  store ptr %86, ptr %88, align 8, !tbaa !5
  %89 = getelementptr inbounds [10 x %struct.Relist], ptr %12, i64 0, i64 0
  %90 = getelementptr inbounds %struct.Relist, ptr %89, i64 10
  %91 = getelementptr inbounds %struct.Relist, ptr %90, i64 -2
  %92 = getelementptr inbounds %struct.Reljunk, ptr %10, i32 0, i32 1
  %93 = getelementptr inbounds [2 x ptr], ptr %92, i64 0, i64 1
  store ptr %91, ptr %93, align 8, !tbaa !5
  %94 = load ptr, ptr %6, align 8, !tbaa !5
  %95 = load ptr, ptr %7, align 8, !tbaa !5
  %96 = load ptr, ptr %8, align 8, !tbaa !5
  %97 = load i32, ptr %9, align 4, !tbaa !9
  %98 = call i32 @regexec1(ptr noundef %94, ptr noundef %95, ptr noundef %96, i32 noundef %97, ptr noundef %10)
  store i32 %98, ptr %13, align 4, !tbaa !9
  %99 = load i32, ptr %13, align 4, !tbaa !9
  %100 = icmp sge i32 %99, 0
  br i1 %100, label %101, label %103

101:                                              ; preds = %77
  %102 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %102, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %114

103:                                              ; preds = %77
  %104 = load ptr, ptr %6, align 8, !tbaa !5
  %105 = load ptr, ptr %7, align 8, !tbaa !5
  %106 = load ptr, ptr %8, align 8, !tbaa !5
  %107 = load i32, ptr %9, align 4, !tbaa !9
  %108 = call i32 @regexec2(ptr noundef %104, ptr noundef %105, ptr noundef %106, i32 noundef %107, ptr noundef %10)
  store i32 %108, ptr %13, align 4, !tbaa !9
  %109 = load i32, ptr %13, align 4, !tbaa !9
  %110 = icmp sge i32 %109, 0
  br i1 %110, label %111, label %113

111:                                              ; preds = %103
  %112 = load i32, ptr %13, align 4, !tbaa !9
  store i32 %112, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %114

113:                                              ; preds = %103
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %114

114:                                              ; preds = %113, %111, %101
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 5200, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 5200, ptr %11) #2
  call void @llvm.lifetime.end.p0(i64 72, ptr %10) #2
  %115 = load i32, ptr %5, align 4
  ret i32 %115
}

; 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 @regexec1(ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @regexec2(ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr 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 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 40}
!12 = !{!"Reljunk", !7, i64 0, !7, i64 16, !10, i64 32, !10, i64 36, !6, i64 40, !6, i64 48, !6, i64 56, !6, i64 64}
!13 = !{!12, !6, i64 48}
!14 = !{!7, !7, i64 0}
!15 = !{!12, !10, i64 32}
!16 = !{!12, !10, i64 36}
!17 = !{!18, !6, i64 0}
!18 = !{!"Reprog", !6, i64 0, !7, i64 8, !7, i64 8456}
!19 = !{!20, !10, i64 0}
!20 = !{!"Reinst", !10, i64 0, !7, i64 8, !7, i64 16}


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

%struct.Reljunk = type { [2 x ptr], [2 x ptr], i32, i32, ptr, ptr, ptr, ptr }
%struct.Relist = type { ptr, %struct.Resublist }
%struct.Resublist = type { [32 x %struct.Resub] }
%struct.Resub = type { %union.anon, %union.anon.0 }
%union.anon = type { ptr }
%union.anon.0 = type { ptr }

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, -2147483648) i32 @regexec9(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = alloca %struct.Reljunk, align 8
  %6 = alloca [10 x %struct.Relist], align 16
  %7 = alloca [10 x %struct.Relist], align 16
  call void @llvm.lifetime.start.p0(i64 72, ptr nonnull %5) #3
  call void @llvm.lifetime.start.p0(i64 5200, ptr nonnull %6) #3
  call void @llvm.lifetime.start.p0(i64 5200, ptr nonnull %7) #3
  %8 = getelementptr inbounds i8, ptr %5, i64 40
  store ptr %1, ptr %8, align 8, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %5, i64 48
  store ptr null, ptr %9, align 8, !tbaa !11
  %10 = icmp ne ptr %2, null
  %11 = icmp sgt i32 %3, 0
  %or.cond = and i1 %10, %11
  br i1 %or.cond, label %12, label %19

12:                                               ; preds = %4
  %13 = load ptr, ptr %2, align 8, !tbaa !12
  %.not = icmp eq ptr %13, null
  br i1 %.not, label %15, label %14

14:                                               ; preds = %12
  store ptr %13, ptr %8, align 8, !tbaa !5
  br label %15

15:                                               ; preds = %14, %12
  %16 = getelementptr inbounds i8, ptr %2, i64 8
  %17 = load ptr, ptr %16, align 8, !tbaa !12
  %.not29 = icmp eq ptr %17, null
  br i1 %.not29, label %19, label %18

18:                                               ; preds = %15
  store ptr %17, ptr %9, align 8, !tbaa !11
  br label %19

19:                                               ; preds = %15, %18, %4
  %20 = getelementptr inbounds i8, ptr %5, i64 32
  store i32 0, ptr %20, align 8, !tbaa !13
  %21 = getelementptr inbounds i8, ptr %5, i64 36
  store i32 0, ptr %21, align 4, !tbaa !14
  %22 = load ptr, ptr %0, align 8, !tbaa !15
  %23 = load i32, ptr %22, align 8, !tbaa !17
  switch i32 %23, label %.thread [
    i32 127, label %24
    i32 195, label %29
  ]

24:                                               ; preds = %19
  %25 = getelementptr inbounds i8, ptr %22, i64 8
  %26 = load i32, ptr %25, align 8, !tbaa !12
  %27 = icmp ult i32 %26, 128
  br i1 %27, label %28, label %.thread

28:                                               ; preds = %24
  store i32 127, ptr %20, align 8, !tbaa !13
  store i32 %26, ptr %21, align 4, !tbaa !14
  br label %.thread

29:                                               ; preds = %19
  store i32 195, ptr %20, align 8, !tbaa !13
  br label %.thread

.thread:                                          ; preds = %19, %24, %28, %29
  store ptr %6, ptr %5, align 8, !tbaa !19
  %30 = getelementptr inbounds i8, ptr %5, i64 8
  store ptr %7, ptr %30, align 8, !tbaa !19
  %31 = getelementptr inbounds i8, ptr %6, i64 4160
  %32 = getelementptr inbounds i8, ptr %5, i64 16
  store ptr %31, ptr %32, align 8, !tbaa !19
  %33 = getelementptr inbounds i8, ptr %7, i64 4160
  %34 = getelementptr inbounds i8, ptr %5, i64 24
  store ptr %33, ptr %34, align 8, !tbaa !19
  %35 = call i32 @regexec1(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef nonnull %5)
  %36 = icmp sgt i32 %35, -1
  br i1 %36, label %39, label %37

37:                                               ; preds = %.thread
  %38 = call i32 @regexec2(ptr noundef nonnull %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, ptr noundef nonnull %5)
  %. = call i32 @llvm.smax.i32(i32 %38, i32 -1)
  br label %39

39:                                               ; preds = %37, %.thread
  %.0 = phi i32 [ %35, %.thread ], [ %., %37 ]
  call void @llvm.lifetime.end.p0(i64 5200, ptr nonnull %7) #3
  call void @llvm.lifetime.end.p0(i64 5200, ptr nonnull %6) #3
  call void @llvm.lifetime.end.p0(i64 72, ptr nonnull %5) #3
  ret i32 %.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: nounwind uwtable
declare hidden i32 @regexec1(ptr noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #0

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, i64 40}
!6 = !{!"Reljunk", !7, i64 0, !7, i64 16, !9, i64 32, !9, i64 36, !10, i64 40, !10, i64 48, !10, i64 56, !10, i64 64}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!6, !10, i64 48}
!12 = !{!7, !7, i64 0}
!13 = !{!6, !9, i64 32}
!14 = !{!6, !9, i64 36}
!15 = !{!16, !10, i64 0}
!16 = !{!"Reprog", !10, i64 0, !7, i64 8, !7, i64 8456}
!17 = !{!18, !9, i64 0}
!18 = !{!"Reinst", !9, i64 0, !7, i64 8, !7, i64 16}
!19 = !{!10, !10, i64 0}


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