; LLVM IR from mitdbg/deneva :: concurrency_control/row_lock.ll (ZN8Row_lock4initEP5row_t)

; 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.mem_alloc = type { i8 }
%class.Row_lock = type { ptr, i8, ptr, i32, i32, i32, ptr, i64, ptr, ptr, i64, i64 }

@mem_allocator = external global %class.mem_alloc, align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8Row_lock4initEP5row_t(ptr noundef nonnull align 8 dereferenceable(88) %0, ptr noundef %1) #0 align 2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = load ptr, ptr %4, align 8, !tbaa !5
  %8 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 2
  store ptr %7, ptr %8, align 8, !tbaa !9
  %9 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 7
  store i64 1, ptr %9, align 8, !tbaa !15
  %10 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 6
  store ptr null, ptr %10, align 8, !tbaa !16
  %11 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 7
  %12 = load i64, ptr %11, align 8, !tbaa !15
  %13 = mul i64 8, %12
  %14 = call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef %13)
  %15 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 6
  store ptr %14, ptr %15, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #5
  store i64 0, ptr %5, align 8, !tbaa !17
  br label %16

16:                                               ; preds = %27, %2
  %17 = load i64, ptr %5, align 8, !tbaa !17
  %18 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 7
  %19 = load i64, ptr %18, align 8, !tbaa !15
  %20 = icmp ult i64 %17, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #5
  br label %30

22:                                               ; preds = %16
  %23 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 6
  %24 = load ptr, ptr %23, align 8, !tbaa !16
  %25 = load i64, ptr %5, align 8, !tbaa !17
  %26 = getelementptr inbounds ptr, ptr %24, i64 %25
  store ptr null, ptr %26, align 8, !tbaa !5
  br label %27

27:                                               ; preds = %22
  %28 = load i64, ptr %5, align 8, !tbaa !17
  %29 = add i64 %28, 1
  store i64 %29, ptr %5, align 8, !tbaa !17
  br label %16, !llvm.loop !18

30:                                               ; preds = %21
  %31 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 8
  store ptr null, ptr %31, align 8, !tbaa !20
  %32 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 9
  store ptr null, ptr %32, align 8, !tbaa !21
  %33 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 4
  store i32 0, ptr %33, align 4, !tbaa !22
  %34 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 5
  store i32 0, ptr %34, align 8, !tbaa !23
  %35 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 10
  store i64 0, ptr %35, align 8, !tbaa !24
  %36 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 40) #6
  %37 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 0
  store ptr %36, ptr %37, align 8, !tbaa !25
  %38 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 0
  %39 = load ptr, ptr %38, align 8, !tbaa !25
  %40 = call i32 @pthread_mutex_init(ptr noundef %39, ptr noundef null) #5
  %41 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 3
  store i32 2, ptr %41, align 8, !tbaa !26
  %42 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 1
  store i8 0, ptr %42, align 8, !tbaa !27
  %43 = getelementptr inbounds %class.Row_lock, ptr %6, i32 0, i32 11
  store i64 0, ptr %43, align 8, !tbaa !28
  ret void
}

declare noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1), i64 noundef) #1

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_init(ptr noundef, ptr noundef) #4

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 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 #5 = { nounwind }
attributes #6 = { 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, !6, i64 16}
!10 = !{!"_ZTS8Row_lock", !6, i64 0, !11, i64 8, !6, i64 16, !12, i64 24, !13, i64 28, !13, i64 32, !6, i64 40, !14, i64 48, !6, i64 56, !6, i64 64, !14, i64 72, !14, i64 80}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"_ZTS6lock_t", !7, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = !{!"long", !7, i64 0}
!15 = !{!10, !14, i64 48}
!16 = !{!10, !6, i64 40}
!17 = !{!14, !14, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!10, !6, i64 56}
!21 = !{!10, !6, i64 64}
!22 = !{!10, !13, i64 28}
!23 = !{!10, !13, i64 32}
!24 = !{!10, !14, i64 72}
!25 = !{!10, !6, i64 0}
!26 = !{!10, !12, i64 24}
!27 = !{!10, !11, i64 8}
!28 = !{!10, !14, i64 80}


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

%class.mem_alloc = type { i8 }

@mem_allocator = external global %class.mem_alloc, align 1

; Function Attrs: mustprogress uwtable
define dso_local void @_ZN8Row_lock4initEP5row_t(ptr nocapture noundef nonnull align 8 dereferenceable(88) %0, ptr noundef %1) local_unnamed_addr #0 align 2 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %1, ptr %3, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 48
  store i64 1, ptr %4, align 8, !tbaa !14
  %5 = getelementptr inbounds i8, ptr %0, i64 40
  store ptr null, ptr %5, align 8, !tbaa !15
  %6 = tail call noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1) @mem_allocator, i64 noundef 8)
  store ptr %6, ptr %5, align 8, !tbaa !15
  %7 = load i64, ptr %4, align 8, !tbaa !14
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %2
  %xtraiter = and i64 %7, 3
  %8 = icmp ult i64 %7, 4
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %7, -4
  br label %.lr.ph

._crit_edge.loopexit.unr-lcssa:                   ; preds = %.lr.ph, %.lr.ph.preheader
  %.04.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %31, %.lr.ph ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil
  %.04.epil = phi i64 [ %11, %.lr.ph.epil ], [ %.04.unr, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.epil ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %9 = load ptr, ptr %5, align 8, !tbaa !15
  %10 = getelementptr inbounds ptr, ptr %9, i64 %.04.epil
  store ptr null, ptr %10, align 8, !tbaa !16
  %11 = add nuw i64 %.04.epil, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.lr.ph.epil, !llvm.loop !17

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.lr.ph.epil, %2
  %12 = getelementptr inbounds i8, ptr %0, i64 56
  %13 = getelementptr inbounds i8, ptr %0, i64 28
  store i32 0, ptr %13, align 4, !tbaa !19
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  store i32 0, ptr %14, align 8, !tbaa !20
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(24) %12, i8 0, i64 24, i1 false)
  %15 = tail call noalias noundef nonnull dereferenceable(40) ptr @_Znwm(i64 noundef 40) #5
  store ptr %15, ptr %0, align 8, !tbaa !21
  %16 = tail call i32 @pthread_mutex_init(ptr noundef nonnull %15, ptr noundef null) #6
  %17 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 2, ptr %17, align 8, !tbaa !22
  %18 = getelementptr inbounds i8, ptr %0, i64 8
  store i8 0, ptr %18, align 8, !tbaa !23
  %19 = getelementptr inbounds i8, ptr %0, i64 80
  store i64 0, ptr %19, align 8, !tbaa !24
  ret void

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %.04 = phi i64 [ 0, %.lr.ph.preheader.new ], [ %31, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.3, %.lr.ph ]
  %20 = load ptr, ptr %5, align 8, !tbaa !15
  %21 = getelementptr inbounds ptr, ptr %20, i64 %.04
  store ptr null, ptr %21, align 8, !tbaa !16
  %22 = or disjoint i64 %.04, 1
  %23 = load ptr, ptr %5, align 8, !tbaa !15
  %24 = getelementptr inbounds ptr, ptr %23, i64 %22
  store ptr null, ptr %24, align 8, !tbaa !16
  %25 = or disjoint i64 %.04, 2
  %26 = load ptr, ptr %5, align 8, !tbaa !15
  %27 = getelementptr inbounds ptr, ptr %26, i64 %25
  store ptr null, ptr %27, align 8, !tbaa !16
  %28 = or disjoint i64 %.04, 3
  %29 = load ptr, ptr %5, align 8, !tbaa !15
  %30 = getelementptr inbounds ptr, ptr %29, i64 %28
  store ptr null, ptr %30, align 8, !tbaa !16
  %31 = add nuw i64 %.04, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph, !llvm.loop !25
}

declare noundef ptr @_ZN9mem_alloc5allocEm(ptr noundef nonnull align 1 dereferenceable(1), i64 noundef) local_unnamed_addr #1

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

; Function Attrs: nounwind
declare i32 @pthread_mutex_init(ptr noundef, ptr noundef) local_unnamed_addr #3

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

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 = { "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 = { 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 #4 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !7, i64 16}
!6 = !{!"_ZTS8Row_lock", !7, i64 0, !10, i64 8, !7, i64 16, !11, i64 24, !12, i64 28, !12, i64 32, !7, i64 40, !13, i64 48, !7, i64 56, !7, i64 64, !13, i64 72, !13, i64 80}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"bool", !8, i64 0}
!11 = !{!"_ZTS6lock_t", !8, i64 0}
!12 = !{!"int", !8, i64 0}
!13 = !{!"long", !8, i64 0}
!14 = !{!6, !13, i64 48}
!15 = !{!6, !7, i64 40}
!16 = !{!7, !7, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.unroll.disable"}
!19 = !{!6, !12, i64 28}
!20 = !{!6, !12, i64 32}
!21 = !{!6, !7, i64 0}
!22 = !{!6, !11, i64 24}
!23 = !{!6, !10, i64 8}
!24 = !{!6, !13, i64 80}
!25 = distinct !{!25, !26}
!26 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,MemCpyOptPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass