; LLVM IR from IlyaGrebnov/libsais :: src (libsais16x64)

; 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: 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 void @libsais16x64_convert_inplace_32u_to_64u_omp(ptr noundef, i64 noundef, i64 noundef) #2

; 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
declare hidden i64 @libsais16x64_main(ptr noundef, ptr noundef, i64 noundef, i64 noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i64 @libsais16x64_gsa(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) #2 {
  %6 = alloca i64, align 8
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  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 i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = icmp eq ptr %14, null
  br i1 %15, label %36, label %16

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

19:                                               ; preds = %16
  %20 = load i64, ptr %9, align 8, !tbaa !9
  %21 = icmp slt i64 %20, 0
  br i1 %21, label %36, label %22

22:                                               ; preds = %19
  %23 = load i64, ptr %9, align 8, !tbaa !9
  %24 = icmp sgt i64 %23, 0
  br i1 %24, label %25, label %33

25:                                               ; preds = %22
  %26 = load ptr, ptr %7, align 8, !tbaa !5
  %27 = load i64, ptr %9, align 8, !tbaa !9
  %28 = sub nsw i64 %27, 1
  %29 = getelementptr inbounds i16, ptr %26, i64 %28
  %30 = load i16, ptr %29, align 2, !tbaa !11
  %31 = zext i16 %30 to i32
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %36, label %33

33:                                               ; preds = %25, %22
  %34 = load i64, ptr %10, align 8, !tbaa !9
  %35 = icmp slt i64 %34, 0
  br i1 %35, label %36, label %37

36:                                               ; preds = %33, %25, %19, %16, %5
  store i64 -1, ptr %6, align 8
  br label %116

37:                                               ; preds = %33
  %38 = load i64, ptr %9, align 8, !tbaa !9
  %39 = icmp sle i64 %38, 1
  br i1 %39, label %40, label %64

40:                                               ; preds = %37
  %41 = load ptr, ptr %11, align 8, !tbaa !5
  %42 = icmp ne ptr %41, null
  br i1 %42, label %43, label %45

43:                                               ; preds = %40
  %44 = load ptr, ptr %11, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %44, i8 0, i64 524288, i1 false)
  br label %45

45:                                               ; preds = %43, %40
  %46 = load i64, ptr %9, align 8, !tbaa !9
  %47 = icmp eq i64 %46, 1
  br i1 %47, label %48, label %63

48:                                               ; preds = %45
  %49 = load ptr, ptr %8, align 8, !tbaa !5
  %50 = getelementptr inbounds i64, ptr %49, i64 0
  store i64 0, ptr %50, align 8, !tbaa !9
  %51 = load ptr, ptr %11, align 8, !tbaa !5
  %52 = icmp ne ptr %51, null
  br i1 %52, label %53, label %62

53:                                               ; preds = %48
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = load ptr, ptr %7, align 8, !tbaa !5
  %56 = getelementptr inbounds i16, ptr %55, i64 0
  %57 = load i16, ptr %56, align 2, !tbaa !11
  %58 = zext i16 %57 to i64
  %59 = getelementptr inbounds i64, ptr %54, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !9
  %61 = add nsw i64 %60, 1
  store i64 %61, ptr %59, align 8, !tbaa !9
  br label %62

62:                                               ; preds = %53, %48
  br label %63

63:                                               ; preds = %62, %45
  store i64 0, ptr %6, align 8
  br label %116

64:                                               ; preds = %37
  br label %65

65:                                               ; preds = %64
  %66 = load i64, ptr %9, align 8, !tbaa !9
  %67 = icmp sle i64 %66, 2147483647
  br i1 %67, label %68, label %109

68:                                               ; preds = %65
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  %69 = load i64, ptr %10, align 8, !tbaa !9
  %70 = load i64, ptr %10, align 8, !tbaa !9
  %71 = add nsw i64 %69, %70
  %72 = load i64, ptr %9, align 8, !tbaa !9
  %73 = add nsw i64 %71, %72
  %74 = load i64, ptr %9, align 8, !tbaa !9
  %75 = add nsw i64 %73, %74
  %76 = icmp sle i64 %75, 2147483647
  br i1 %76, label %77, label %83

77:                                               ; preds = %68
  %78 = load i64, ptr %10, align 8, !tbaa !9
  %79 = load i64, ptr %10, align 8, !tbaa !9
  %80 = add nsw i64 %78, %79
  %81 = load i64, ptr %9, align 8, !tbaa !9
  %82 = add nsw i64 %80, %81
  br label %86

83:                                               ; preds = %68
  %84 = load i64, ptr %9, align 8, !tbaa !9
  %85 = sub nsw i64 2147483647, %84
  br label %86

86:                                               ; preds = %83, %77
  %87 = phi i64 [ %82, %77 ], [ %85, %83 ]
  store i64 %87, ptr %12, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %88 = load ptr, ptr %7, align 8, !tbaa !5
  %89 = load ptr, ptr %8, align 8, !tbaa !5
  %90 = load i64, ptr %9, align 8, !tbaa !9
  %91 = trunc i64 %90 to i32
  %92 = load i64, ptr %12, align 8, !tbaa !9
  %93 = trunc i64 %92 to i32
  %94 = load ptr, ptr %11, align 8, !tbaa !5
  %95 = call i32 @libsais16_gsa(ptr noundef %88, ptr noundef %89, i32 noundef %91, i32 noundef %93, ptr noundef %94)
  %96 = sext i32 %95 to i64
  store i64 %96, ptr %13, align 8, !tbaa !9
  %97 = load i64, ptr %13, align 8, !tbaa !9
  %98 = icmp sge i64 %97, 0
  br i1 %98, label %99, label %107

99:                                               ; preds = %86
  %100 = load ptr, ptr %8, align 8, !tbaa !5
  %101 = load i64, ptr %9, align 8, !tbaa !9
  call void @libsais16x64_convert_inplace_32u_to_64u_omp(ptr noundef %100, i64 noundef %101, i64 noundef 1)
  %102 = load ptr, ptr %11, align 8, !tbaa !5
  %103 = icmp ne ptr %102, null
  br i1 %103, label %104, label %106

104:                                              ; preds = %99
  %105 = load ptr, ptr %11, align 8, !tbaa !5
  call void @libsais16x64_convert_inplace_32u_to_64u_omp(ptr noundef %105, i64 noundef 65536, i64 noundef 1)
  br label %106

106:                                              ; preds = %104, %99
  br label %107

107:                                              ; preds = %106, %86
  %108 = load i64, ptr %13, align 8, !tbaa !9
  store i64 %108, ptr %6, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %116

109:                                              ; preds = %65
  %110 = load ptr, ptr %7, align 8, !tbaa !5
  %111 = load ptr, ptr %8, align 8, !tbaa !5
  %112 = load i64, ptr %9, align 8, !tbaa !9
  %113 = load i64, ptr %10, align 8, !tbaa !9
  %114 = load ptr, ptr %11, align 8, !tbaa !5
  %115 = call i64 @libsais16x64_main(ptr noundef %110, ptr noundef %111, i64 noundef %112, i64 noundef 2, i64 noundef 0, ptr noundef null, i64 noundef %113, ptr noundef %114, i64 noundef 1)
  store i64 %115, ptr %6, align 8
  br label %116

116:                                              ; preds = %109, %107, %63, %36
  %117 = load i64, ptr %6, align 8
  ret i64 %117
}

declare i32 @libsais16_gsa(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) #3

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { "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 #4 = { 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 = !{!"short", !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 void @libsais16x64_convert_inplace_32u_to_64u_omp(ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind uwtable
define dso_local i64 @libsais16x64_gsa(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #1 {
  %6 = icmp eq ptr %0, null
  %7 = icmp eq ptr %1, null
  %or.cond = or i1 %6, %7
  %8 = icmp slt i64 %2, 0
  %or.cond3 = or i1 %or.cond, %8
  br i1 %or.cond3, label %.thread54, label %9

9:                                                ; preds = %5
  %.not55 = icmp eq i64 %2, 0
  br i1 %.not55, label %16, label %10

10:                                               ; preds = %9
  %11 = getelementptr i16, ptr %0, i64 %2
  %12 = getelementptr i8, ptr %11, i64 -2
  %13 = load i16, ptr %12, align 2, !tbaa !5
  %14 = icmp ne i16 %13, 0
  %15 = icmp slt i64 %3, 0
  %or.cond5 = or i1 %15, %14
  br i1 %or.cond5, label %.thread54, label %17

16:                                               ; preds = %9
  %.old4 = icmp slt i64 %3, 0
  br i1 %.old4, label %.thread54, label %.thread.thread

17:                                               ; preds = %10
  %18 = icmp eq i64 %2, 1
  br i1 %18, label %.thread, label %25

.thread:                                          ; preds = %17
  %.not50 = icmp eq ptr %4, null
  br i1 %.not50, label %24, label %.thread51

.thread.thread:                                   ; preds = %16
  %.not5053 = icmp eq ptr %4, null
  br i1 %.not5053, label %.thread54, label %.thread51.thread

.thread51.thread:                                 ; preds = %.thread.thread
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(524288) %4, i8 0, i64 524288, i1 false)
  br label %.thread54

.thread51:                                        ; preds = %.thread
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(524288) %4, i8 0, i64 524288, i1 false)
  store i64 0, ptr %1, align 8, !tbaa !9
  %19 = load i16, ptr %0, align 2, !tbaa !5
  %20 = zext i16 %19 to i64
  %21 = getelementptr inbounds i64, ptr %4, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !9
  %23 = add nsw i64 %22, 1
  store i64 %23, ptr %21, align 8, !tbaa !9
  br label %.thread54

24:                                               ; preds = %.thread
  store i64 0, ptr %1, align 8, !tbaa !9
  br label %.thread54

25:                                               ; preds = %17
  %26 = icmp ult i64 %2, 2147483648
  br i1 %26, label %27, label %41

27:                                               ; preds = %25
  %28 = shl nuw nsw i64 %3, 1
  %29 = add nuw nsw i64 %28, %2
  %30 = add nuw nsw i64 %29, %2
  %31 = icmp slt i64 %30, 2147483648
  %32 = sub nuw nsw i64 2147483647, %2
  %33 = select i1 %31, i64 %29, i64 %32
  %34 = trunc nuw nsw i64 %2 to i32
  %35 = trunc i64 %33 to i32
  %36 = tail call i32 @libsais16_gsa(ptr noundef nonnull %0, ptr noundef nonnull %1, i32 noundef %34, i32 noundef %35, ptr noundef %4) #3
  %37 = sext i32 %36 to i64
  %38 = icmp sgt i32 %36, -1
  br i1 %38, label %39, label %.thread54

39:                                               ; preds = %27
  tail call void @libsais16x64_convert_inplace_32u_to_64u_omp(ptr noundef nonnull %1, i64 noundef %2, i64 noundef 1)
  %.not = icmp eq ptr %4, null
  br i1 %.not, label %.thread54, label %40

40:                                               ; preds = %39
  tail call void @libsais16x64_convert_inplace_32u_to_64u_omp(ptr noundef nonnull %4, i64 noundef 65536, i64 noundef 1)
  br label %.thread54

41:                                               ; preds = %25
  %42 = tail call i64 @libsais16x64_main(ptr noundef nonnull %0, ptr noundef nonnull %1, i64 noundef %2, i64 noundef 2, i64 noundef 0, ptr noundef null, i64 noundef %3, ptr noundef %4, i64 noundef 1)
  br label %.thread54

.thread54:                                        ; preds = %.thread.thread, %.thread51.thread, %24, %27, %40, %39, %.thread51, %5, %10, %16, %41
  %.0 = phi i64 [ %42, %41 ], [ -1, %16 ], [ -1, %10 ], [ -1, %5 ], [ 0, %24 ], [ 0, %.thread51 ], [ %37, %39 ], [ %37, %40 ], [ %37, %27 ], [ 0, %.thread51.thread ], [ 0, %.thread.thread ]
  ret i64 %.0
}

declare i32 @libsais16_gsa(ptr noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef) local_unnamed_addr #2

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" }
attributes #2 = { "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 = !{!"short", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}


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