; LLVM IR from idmillington/cyclone-physics :: src/random.ll (ZN7cyclone6Random10randomBitsEv)

; 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.cyclone::Random" = type { i32, i32, [17 x i32] }

; 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 i32 @_ZN7cyclone6Random4rotlEjj(ptr noundef nonnull align 4 dereferenceable(76), i32 noundef, i32 noundef) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN7cyclone6Random10randomBitsEv(ptr noundef nonnull align 4 dereferenceable(76) %0) #1 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  %4 = load ptr, ptr %2, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #2
  %5 = getelementptr inbounds %"class.cyclone::Random", ptr %4, i32 0, i32 2
  %6 = getelementptr inbounds %"class.cyclone::Random", ptr %4, i32 0, i32 1
  %7 = load i32, ptr %6, align 4, !tbaa !9
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [17 x i32], ptr %5, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !12
  %11 = call noundef i32 @_ZN7cyclone6Random4rotlEjj(ptr noundef nonnull align 4 dereferenceable(76) %4, i32 noundef %10, i32 noundef 13)
  %12 = getelementptr inbounds %"class.cyclone::Random", ptr %4, i32 0, i32 2
  %13 = getelementptr inbounds %"class.cyclone::Random", ptr %4, i32 0, i32 0
  %14 = load i32, ptr %13, align 4, !tbaa !13
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [17 x i32], ptr %12, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !12
  %18 = call noundef i32 @_ZN7cyclone6Random4rotlEjj(ptr noundef nonnull align 4 dereferenceable(76) %4, i32 noundef %17, i32 noundef 9)
  %19 = add i32 %11, %18
  %20 = getelementptr inbounds %"class.cyclone::Random", ptr %4, i32 0, i32 2
  %21 = getelementptr inbounds %"class.cyclone::Random", ptr %4, i32 0, i32 0
  %22 = load i32, ptr %21, align 4, !tbaa !13
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [17 x i32], ptr %20, i64 0, i64 %23
  store i32 %19, ptr %24, align 4, !tbaa !12
  store i32 %19, ptr %3, align 4, !tbaa !12
  %25 = getelementptr inbounds %"class.cyclone::Random", ptr %4, i32 0, i32 0
  %26 = load i32, ptr %25, align 4, !tbaa !13
  %27 = add nsw i32 %26, -1
  store i32 %27, ptr %25, align 4, !tbaa !13
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %31

29:                                               ; preds = %1
  %30 = getelementptr inbounds %"class.cyclone::Random", ptr %4, i32 0, i32 0
  store i32 16, ptr %30, align 4, !tbaa !13
  br label %31

31:                                               ; preds = %29, %1
  %32 = getelementptr inbounds %"class.cyclone::Random", ptr %4, i32 0, i32 1
  %33 = load i32, ptr %32, align 4, !tbaa !9
  %34 = add nsw i32 %33, -1
  store i32 %34, ptr %32, align 4, !tbaa !9
  %35 = icmp slt i32 %34, 0
  br i1 %35, label %36, label %38

36:                                               ; preds = %31
  %37 = getelementptr inbounds %"class.cyclone::Random", ptr %4, i32 0, i32 1
  store i32 16, ptr %37, align 4, !tbaa !9
  br label %38

38:                                               ; preds = %36, %31
  %39 = load i32, ptr %3, align 4, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #2
  ret i32 %39
}

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 = { 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, !11, i64 4}
!10 = !{!"_ZTSN7cyclone6RandomE", !11, i64 0, !11, i64 4, !7, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!11, !11, i64 0}
!13 = !{!10, !11, i64 0}


; 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 nounwind uwtable
declare dso_local noundef i32 @_ZN7cyclone6Random4rotlEjj(ptr noundef nonnull align 4 dereferenceable(76), i32 noundef, i32 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef i32 @_ZN7cyclone6Random10randomBitsEv(ptr noundef nonnull align 4 dereferenceable(76) %0) local_unnamed_addr #0 align 2 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = getelementptr inbounds i8, ptr %0, i64 4
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  %6 = getelementptr inbounds [17 x i32], ptr %2, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !10
  %8 = tail call noundef i32 @_ZN7cyclone6Random4rotlEjj(ptr noundef nonnull align 4 dereferenceable(76) %0, i32 noundef %7, i32 noundef 13)
  %9 = load i32, ptr %0, align 4, !tbaa !11
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [17 x i32], ptr %2, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !10
  %13 = tail call noundef i32 @_ZN7cyclone6Random4rotlEjj(ptr noundef nonnull align 4 dereferenceable(76) %0, i32 noundef %12, i32 noundef 9)
  %14 = add i32 %13, %8
  %15 = load i32, ptr %0, align 4, !tbaa !11
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds [17 x i32], ptr %2, i64 0, i64 %16
  store i32 %14, ptr %17, align 4, !tbaa !10
  %18 = load <2 x i32>, ptr %0, align 4, !tbaa !10
  %19 = add nsw <2 x i32> %18, <i32 -1, i32 -1>
  %20 = icmp slt <2 x i32> %18, <i32 1, i32 1>
  %21 = select <2 x i1> %20, <2 x i32> <i32 16, i32 16>, <2 x i32> %19
  store <2 x i32> %21, ptr %0, align 4, !tbaa !10
  ret i32 %14
}

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

!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 4}
!6 = !{!"_ZTSN7cyclone6RandomE", !7, i64 0, !7, i64 4, !8, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass