; LLVM IR from buresjan/optim_lbm :: nomad/src/Math/RandomPickup.ll (ZN9NOMAD_4_312RandomPickup6pickupEv)

; 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.NOMAD_4_3::RandomPickup" = type { %"class.NOMAD_4_3::Uncopyable", i64, i64, ptr }
%"class.NOMAD_4_3::Uncopyable" = type { ptr }

; 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 noundef i64 @_ZN9NOMAD_4_312RandomPickup6pickupEv(ptr noundef nonnull align 8 dereferenceable(32) %0) #1 align 2 {
  %2 = alloca i64, align 8
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8
  %7 = getelementptr inbounds %"class.NOMAD_4_3::RandomPickup", ptr %6, i32 0, i32 2
  %8 = load i64, ptr %7, align 8, !tbaa !9
  %9 = icmp eq i64 %8, 0
  br i1 %9, label %10, label %11

10:                                               ; preds = %1
  store i64 0, ptr %2, align 8
  br label %51

11:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %12 = call noundef i32 @_ZN9NOMAD_4_33RNG4randEv()
  %13 = zext i32 %12 to i64
  %14 = getelementptr inbounds %"class.NOMAD_4_3::RandomPickup", ptr %6, i32 0, i32 2
  %15 = load i64, ptr %14, align 8, !tbaa !9
  %16 = urem i64 %13, %15
  store i64 %16, ptr %4, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %17 = getelementptr inbounds %"class.NOMAD_4_3::RandomPickup", ptr %6, i32 0, i32 3
  %18 = load ptr, ptr %17, align 8, !tbaa !14
  %19 = load i64, ptr %4, align 8, !tbaa !13
  %20 = getelementptr inbounds i64, ptr %18, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !13
  store i64 %21, ptr %5, align 8, !tbaa !13
  %22 = load i64, ptr %4, align 8, !tbaa !13
  %23 = getelementptr inbounds %"class.NOMAD_4_3::RandomPickup", ptr %6, i32 0, i32 2
  %24 = load i64, ptr %23, align 8, !tbaa !9
  %25 = sub i64 %24, 1
  %26 = icmp ult i64 %22, %25
  br i1 %26, label %27, label %46

27:                                               ; preds = %11
  %28 = getelementptr inbounds %"class.NOMAD_4_3::RandomPickup", ptr %6, i32 0, i32 3
  %29 = load ptr, ptr %28, align 8, !tbaa !14
  %30 = getelementptr inbounds %"class.NOMAD_4_3::RandomPickup", ptr %6, i32 0, i32 2
  %31 = load i64, ptr %30, align 8, !tbaa !9
  %32 = sub i64 %31, 1
  %33 = getelementptr inbounds i64, ptr %29, i64 %32
  %34 = load i64, ptr %33, align 8, !tbaa !13
  %35 = getelementptr inbounds %"class.NOMAD_4_3::RandomPickup", ptr %6, i32 0, i32 3
  %36 = load ptr, ptr %35, align 8, !tbaa !14
  %37 = load i64, ptr %4, align 8, !tbaa !13
  %38 = getelementptr inbounds i64, ptr %36, i64 %37
  store i64 %34, ptr %38, align 8, !tbaa !13
  %39 = load i64, ptr %5, align 8, !tbaa !13
  %40 = getelementptr inbounds %"class.NOMAD_4_3::RandomPickup", ptr %6, i32 0, i32 3
  %41 = load ptr, ptr %40, align 8, !tbaa !14
  %42 = getelementptr inbounds %"class.NOMAD_4_3::RandomPickup", ptr %6, i32 0, i32 2
  %43 = load i64, ptr %42, align 8, !tbaa !9
  %44 = sub i64 %43, 1
  %45 = getelementptr inbounds i64, ptr %41, i64 %44
  store i64 %39, ptr %45, align 8, !tbaa !13
  br label %46

46:                                               ; preds = %27, %11
  %47 = getelementptr inbounds %"class.NOMAD_4_3::RandomPickup", ptr %6, i32 0, i32 2
  %48 = load i64, ptr %47, align 8, !tbaa !9
  %49 = add i64 %48, -1
  store i64 %49, ptr %47, align 8, !tbaa !9
  %50 = load i64, ptr %5, align 8, !tbaa !13
  store i64 %50, ptr %2, align 8
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %51

51:                                               ; preds = %46, %10
  %52 = load i64, ptr %2, align 8
  ret i64 %52
}

declare noundef i32 @_ZN9NOMAD_4_33RNG4randEv() #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 = { "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, !12, i64 16}
!10 = !{!"_ZTSN9NOMAD_4_312RandomPickupE", !11, i64 0, !12, i64 8, !12, i64 16, !6, i64 24}
!11 = !{!"_ZTSN9NOMAD_4_310UncopyableE"}
!12 = !{!"long", !7, i64 0}
!13 = !{!12, !12, i64 0}
!14 = !{!10, !6, i64 24}


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

; Function Attrs: mustprogress uwtable
define dso_local noundef i64 @_ZN9NOMAD_4_312RandomPickup6pickupEv(ptr nocapture noundef nonnull align 8 dereferenceable(32) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load i64, ptr %2, align 8, !tbaa !5
  %4 = icmp eq i64 %3, 0
  br i1 %4, label %23, label %5

5:                                                ; preds = %1
  %6 = tail call noundef i32 @_ZN9NOMAD_4_33RNG4randEv()
  %7 = zext i32 %6 to i64
  %8 = load i64, ptr %2, align 8, !tbaa !5
  %9 = urem i64 %7, %8
  %10 = getelementptr inbounds i8, ptr %0, i64 24
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %12 = getelementptr inbounds i64, ptr %11, i64 %9
  %13 = load i64, ptr %12, align 8, !tbaa !13
  %14 = add i64 %8, -1
  %15 = icmp ult i64 %9, %14
  br i1 %15, label %16, label %22

16:                                               ; preds = %5
  %17 = getelementptr inbounds i64, ptr %11, i64 %14
  %18 = load i64, ptr %17, align 8, !tbaa !13
  store i64 %18, ptr %12, align 8, !tbaa !13
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %20 = getelementptr i64, ptr %11, i64 %19
  %21 = getelementptr i8, ptr %20, i64 -8
  store i64 %13, ptr %21, align 8, !tbaa !13
  %.pre = load i64, ptr %2, align 8, !tbaa !5
  %.pre7 = add i64 %.pre, -1
  br label %22

22:                                               ; preds = %16, %5
  %.pre-phi = phi i64 [ %.pre7, %16 ], [ %14, %5 ]
  store i64 %.pre-phi, ptr %2, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %1, %22
  %.0 = phi i64 [ %13, %22 ], [ 0, %1 ]
  ret i64 %.0
}

declare noundef i32 @_ZN9NOMAD_4_33RNG4randEv() local_unnamed_addr #1

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

!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, !8, i64 16}
!6 = !{!"_ZTSN9NOMAD_4_312RandomPickupE", !7, i64 0, !8, i64 8, !8, i64 16, !11, i64 24}
!7 = !{!"_ZTSN9NOMAD_4_310UncopyableE"}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C++ TBAA"}
!11 = !{!"any pointer", !9, i64 0}
!12 = !{!6, !11, i64 24}
!13 = !{!8, !8, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass