; LLVM IR from mitdbg/deneva :: benchmarks/tpcc_wl.ll (ZN12TPCCWorkload15threadInitStockEPv)

; 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.thr_args = type { ptr, i32, i32 }

@g_num_wh = external global i32, align 4
@.str.23 = external hidden unnamed_addr constant [12 x i8], align 1
@g_node_cnt = external global i32, align 4
@g_node_id = 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

declare i32 @printf(ptr noundef, ...) #1

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

12:                                               ; preds = %32, %1
  %13 = load i64, ptr %5, align 8, !tbaa !14
  %14 = load i32, ptr @g_num_wh, align 4, !tbaa !13
  %15 = zext i32 %14 to i64
  %16 = icmp ule i64 %13, %15
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %12
  %19 = load i64, ptr %5, align 8, !tbaa !14
  %20 = call noundef i64 @_Z10wh_to_partm(i64 noundef %19)
  %21 = load i32, ptr @g_node_cnt, align 4, !tbaa !13
  %22 = zext i32 %21 to i64
  %23 = urem i64 %20, %22
  %24 = load i32, ptr @g_node_id, align 4, !tbaa !13
  %25 = zext i32 %24 to i64
  %26 = icmp ne i64 %23, %25
  br i1 %26, label %27, label %28

27:                                               ; preds = %18
  br label %32

28:                                               ; preds = %18
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = load i32, ptr %4, align 4, !tbaa !13
  %31 = load i64, ptr %5, align 8, !tbaa !14
  call void @_ZN12TPCCWorkload14init_tab_stockEim(ptr noundef nonnull align 8 dereferenceable(296) %29, i32 noundef %30, i64 noundef %31)
  br label %32

32:                                               ; preds = %28, %27
  %33 = load i64, ptr %5, align 8, !tbaa !14
  %34 = add i64 %33, 1
  store i64 %34, ptr %5, align 8, !tbaa !14
  br label %12, !llvm.loop !16

35:                                               ; preds = %17
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.23)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #3
  ret ptr null
}

declare noundef i64 @_Z10wh_to_partm(i64 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12TPCCWorkload14init_tab_stockEim(ptr noundef nonnull align 8 dereferenceable(296), i32 noundef, i64 noundef) #2 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !6, i64 0}
!10 = !{!"_ZTS8thr_args", !6, i64 0, !11, i64 8, !11, i64 12}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !11, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!15, !15, i64 0}
!15 = !{!"long", !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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_num_wh = external local_unnamed_addr global i32, align 4
@.str.23 = external hidden unnamed_addr constant [12 x i8], align 1
@g_node_cnt = external local_unnamed_addr global i32, align 4
@g_node_id = external local_unnamed_addr global i32, align 4

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

; Function Attrs: mustprogress uwtable
define dso_local noalias noundef ptr @_ZN12TPCCWorkload15threadInitStockEPv(ptr nocapture noundef readonly %0) local_unnamed_addr #1 align 2 {
  %2 = load ptr, ptr %0, align 8, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 8
  %4 = load i32, ptr %3, align 8, !tbaa !11
  %5 = load i32, ptr @g_num_wh, align 4, !tbaa !12
  %.not8 = icmp eq i32 %5, 0
  br i1 %.not8, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %14, %1
  %6 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.23)
  ret ptr null

.lr.ph:                                           ; preds = %1, %14
  %.09 = phi i64 [ %15, %14 ], [ 1, %1 ]
  %7 = tail call noundef i64 @_Z10wh_to_partm(i64 noundef %.09)
  %8 = load i32, ptr @g_node_cnt, align 4, !tbaa !12
  %9 = zext i32 %8 to i64
  %10 = urem i64 %7, %9
  %11 = load i32, ptr @g_node_id, align 4, !tbaa !12
  %12 = zext i32 %11 to i64
  %.not7 = icmp eq i64 %10, %12
  br i1 %.not7, label %13, label %14

13:                                               ; preds = %.lr.ph
  tail call void @_ZN12TPCCWorkload14init_tab_stockEim(ptr noundef nonnull align 8 dereferenceable(296) %2, i32 noundef %4, i64 noundef %.09)
  br label %14

14:                                               ; preds = %.lr.ph, %13
  %15 = add nuw nsw i64 %.09, 1
  %16 = load i32, ptr @g_num_wh, align 4, !tbaa !12
  %17 = zext i32 %16 to i64
  %.not.not = icmp ult i64 %.09, %17
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !13
}

declare noundef i64 @_Z10wh_to_partm(i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZN12TPCCWorkload14init_tab_stockEim(ptr noundef nonnull align 8 dereferenceable(296), i32 noundef, i64 noundef) local_unnamed_addr #1 align 2

attributes #0 = { 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 #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 = { "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, !7, i64 0}
!6 = !{!"_ZTS8thr_args", !7, i64 0, !10, i64 8, !10, i64 12}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!10, !10, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


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