; LLVM IR from mitdbg/deneva :: benchmarks/ycsb_query.ll (ZN9YCSBQuery12participantsERPbP8Workload)

; 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.YCSBQuery = type { %class.BaseQuery, %class.Array.0 }
%class.BaseQuery = type { ptr, i64, %class.Array, %class.Array, %class.Array, %class.Array }
%class.Array = type { ptr, i64, i64 }
%class.Array.0 = type { ptr, i64, i64 }
%class.ycsb_request = type <{ i32, [4 x i8], i64, i8, [7 x i8] }>

@g_node_cnt = 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 nounwind uwtable
declare dso_local noundef i64 @_ZN5ArrayIP12ycsb_requestE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

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

declare noundef i32 @_ZN12YCSBWorkload11key_to_partEm(ptr noundef nonnull align 8 dereferenceable(176), i64 noundef) #2

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN9YCSBQuery12participantsERPbP8Workload(ptr noundef nonnull align 8 dereferenceable(136) %0, ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef %2) #3 align 2 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store ptr %2, ptr %6, align 8, !tbaa !5
  %11 = load ptr, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !11
  br label %12

12:                                               ; preds = %23, %3
  %13 = load i64, ptr %8, align 8, !tbaa !11
  %14 = load i32, ptr @g_node_cnt, align 4, !tbaa !9
  %15 = zext i32 %14 to i64
  %16 = icmp ult i64 %13, %15
  br i1 %16, label %18, label %17

17:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %26

18:                                               ; preds = %12
  %19 = load ptr, ptr %5, align 8, !tbaa !5
  %20 = load ptr, ptr %19, align 8, !tbaa !5
  %21 = load i64, ptr %8, align 8, !tbaa !11
  %22 = getelementptr inbounds i8, ptr %20, i64 %21
  store i8 0, ptr %22, align 1, !tbaa !13
  br label %23

23:                                               ; preds = %18
  %24 = load i64, ptr %8, align 8, !tbaa !11
  %25 = add i64 %24, 1
  store i64 %25, ptr %8, align 8, !tbaa !11
  br label %12, !llvm.loop !15

26:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !11
  br label %27

27:                                               ; preds = %58, %26
  %28 = load i64, ptr %9, align 8, !tbaa !11
  %29 = getelementptr inbounds %class.YCSBQuery, ptr %11, i32 0, i32 1
  %30 = call noundef i64 @_ZN5ArrayIP12ycsb_requestE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %29)
  %31 = icmp ult i64 %28, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  br label %61

33:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  %34 = load ptr, ptr %6, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.YCSBQuery, ptr %11, i32 0, i32 1
  %36 = load i64, ptr %9, align 8, !tbaa !11
  %37 = call noundef ptr @_ZN5ArrayIP12ycsb_requestEixEm(ptr noundef nonnull align 8 dereferenceable(24) %35, i64 noundef %36)
  %38 = getelementptr inbounds %class.ycsb_request, ptr %37, i32 0, i32 2
  %39 = load i64, ptr %38, align 8, !tbaa !17
  %40 = call noundef i32 @_ZN12YCSBWorkload11key_to_partEm(ptr noundef nonnull align 8 dereferenceable(176) %34, i64 noundef %39)
  %41 = load i32, ptr @g_node_cnt, align 4, !tbaa !9
  %42 = urem i32 %40, %41
  %43 = zext i32 %42 to i64
  store i64 %43, ptr %10, align 8, !tbaa !11
  %44 = load ptr, ptr %5, align 8, !tbaa !5
  %45 = load ptr, ptr %44, align 8, !tbaa !5
  %46 = load i64, ptr %10, align 8, !tbaa !11
  %47 = getelementptr inbounds i8, ptr %45, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !13, !range !20, !noundef !21
  %49 = trunc i8 %48 to i1
  br i1 %49, label %53, label %50

50:                                               ; preds = %33
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %7, align 4, !tbaa !9
  br label %53

53:                                               ; preds = %50, %33
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = load ptr, ptr %54, align 8, !tbaa !5
  %56 = load i64, ptr %10, align 8, !tbaa !11
  %57 = getelementptr inbounds i8, ptr %55, i64 %56
  store i8 1, ptr %57, align 1, !tbaa !13
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %58

58:                                               ; preds = %53
  %59 = load i64, ptr %9, align 8, !tbaa !11
  %60 = add i64 %59, 1
  store i64 %60, ptr %9, align 8, !tbaa !11
  br label %27, !llvm.loop !22

61:                                               ; preds = %32
  %62 = load i32, ptr %7, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  ret i64 %63
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { 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 #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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"bool", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = !{!18, !12, i64 8}
!18 = !{!"_ZTS12ycsb_request", !19, i64 0, !12, i64 8, !7, i64 16}
!19 = !{!"_ZTS8access_t", !7, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = distinct !{!22, !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"

@g_node_cnt = external local_unnamed_addr global i32, align 4

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

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

declare noundef i32 @_ZN12YCSBWorkload11key_to_partEm(ptr noundef nonnull align 8 dereferenceable(176), i64 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local noundef range(i64 -2147483648, 2147483648) i64 @_ZN9YCSBQuery12participantsERPbP8Workload(ptr noundef nonnull align 8 dereferenceable(136) %0, ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %1, ptr noundef %2) local_unnamed_addr #2 align 2 {
  %4 = load i32, ptr @g_node_cnt, align 4, !tbaa !5
  %.not = icmp eq i32 %4, 0
  br i1 %.not, label %.preheader, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %5 = zext i32 %4 to i64
  %6 = load ptr, ptr %1, align 8, !tbaa !9
  tail call void @llvm.memset.p0.i64(ptr align 1 %6, i8 0, i64 %5, i1 false), !tbaa !11
  br label %.preheader

.preheader:                                       ; preds = %.lr.ph, %3
  %7 = getelementptr inbounds i8, ptr %0, i64 112
  %8 = tail call noundef i64 @_ZN5ArrayIP12ycsb_requestE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7)
  %.not20 = icmp eq i64 %8, 0
  br i1 %.not20, label %._crit_edge, label %.lr.ph19

._crit_edge.loopexit:                             ; preds = %.lr.ph19
  %9 = zext nneg i32 %spec.select to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader
  %.0.lcssa = phi i64 [ 0, %.preheader ], [ %9, %._crit_edge.loopexit ]
  ret i64 %.0.lcssa

.lr.ph19:                                         ; preds = %.preheader, %.lr.ph19
  %.018 = phi i32 [ %spec.select, %.lr.ph19 ], [ 0, %.preheader ]
  %.01417 = phi i64 [ %21, %.lr.ph19 ], [ 0, %.preheader ]
  %10 = tail call noundef ptr @_ZN5ArrayIP12ycsb_requestEixEm(ptr noundef nonnull align 8 dereferenceable(24) %7, i64 noundef %.01417)
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  %12 = load i64, ptr %11, align 8, !tbaa !13
  %13 = tail call noundef i32 @_ZN12YCSBWorkload11key_to_partEm(ptr noundef nonnull align 8 dereferenceable(176) %2, i64 noundef %12)
  %14 = load i32, ptr @g_node_cnt, align 4, !tbaa !5
  %15 = urem i32 %13, %14
  %16 = zext i32 %15 to i64
  %17 = load ptr, ptr %1, align 8, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %17, i64 %16
  %19 = load i8, ptr %18, align 1, !tbaa !11, !range !17, !noundef !18
  %20 = xor i8 %19, 1
  %not. = zext nneg i8 %20 to i32
  %spec.select = add nuw nsw i32 %.018, %not.
  store i8 1, ptr %18, align 1, !tbaa !11
  %21 = add nuw i64 %.01417, 1
  %22 = tail call noundef i64 @_ZN5ArrayIP12ycsb_requestE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %7)
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %.lr.ph19, label %._crit_edge.loopexit, !llvm.loop !19
}

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

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

!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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{!14, !16, i64 8}
!14 = !{!"_ZTS12ycsb_request", !15, i64 0, !16, i64 8, !7, i64 16}
!15 = !{!"_ZTS8access_t", !7, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{i8 0, i8 2}
!18 = !{}
!19 = distinct !{!19, !20}
!20 = !{!"llvm.loop.mustprogress"}


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