; LLVM IR from davidesantangelo/krep :: krep (search_chunk_thread)

; 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.thread_data_t = type { i32, ptr, ptr, i64, ptr, i64, i8 }
%struct.search_params = type { ptr, i64, ptr, ptr, i64, i8, i8, i8, i8, i8, i8, ptr, ptr, i64 }

@stderr = external global ptr, align 8
@.str.75 = external hidden unnamed_addr constant [58 x i8], align 1

; 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: nounwind uwtable
declare dso_local ptr @match_result_init(i64 noundef) #1

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #2

; Function Attrs: nounwind uwtable
declare dso_local ptr @select_search_algorithm(ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local ptr @search_chunk_thread(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %10, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  store ptr null, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  store i64 0, ptr %6, align 8, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.thread_data_t, ptr %11, i32 0, i32 1
  %13 = load ptr, ptr %12, align 8, !tbaa !11
  %14 = getelementptr inbounds %struct.search_params, ptr %13, i32 0, i32 9
  %15 = load i8, ptr %14, align 4, !tbaa !15, !range !17, !noundef !18
  %16 = trunc i8 %15 to i1
  br i1 %16, label %17, label %50

17:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  %18 = load ptr, ptr %4, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.thread_data_t, ptr %18, i32 0, i32 3
  %20 = load i64, ptr %19, align 8, !tbaa !19
  %21 = udiv i64 %20, 1000
  %22 = icmp ugt i64 %21, 100
  br i1 %22, label %23, label %28

23:                                               ; preds = %17
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.thread_data_t, ptr %24, i32 0, i32 3
  %26 = load i64, ptr %25, align 8, !tbaa !19
  %27 = udiv i64 %26, 1000
  br label %29

28:                                               ; preds = %17
  br label %29

29:                                               ; preds = %28, %23
  %30 = phi i64 [ %27, %23 ], [ 100, %28 ]
  store i64 %30, ptr %7, align 8, !tbaa !9
  %31 = load i64, ptr %7, align 8, !tbaa !9
  %32 = call ptr @match_result_init(i64 noundef %31)
  store ptr %32, ptr %5, align 8, !tbaa !5
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = icmp ne ptr %33, null
  br i1 %34, label %43, label %35

35:                                               ; preds = %29
  %36 = load ptr, ptr @stderr, align 8, !tbaa !5
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.thread_data_t, ptr %37, i32 0, i32 0
  %39 = load i32, ptr %38, align 8, !tbaa !20
  %40 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %36, ptr noundef @.str.75, i32 noundef %39) #3
  %41 = load ptr, ptr %4, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.thread_data_t, ptr %41, i32 0, i32 6
  store i8 1, ptr %42, align 8, !tbaa !21
  store ptr null, ptr %2, align 8
  store i32 1, ptr %8, align 4
  br label %47

43:                                               ; preds = %29
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load ptr, ptr %4, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.thread_data_t, ptr %45, i32 0, i32 4
  store ptr %44, ptr %46, align 8, !tbaa !22
  store i32 0, ptr %8, align 4
  br label %47

47:                                               ; preds = %43, %35
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  %48 = load i32, ptr %8, align 4
  switch i32 %48, label %70 [
    i32 0, label %49
  ]

49:                                               ; preds = %47
  br label %50

50:                                               ; preds = %49, %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %51 = load ptr, ptr %4, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.thread_data_t, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !11
  %54 = call ptr @select_search_algorithm(ptr noundef %53)
  store ptr %54, ptr %9, align 8, !tbaa !5
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.thread_data_t, ptr %56, i32 0, i32 1
  %58 = load ptr, ptr %57, align 8, !tbaa !11
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.thread_data_t, ptr %59, i32 0, i32 2
  %61 = load ptr, ptr %60, align 8, !tbaa !23
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.thread_data_t, ptr %62, i32 0, i32 3
  %64 = load i64, ptr %63, align 8, !tbaa !19
  %65 = load ptr, ptr %5, align 8, !tbaa !5
  %66 = call i64 %55(ptr noundef %58, ptr noundef %61, i64 noundef %64, ptr noundef %65)
  store i64 %66, ptr %6, align 8, !tbaa !9
  %67 = load i64, ptr %6, align 8, !tbaa !9
  %68 = load ptr, ptr %4, align 8, !tbaa !5
  %69 = getelementptr inbounds %struct.thread_data_t, ptr %68, i32 0, i32 5
  store i64 %67, ptr %69, align 8, !tbaa !24
  store ptr null, ptr %2, align 8
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %70

70:                                               ; preds = %50, %47
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  %71 = load ptr, ptr %2, align 8
  ret ptr %71
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nounwind "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 = !{!"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, !6, i64 8}
!12 = !{!"", !13, i64 0, !6, i64 8, !6, i64 16, !10, i64 24, !6, i64 32, !10, i64 40, !14, i64 48}
!13 = !{!"int", !7, i64 0}
!14 = !{!"_Bool", !7, i64 0}
!15 = !{!16, !14, i64 44}
!16 = !{!"search_params", !6, i64 0, !10, i64 8, !6, i64 16, !6, i64 24, !10, i64 32, !14, i64 40, !14, i64 41, !14, i64 42, !14, i64 43, !14, i64 44, !14, i64 45, !6, i64 48, !6, i64 56, !10, i64 64}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = !{!12, !10, i64 24}
!20 = !{!12, !13, i64 0}
!21 = !{!12, !14, i64 48}
!22 = !{!12, !6, i64 32}
!23 = !{!12, !6, i64 16}
!24 = !{!12, !10, i64 40}


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

@stderr = external local_unnamed_addr global ptr, align 8
@.str.75 = external hidden unnamed_addr constant [58 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local ptr @match_result_init(i64 noundef) local_unnamed_addr #0

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local ptr @select_search_algorithm(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef ptr @search_chunk_thread(ptr nocapture noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 44
  %5 = load i8, ptr %4, align 4, !tbaa !13, !range !15, !noundef !16
  %6 = trunc nuw i8 %5 to i1
  br i1 %6, label %7, label %20

7:                                                ; preds = %1
  %8 = getelementptr inbounds i8, ptr %0, i64 24
  %9 = load i64, ptr %8, align 8, !tbaa !17
  %10 = icmp ugt i64 %9, 100999
  %11 = udiv i64 %9, 1000
  %12 = select i1 %10, i64 %11, i64 100
  %13 = tail call ptr @match_result_init(i64 noundef %12)
  %.not.not = icmp eq ptr %13, null
  br i1 %.not.not, label %.thread, label %18

.thread:                                          ; preds = %7
  %14 = load ptr, ptr @stderr, align 8, !tbaa !18
  %15 = load i32, ptr %0, align 8, !tbaa !19
  %16 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %14, ptr noundef nonnull @.str.75, i32 noundef %15) #2
  %17 = getelementptr inbounds i8, ptr %0, i64 48
  store i8 1, ptr %17, align 8, !tbaa !20
  br label %30

18:                                               ; preds = %7
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  store ptr %13, ptr %19, align 8, !tbaa !21
  %.pre = load ptr, ptr %2, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %18, %1
  %21 = phi ptr [ %.pre, %18 ], [ %3, %1 ]
  %.020 = phi ptr [ %13, %18 ], [ null, %1 ]
  %22 = tail call ptr @select_search_algorithm(ptr noundef %21)
  %23 = load ptr, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %0, i64 16
  %25 = load ptr, ptr %24, align 8, !tbaa !22
  %26 = getelementptr inbounds i8, ptr %0, i64 24
  %27 = load i64, ptr %26, align 8, !tbaa !17
  %28 = tail call i64 %22(ptr noundef %23, ptr noundef %25, i64 noundef %27, ptr noundef %.020) #3
  %29 = getelementptr inbounds i8, ptr %0, i64 40
  store i64 %28, ptr %29, align 8, !tbaa !23
  br label %30

30:                                               ; preds = %.thread, %20
  ret ptr null
}

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 = { nofree nounwind "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 = { cold nounwind }
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 8}
!6 = !{!"", !7, i64 0, !10, i64 8, !10, i64 16, !11, i64 24, !10, i64 32, !11, i64 40, !12, i64 48}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!"long", !8, i64 0}
!12 = !{!"_Bool", !8, i64 0}
!13 = !{!14, !12, i64 44}
!14 = !{!"search_params", !10, i64 0, !11, i64 8, !10, i64 16, !10, i64 24, !11, i64 32, !12, i64 40, !12, i64 41, !12, i64 42, !12, i64 43, !12, i64 44, !12, i64 45, !10, i64 48, !10, i64 56, !11, i64 64}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!6, !11, i64 24}
!18 = !{!10, !10, i64 0}
!19 = !{!6, !7, i64 0}
!20 = !{!6, !12, i64 48}
!21 = !{!6, !10, i64 32}
!22 = !{!6, !10, i64 16}
!23 = !{!6, !11, i64 40}


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