; LLVM IR from mitdbg/deneva :: client/client_query.ll (ZN18Client_query_queue19initQueriesParallelEv)

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

%class.Client_query_queue = type { ptr, i64, %"class.std::vector", ptr, i64 }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::vector<BaseQuery *>, std::allocator<std::vector<BaseQuery *>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::vector<BaseQuery *>, std::allocator<std::vector<BaseQuery *>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::vector<BaseQuery *>, std::allocator<std::vector<BaseQuery *>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::vector<BaseQuery *>, std::allocator<std::vector<BaseQuery *>>>::_Vector_impl_data" = type { ptr, ptr, ptr }

@g_servers_per_client = external global i32, align 4
@g_max_txn_per_part = external global i32, align 4
@g_init_parallelism = external global i32, align 4
@g_server_start_node = external global i32, align 4

; 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: mustprogress uwtable
define dso_local void @_ZN18Client_query_queue19initQueriesParallelEv(ptr noundef nonnull align 8 dereferenceable(56) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %10 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  %11 = getelementptr inbounds %class.Client_query_queue, ptr %10, i32 0, i32 4
  %12 = atomicrmw add ptr %11, i64 1 seq_cst, align 8
  %13 = trunc i64 %12 to i32
  store i32 %13, ptr %3, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #6
  %14 = load i32, ptr @g_max_txn_per_part, align 4, !tbaa !9
  %15 = add i32 %14, 4
  %16 = zext i32 %15 to i64
  store i64 %16, ptr %4, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %17 = load i32, ptr %3, align 4, !tbaa !9
  %18 = load i32, ptr @g_init_parallelism, align 4, !tbaa !9
  %19 = sub i32 %18, 1
  %20 = icmp eq i32 %17, %19
  br i1 %20, label %21, label %24

21:                                               ; preds = %1
  %22 = load i64, ptr %4, align 8, !tbaa !11
  %23 = trunc i64 %22 to i32
  store i32 %23, ptr %5, align 4, !tbaa !9
  br label %34

24:                                               ; preds = %1
  %25 = load i64, ptr %4, align 8, !tbaa !11
  %26 = load i32, ptr @g_init_parallelism, align 4, !tbaa !9
  %27 = zext i32 %26 to i64
  %28 = udiv i64 %25, %27
  %29 = load i32, ptr %3, align 4, !tbaa !9
  %30 = add i32 %29, 1
  %31 = zext i32 %30 to i64
  %32 = mul i64 %28, %31
  %33 = trunc i64 %32 to i32
  store i32 %33, ptr %5, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %24, %21
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %35 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #7
  call void @_ZN18YCSBQueryGeneratorC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %35) #6
  store ptr %35, ptr %6, align 8, !tbaa !5
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  call void @_ZN18YCSBQueryGenerator4initEv(ptr noundef nonnull align 8 dereferenceable(24) %36)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %37

37:                                               ; preds = %79, %34
  %38 = load i32, ptr %7, align 4, !tbaa !9
  %39 = load i32, ptr @g_servers_per_client, align 4, !tbaa !9
  %40 = icmp ult i32 %38, %39
  br i1 %40, label %42, label %41

41:                                               ; preds = %37
  store i32 2, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %82

42:                                               ; preds = %37
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %43 = load i64, ptr %4, align 8, !tbaa !11
  %44 = load i32, ptr @g_init_parallelism, align 4, !tbaa !9
  %45 = zext i32 %44 to i64
  %46 = udiv i64 %43, %45
  %47 = load i32, ptr %3, align 4, !tbaa !9
  %48 = zext i32 %47 to i64
  %49 = mul i64 %46, %48
  %50 = trunc i64 %49 to i32
  store i32 %50, ptr %9, align 4, !tbaa !9
  br label %51

51:                                               ; preds = %75, %42
  %52 = load i32, ptr %9, align 4, !tbaa !9
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = icmp ult i32 %52, %53
  br i1 %54, label %56, label %55

55:                                               ; preds = %51
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %78

56:                                               ; preds = %51
  %57 = load ptr, ptr %6, align 8, !tbaa !5
  %58 = getelementptr inbounds %class.Client_query_queue, ptr %10, i32 0, i32 0
  %59 = load ptr, ptr %58, align 8, !tbaa !13
  %60 = load i32, ptr %7, align 4, !tbaa !9
  %61 = load i32, ptr @g_server_start_node, align 4, !tbaa !9
  %62 = add i32 %60, %61
  %63 = zext i32 %62 to i64
  %64 = load ptr, ptr %57, align 8, !tbaa !19
  %65 = getelementptr inbounds ptr, ptr %64, i64 2
  %66 = load ptr, ptr %65, align 8
  %67 = call noundef ptr %66(ptr noundef nonnull align 8 dereferenceable(24) %57, ptr noundef %59, i64 noundef %63)
  %68 = getelementptr inbounds %class.Client_query_queue, ptr %10, i32 0, i32 2
  %69 = load i32, ptr %7, align 4, !tbaa !9
  %70 = zext i32 %69 to i64
  %71 = call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IP9BaseQuerySaIS1_EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %68, i64 noundef %70) #6
  %72 = load i32, ptr %9, align 4, !tbaa !9
  %73 = zext i32 %72 to i64
  %74 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP9BaseQuerySaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %71, i64 noundef %73) #6
  store ptr %67, ptr %74, align 8, !tbaa !5
  br label %75

75:                                               ; preds = %56
  %76 = load i32, ptr %9, align 4, !tbaa !9
  %77 = add i32 %76, 1
  store i32 %77, ptr %9, align 4, !tbaa !9
  br label %51, !llvm.loop !21

78:                                               ; preds = %55
  br label %79

79:                                               ; preds = %78
  %80 = load i32, ptr %7, align 4, !tbaa !9
  %81 = add i32 %80, 1
  store i32 %81, ptr %7, align 4, !tbaa !9
  br label %37, !llvm.loop !23

82:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  ret void
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN18YCSBQueryGeneratorC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3 align 2

declare void @_ZN18YCSBQueryGenerator4initEv(ptr noundef nonnull align 8 dereferenceable(24)) #4

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IP9BaseQuerySaIS1_EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #5 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP9BaseQuerySaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #5 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress 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 = { nobuiltin allocsize(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 = { inlinehint mustprogress 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 #4 = { "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 #5 = { mustprogress 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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 0}
!14 = !{!"_ZTS18Client_query_queue", !6, i64 0, !12, i64 8, !15, i64 16, !6, i64 40, !12, i64 48}
!15 = !{!"_ZTSSt6vectorIS_IP9BaseQuerySaIS1_EESaIS3_EE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseISt6vectorIP9BaseQuerySaIS2_EESaIS4_EE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseISt6vectorIP9BaseQuerySaIS2_EESaIS4_EE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseISt6vectorIP9BaseQuerySaIS2_EESaIS4_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !8, i64 0}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}
!23 = distinct !{!23, !22}


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

@g_servers_per_client = external local_unnamed_addr global i32, align 4
@g_max_txn_per_part = external local_unnamed_addr global i32, align 4
@g_init_parallelism = external local_unnamed_addr global i32, align 4
@g_server_start_node = external local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN18Client_query_queue19initQueriesParallelEv(ptr noundef nonnull align 8 dereferenceable(56) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 48
  %3 = atomicrmw add ptr %2, i64 1 seq_cst, align 8
  %4 = trunc i64 %3 to i32
  %5 = load i32, ptr @g_max_txn_per_part, align 4, !tbaa !5
  %6 = add i32 %5, 4
  %7 = load i32, ptr @g_init_parallelism, align 4, !tbaa !5
  %8 = add i32 %7, -1
  %9 = icmp eq i32 %8, %4
  br i1 %9, label %14, label %10

10:                                               ; preds = %1
  %11 = udiv i32 %6, %7
  %12 = add i32 %4, 1
  %13 = mul i32 %11, %12
  br label %14

14:                                               ; preds = %1, %10
  %.017 = phi i32 [ %13, %10 ], [ %6, %1 ]
  %15 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #5
  tail call void @_ZN18YCSBQueryGeneratorC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %15) #6
  tail call void @_ZN18YCSBQueryGenerator4initEv(ptr noundef nonnull align 8 dereferenceable(24) %15)
  %16 = load i32, ptr @g_servers_per_client, align 4, !tbaa !5
  %.not = icmp eq i32 %16, 0
  br i1 %.not, label %._crit_edge23, label %.lr.ph22

.lr.ph22:                                         ; preds = %14
  %17 = getelementptr inbounds i8, ptr %0, i64 16
  %18 = zext i32 %.017 to i64
  br label %19

._crit_edge23:                                    ; preds = %._crit_edge, %14
  ret void

19:                                               ; preds = %.lr.ph22, %._crit_edge
  %20 = phi i32 [ %16, %.lr.ph22 ], [ %27, %._crit_edge ]
  %indvars.iv25 = phi i64 [ 0, %.lr.ph22 ], [ %indvars.iv.next26, %._crit_edge ]
  %21 = load i32, ptr @g_init_parallelism, align 4, !tbaa !5
  %22 = udiv i32 %6, %21
  %23 = mul i32 %22, %4
  %24 = icmp ult i32 %23, %.017
  br i1 %24, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %19
  %25 = zext i32 %23 to i64
  %26 = trunc nuw i64 %indvars.iv25 to i32
  br label %30

._crit_edge.loopexit:                             ; preds = %30
  %.pre = load i32, ptr @g_servers_per_client, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %19
  %27 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %20, %19 ]
  %indvars.iv.next26 = add nuw nsw i64 %indvars.iv25, 1
  %28 = zext i32 %27 to i64
  %29 = icmp ult i64 %indvars.iv.next26, %28
  br i1 %29, label %19, label %._crit_edge23, !llvm.loop !9

30:                                               ; preds = %.lr.ph, %30
  %indvars.iv = phi i64 [ %25, %.lr.ph ], [ %indvars.iv.next, %30 ]
  %31 = load ptr, ptr %0, align 8, !tbaa !11
  %32 = load i32, ptr @g_server_start_node, align 4, !tbaa !5
  %33 = add i32 %32, %26
  %34 = zext i32 %33 to i64
  %35 = load ptr, ptr %15, align 8, !tbaa !19
  %36 = getelementptr inbounds i8, ptr %35, i64 16
  %37 = load ptr, ptr %36, align 8
  %38 = tail call noundef ptr %37(ptr noundef nonnull align 8 dereferenceable(24) %15, ptr noundef %31, i64 noundef %34)
  %39 = tail call noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IP9BaseQuerySaIS1_EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %17, i64 noundef %indvars.iv25) #6
  %40 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP9BaseQuerySaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %39, i64 noundef %indvars.iv) #6
  store ptr %38, ptr %40, align 8, !tbaa !21
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %41 = icmp ult i64 %indvars.iv.next, %18
  br i1 %41, label %30, label %._crit_edge.loopexit, !llvm.loop !22
}

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN18YCSBQueryGeneratorC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #2 align 2

declare void @_ZN18YCSBQueryGenerator4initEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #3

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(24) ptr @_ZNSt6vectorIS_IP9BaseQuerySaIS1_EESaIS3_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP9BaseQuerySaIS1_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #4 align 2

attributes #0 = { mustprogress 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 = { nobuiltin allocsize(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 = { inlinehint mustprogress 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 = { mustprogress 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 #5 = { builtin allocsize(0) }
attributes #6 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !13, i64 0}
!12 = !{!"_ZTS18Client_query_queue", !13, i64 0, !14, i64 8, !15, i64 16, !13, i64 40, !14, i64 48}
!13 = !{!"any pointer", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!"_ZTSSt6vectorIS_IP9BaseQuerySaIS1_EESaIS3_EE", !16, i64 0}
!16 = !{!"_ZTSSt12_Vector_baseISt6vectorIP9BaseQuerySaIS2_EESaIS4_EE", !17, i64 0}
!17 = !{!"_ZTSNSt12_Vector_baseISt6vectorIP9BaseQuerySaIS2_EESaIS4_EE12_Vector_implE", !18, i64 0}
!18 = !{!"_ZTSNSt12_Vector_baseISt6vectorIP9BaseQuerySaIS2_EESaIS4_EE17_Vector_impl_dataE", !13, i64 0, !13, i64 8, !13, i64 16}
!19 = !{!20, !20, i64 0}
!20 = !{!"vtable pointer", !8, i64 0}
!21 = !{!13, !13, i64 0}
!22 = distinct !{!22, !10}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass