; LLVM IR from leonfoks/coretran :: src/random (xorshift1024star)

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

@s = external dso_local global [16 x i64], align 16
@p = external dso_local global i32, align 4

; Function Attrs: nounwind uwtable
define dso_local i64 @next() #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %1) #2
  %3 = load i32, ptr @p, align 4, !tbaa !5
  %4 = sext i32 %3 to i64
  %5 = getelementptr inbounds [16 x i64], ptr @s, i64 0, i64 %4
  %6 = load i64, ptr %5, align 8, !tbaa !9
  store i64 %6, ptr %1, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #2
  %7 = load i32, ptr @p, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  %9 = and i32 %8, 15
  store i32 %9, ptr @p, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [16 x i64], ptr @s, i64 0, i64 %10
  %12 = load i64, ptr %11, align 8, !tbaa !9
  store i64 %12, ptr %2, align 8, !tbaa !9
  %13 = load i64, ptr %2, align 8, !tbaa !9
  %14 = shl i64 %13, 31
  %15 = load i64, ptr %2, align 8, !tbaa !9
  %16 = xor i64 %15, %14
  store i64 %16, ptr %2, align 8, !tbaa !9
  %17 = load i64, ptr %2, align 8, !tbaa !9
  %18 = load i64, ptr %1, align 8, !tbaa !9
  %19 = xor i64 %17, %18
  %20 = load i64, ptr %2, align 8, !tbaa !9
  %21 = lshr i64 %20, 11
  %22 = xor i64 %19, %21
  %23 = load i64, ptr %1, align 8, !tbaa !9
  %24 = lshr i64 %23, 30
  %25 = xor i64 %22, %24
  %26 = load i32, ptr @p, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [16 x i64], ptr @s, i64 0, i64 %27
  store i64 %25, ptr %28, align 8, !tbaa !9
  %29 = load i32, ptr @p, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [16 x i64], ptr @s, i64 0, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !9
  %33 = mul i64 %32, -7046029254386353133
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %1) #2
  ret i64 %33
}

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

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

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, 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"

@s = external dso_local local_unnamed_addr global [16 x i64], align 16
@p = external dso_local local_unnamed_addr global i32, align 4

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local i64 @next() local_unnamed_addr #0 {
  %1 = load i32, ptr @p, align 4, !tbaa !5
  %2 = sext i32 %1 to i64
  %3 = getelementptr inbounds [16 x i64], ptr @s, i64 0, i64 %2
  %4 = load i64, ptr %3, align 8, !tbaa !9
  %5 = add nsw i32 %1, 1
  %6 = and i32 %5, 15
  store i32 %6, ptr @p, align 4, !tbaa !5
  %7 = zext nneg i32 %6 to i64
  %8 = getelementptr inbounds [16 x i64], ptr @s, i64 0, i64 %7
  %9 = load i64, ptr %8, align 8, !tbaa !9
  %10 = shl i64 %9, 31
  %11 = xor i64 %10, %9
  %12 = lshr i64 %11, 11
  %13 = lshr i64 %4, 30
  %14 = xor i64 %13, %12
  %15 = xor i64 %14, %4
  %16 = xor i64 %15, %11
  store i64 %16, ptr %8, align 8, !tbaa !9
  %17 = mul i64 %16, -7046029254386353133
  ret i64 %17
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) 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, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass