; LLVM IR from taichi-dev/taichi :: taichi/runtime/llvm/runtime_module (runtime)

; 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.RuntimeContext = type { ptr, ptr, i32, ptr }
%struct.LLVMRuntime = type { %struct.PreallocatedMemoryChunk, %struct.PreallocatedMemoryChunk, ptr, ptr, ptr, ptr, ptr, [512 x ptr], [512 x i64], ptr, ptr, [1024 x ptr], [1024 x ptr], [1024 x ptr], ptr, ptr, ptr, ptr, ptr, [2048 x i8], [32 x i64], i32, i64, ptr, i32, i32, i64 }
%struct.PreallocatedMemoryChunk = type { ptr, ptr, i64 }
%struct.RandState = type { i32, i32, i32, i32, 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 i32 @linear_thread_idx(ptr noundef) #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local i32 @rand_u32(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #2
  %9 = load ptr, ptr %2, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.RuntimeContext, ptr %9, i32 0, i32 1
  %11 = load ptr, ptr %10, align 8, !tbaa !9
  %12 = getelementptr inbounds %struct.LLVMRuntime, ptr %11, i32 0, i32 15
  %13 = load ptr, ptr %12, align 8, !tbaa !12
  %14 = load ptr, ptr %2, align 8, !tbaa !5
  %15 = call i32 @linear_thread_idx(ptr noundef %14)
  %16 = sext i32 %15 to i64
  %17 = getelementptr inbounds %struct.RandState, ptr %13, i64 %16
  store ptr %17, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #2
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.RandState, ptr %18, i32 0, i32 0
  store ptr %19, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #2
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.RandState, ptr %20, i32 0, i32 1
  store ptr %21, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #2
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.RandState, ptr %22, i32 0, i32 2
  store ptr %23, ptr %6, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  %24 = load ptr, ptr %3, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.RandState, ptr %24, i32 0, i32 3
  store ptr %25, ptr %7, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = load i32, ptr %26, align 4, !tbaa !16
  %28 = load ptr, ptr %4, align 8, !tbaa !5
  %29 = load i32, ptr %28, align 4, !tbaa !16
  %30 = shl i32 %29, 11
  %31 = xor i32 %27, %30
  store i32 %31, ptr %8, align 4, !tbaa !16
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = load i32, ptr %32, align 4, !tbaa !16
  %34 = load ptr, ptr %4, align 8, !tbaa !5
  store i32 %33, ptr %34, align 4, !tbaa !16
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = load i32, ptr %35, align 4, !tbaa !16
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %36, ptr %37, align 4, !tbaa !16
  %38 = load ptr, ptr %7, align 8, !tbaa !5
  %39 = load i32, ptr %38, align 4, !tbaa !16
  %40 = load ptr, ptr %6, align 8, !tbaa !5
  store i32 %39, ptr %40, align 4, !tbaa !16
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i32, ptr %41, align 4, !tbaa !16
  %43 = load ptr, ptr %7, align 8, !tbaa !5
  %44 = load i32, ptr %43, align 4, !tbaa !16
  %45 = lshr i32 %44, 19
  %46 = xor i32 %42, %45
  %47 = load i32, ptr %8, align 4, !tbaa !16
  %48 = load i32, ptr %8, align 4, !tbaa !16
  %49 = lshr i32 %48, 8
  %50 = xor i32 %47, %49
  %51 = xor i32 %46, %50
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  store i32 %51, ptr %52, align 4, !tbaa !16
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = load i32, ptr %53, align 4, !tbaa !16
  %55 = mul i32 %54, 1000000007
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #2
  ret i32 %55
}

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, !6, i64 8}
!10 = !{!"_ZTS14RuntimeContext", !6, i64 0, !6, i64 8, !11, i64 16, !6, i64 24}
!11 = !{!"int", !7, i64 0}
!12 = !{!13, !6, i64 32880}
!13 = !{!"_ZTS11LLVMRuntime", !14, i64 0, !14, i64 24, !6, i64 48, !6, i64 56, !6, i64 64, !6, i64 72, !6, i64 80, !7, i64 88, !7, i64 4184, !6, i64 8280, !6, i64 8288, !7, i64 8296, !7, i64 16488, !7, i64 24680, !6, i64 32872, !6, i64 32880, !6, i64 32888, !6, i64 32896, !6, i64 32904, !7, i64 32912, !7, i64 34960, !11, i64 35216, !15, i64 35224, !6, i64 35232, !11, i64 35240, !11, i64 35244, !15, i64 35248}
!14 = !{!"_ZTS23PreallocatedMemoryChunk", !6, i64 0, !6, i64 8, !15, i64 16}
!15 = !{!"long", !7, i64 0}
!16 = !{!11, !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"

%struct.RandState = type { i32, i32, i32, i32, i32 }

; Function Attrs: mustprogress nounwind uwtable
declare dso_local i32 @linear_thread_idx(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
define dso_local i32 @rand_u32(ptr noundef %0) local_unnamed_addr #0 {
  %2 = getelementptr inbounds i8, ptr %0, i64 8
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 32880
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %6 = tail call i32 @linear_thread_idx(ptr noundef %0)
  %7 = sext i32 %6 to i64
  %8 = getelementptr inbounds %struct.RandState, ptr %5, i64 %7
  %9 = getelementptr inbounds i8, ptr %8, i64 4
  %10 = getelementptr inbounds i8, ptr %8, i64 8
  %11 = getelementptr inbounds i8, ptr %8, i64 12
  %12 = load i32, ptr %8, align 4, !tbaa !15
  %13 = shl i32 %12, 11
  %14 = xor i32 %13, %12
  %15 = load <2 x i32>, ptr %9, align 4, !tbaa !15
  store <2 x i32> %15, ptr %8, align 4, !tbaa !15
  %16 = load i32, ptr %11, align 4, !tbaa !15
  store i32 %16, ptr %10, align 4, !tbaa !15
  %17 = lshr i32 %16, 19
  %18 = lshr i32 %14, 8
  %19 = xor i32 %18, %17
  %20 = xor i32 %19, %14
  %21 = xor i32 %20, %16
  store i32 %21, ptr %11, align 4, !tbaa !15
  %22 = mul i32 %21, 1000000007
  ret i32 %22
}

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 8}
!6 = !{!"_ZTS14RuntimeContext", !7, i64 0, !7, i64 8, !10, i64 16, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!12, !7, i64 32880}
!12 = !{!"_ZTS11LLVMRuntime", !13, i64 0, !13, i64 24, !7, i64 48, !7, i64 56, !7, i64 64, !7, i64 72, !7, i64 80, !8, i64 88, !8, i64 4184, !7, i64 8280, !7, i64 8288, !8, i64 8296, !8, i64 16488, !8, i64 24680, !7, i64 32872, !7, i64 32880, !7, i64 32888, !7, i64 32896, !7, i64 32904, !8, i64 32912, !8, i64 34960, !10, i64 35216, !14, i64 35224, !7, i64 35232, !10, i64 35240, !10, i64 35244, !14, i64 35248}
!13 = !{!"_ZTS23PreallocatedMemoryChunk", !7, i64 0, !7, i64 8, !14, i64 16}
!14 = !{!"long", !8, i64 0}
!15 = !{!10, !10, i64 0}


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