; LLVM IR from IlyaGrebnov/libbsc :: libbsc/bwt/libsais (libsais)

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @libsais_main_ctx(ptr noundef, ptr noundef, ptr noundef, i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @libsais_gsa_ctx(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  store ptr %2, ptr %10, align 8, !tbaa !5
  store i32 %3, ptr %11, align 4, !tbaa !9
  store i32 %4, ptr %12, align 4, !tbaa !9
  store ptr %5, ptr %13, align 8, !tbaa !5
  %14 = load ptr, ptr %8, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %40, label %16

16:                                               ; preds = %6
  %17 = load ptr, ptr %9, align 8, !tbaa !5
  %18 = icmp eq ptr %17, null
  br i1 %18, label %40, label %19

19:                                               ; preds = %16
  %20 = load ptr, ptr %10, align 8, !tbaa !5
  %21 = icmp eq ptr %20, null
  br i1 %21, label %40, label %22

22:                                               ; preds = %19
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = icmp slt i32 %23, 0
  br i1 %24, label %40, label %25

25:                                               ; preds = %22
  %26 = load i32, ptr %11, align 4, !tbaa !9
  %27 = icmp sgt i32 %26, 0
  br i1 %27, label %28, label %37

28:                                               ; preds = %25
  %29 = load ptr, ptr %9, align 8, !tbaa !5
  %30 = load i32, ptr %11, align 4, !tbaa !9
  %31 = sub nsw i32 %30, 1
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds i8, ptr %29, i64 %32
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %35 = zext i8 %34 to i32
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %40, label %37

37:                                               ; preds = %28, %25
  %38 = load i32, ptr %12, align 4, !tbaa !9
  %39 = icmp slt i32 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %37, %28, %22, %19, %16, %6
  store i32 -1, ptr %7, align 4
  br label %77

41:                                               ; preds = %37
  %42 = load i32, ptr %11, align 4, !tbaa !9
  %43 = icmp sle i32 %42, 1
  br i1 %43, label %44, label %68

44:                                               ; preds = %41
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  %46 = icmp ne ptr %45, null
  br i1 %46, label %47, label %49

47:                                               ; preds = %44
  %48 = load ptr, ptr %13, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 4 %48, i8 0, i64 1024, i1 false)
  br label %49

49:                                               ; preds = %47, %44
  %50 = load i32, ptr %11, align 4, !tbaa !9
  %51 = icmp eq i32 %50, 1
  br i1 %51, label %52, label %67

52:                                               ; preds = %49
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = getelementptr inbounds i32, ptr %53, i64 0
  store i32 0, ptr %54, align 4, !tbaa !9
  %55 = load ptr, ptr %13, align 8, !tbaa !5
  %56 = icmp ne ptr %55, null
  br i1 %56, label %57, label %66

57:                                               ; preds = %52
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds i8, ptr %59, i64 0
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = zext i8 %61 to i64
  %63 = getelementptr inbounds i32, ptr %58, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %63, align 4, !tbaa !9
  br label %66

66:                                               ; preds = %57, %52
  br label %67

67:                                               ; preds = %66, %49
  store i32 0, ptr %7, align 4
  br label %77

68:                                               ; preds = %41
  br label %69

69:                                               ; preds = %68
  %70 = load ptr, ptr %8, align 8, !tbaa !5
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = load ptr, ptr %10, align 8, !tbaa !5
  %73 = load i32, ptr %11, align 4, !tbaa !9
  %74 = load i32, ptr %12, align 4, !tbaa !9
  %75 = load ptr, ptr %13, align 8, !tbaa !5
  %76 = call i32 @libsais_main_ctx(ptr noundef %70, ptr noundef %71, ptr noundef %72, i32 noundef %73, i32 noundef 2, i32 noundef 0, ptr noundef null, i32 noundef %74, ptr noundef %75)
  store i32 %76, ptr %7, align 4
  br label %77

77:                                               ; preds = %69, %67, %40
  %78 = load i32, ptr %7, align 4
  ret i32 %78
}

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { 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, !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 = !{!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"

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

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

; Function Attrs: nounwind uwtable
define dso_local i32 @libsais_gsa_ctx(ptr noundef %0, ptr noundef %1, ptr noundef %2, i32 noundef %3, i32 noundef %4, ptr noundef %5) local_unnamed_addr #1 {
  %7 = icmp eq ptr %0, null
  %8 = icmp eq ptr %1, null
  %or.cond = or i1 %7, %8
  %9 = icmp eq ptr %2, null
  %or.cond3 = or i1 %or.cond, %9
  %10 = icmp slt i32 %3, 0
  %or.cond5 = or i1 %or.cond3, %10
  br i1 %or.cond5, label %.thread38, label %11

11:                                               ; preds = %6
  %.not39 = icmp eq i32 %3, 0
  br i1 %.not39, label %19, label %12

12:                                               ; preds = %11
  %13 = zext nneg i32 %3 to i64
  %14 = getelementptr i8, ptr %1, i64 %13
  %15 = getelementptr i8, ptr %14, i64 -1
  %16 = load i8, ptr %15, align 1, !tbaa !5
  %17 = icmp ne i8 %16, 0
  %18 = icmp slt i32 %4, 0
  %or.cond7 = or i1 %18, %17
  br i1 %or.cond7, label %.thread38, label %20

19:                                               ; preds = %11
  %.old6 = icmp slt i32 %4, 0
  br i1 %.old6, label %.thread38, label %.thread.thread

20:                                               ; preds = %12
  %21 = icmp eq i32 %3, 1
  br i1 %21, label %.thread, label %28

.thread:                                          ; preds = %20
  %.not = icmp eq ptr %5, null
  br i1 %.not, label %27, label %.thread35

.thread.thread:                                   ; preds = %19
  %.not37 = icmp eq ptr %5, null
  br i1 %.not37, label %.thread38, label %.thread35.thread

.thread35.thread:                                 ; preds = %.thread.thread
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1024) %5, i8 0, i64 1024, i1 false)
  br label %.thread38

.thread35:                                        ; preds = %.thread
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 4 dereferenceable(1024) %5, i8 0, i64 1024, i1 false)
  store i32 0, ptr %2, align 4, !tbaa !8
  %22 = load i8, ptr %1, align 1, !tbaa !5
  %23 = zext i8 %22 to i64
  %24 = getelementptr inbounds i32, ptr %5, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !8
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %24, align 4, !tbaa !8
  br label %.thread38

27:                                               ; preds = %.thread
  store i32 0, ptr %2, align 4, !tbaa !8
  br label %.thread38

28:                                               ; preds = %20
  %29 = tail call i32 @libsais_main_ctx(ptr noundef nonnull %0, ptr noundef nonnull %1, ptr noundef nonnull %2, i32 noundef %3, i32 noundef 2, i32 noundef 0, ptr noundef null, i32 noundef %4, ptr noundef %5)
  br label %.thread38

.thread38:                                        ; preds = %.thread.thread, %.thread35.thread, %27, %.thread35, %6, %12, %19, %28
  %.0 = phi i32 [ %29, %28 ], [ -1, %19 ], [ -1, %12 ], [ -1, %6 ], [ 0, %27 ], [ 0, %.thread35 ], [ 0, %.thread35.thread ], [ 0, %.thread.thread ]
  ret i32 %.0
}

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { 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, !6, i64 0}
!6 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !6, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass