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

; 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
@g_node_cnt = external global i32, align 4
@g_node_id = external global i32, align 4
@g_dist_per_wh = external global i32, align 4
@.str.36 = external hidden unnamed_addr constant [12 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

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

declare noundef i64 @_Z10wh_to_partm(i64 noundef) #1

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

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

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

19:                                               ; preds = %14
  store i32 2, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %49

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

29:                                               ; preds = %20
  br label %46

30:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 1, ptr %7, align 8, !tbaa !14
  br label %31

31:                                               ; preds = %42, %30
  %32 = load i64, ptr %7, align 8, !tbaa !14
  %33 = load i32, ptr @g_dist_per_wh, align 4, !tbaa !13
  %34 = zext i32 %33 to i64
  %35 = icmp ule i64 %32, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %31
  store i32 5, ptr %6, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %45

37:                                               ; preds = %31
  %38 = load ptr, ptr %3, align 8, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !13
  %40 = load i64, ptr %7, align 8, !tbaa !14
  %41 = load i64, ptr %5, align 8, !tbaa !14
  call void @_ZN12TPCCWorkload14init_tab_orderEimm(ptr noundef nonnull align 8 dereferenceable(296) %38, i32 noundef %39, i64 noundef %40, i64 noundef %41)
  br label %42

42:                                               ; preds = %37
  %43 = load i64, ptr %7, align 8, !tbaa !14
  %44 = add i64 %43, 1
  store i64 %44, ptr %7, align 8, !tbaa !14
  br label %31, !llvm.loop !16

45:                                               ; preds = %36
  br label %46

46:                                               ; preds = %45, %29
  %47 = load i64, ptr %5, align 8, !tbaa !14
  %48 = add i64 %47, 1
  store i64 %48, ptr %5, align 8, !tbaa !14
  br label %14, !llvm.loop !18

49:                                               ; preds = %19
  %50 = call i32 (ptr, ...) @printf(ptr noundef @.str.36)
  store i32 1, ptr %6, align 4
  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
}

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"}
!18 = distinct !{!18, !17}


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

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

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

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

; Function Attrs: mustprogress uwtable
define dso_local noalias noundef ptr @_ZN12TPCCWorkload15threadInitOrderEPv(ptr nocapture noundef readonly %0) local_unnamed_addr #2 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
  %.not15 = icmp eq i32 %5, 0
  br i1 %.not15, label %._crit_edge, label %.lr.ph17

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

.lr.ph17:                                         ; preds = %1, %.loopexit
  %.01016 = phi i64 [ %17, %.loopexit ], [ 1, %1 ]
  %7 = tail call noundef i64 @_Z10wh_to_partm(i64 noundef %.01016)
  %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
  %.not11 = icmp ne i64 %10, %12
  %13 = load i32, ptr @g_dist_per_wh, align 4
  %.not1213 = icmp eq i32 %13, 0
  %or.cond = select i1 %.not11, i1 true, i1 %.not1213
  br i1 %or.cond, label %.loopexit, label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph17, %.lr.ph
  %.014 = phi i64 [ %14, %.lr.ph ], [ 1, %.lr.ph17 ]
  tail call void @_ZN12TPCCWorkload14init_tab_orderEimm(ptr noundef nonnull align 8 dereferenceable(296) %2, i32 noundef %4, i64 noundef %.014, i64 noundef %.01016)
  %14 = add nuw nsw i64 %.014, 1
  %15 = load i32, ptr @g_dist_per_wh, align 4, !tbaa !12
  %16 = zext i32 %15 to i64
  %.not12.not = icmp ult i64 %.014, %16
  br i1 %.not12.not, label %.lr.ph, label %.loopexit, !llvm.loop !13

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

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 = { "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" }

!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"}
!15 = distinct !{!15, !14}


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