; LLVM IR from pmwkaa/monotone :: monotone/runtime/lib (random)

; 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.timespec = type { i64, i64 }
%struct.Random = type { %struct.Spinlock, [2 x i64] }
%struct.Spinlock = type { i32 }

@.str = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @random_open(ptr noundef %0) #0 {
  %2 = alloca ptr, align 8
  %3 = alloca [2 x i64], align 16
  %4 = alloca i32, align 4
  %5 = alloca %struct.timespec, align 8
  %6 = alloca i64, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %3) #6
  call void @llvm.memset.p0.i64(ptr align 16 %3, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  %7 = call i32 @vfs_open(ptr noundef @.str, i32 noundef 0, i32 noundef 420)
  store i32 %7, ptr %4, align 4, !tbaa !9
  %8 = load i32, ptr %4, align 4, !tbaa !9
  %9 = icmp ne i32 %8, -1
  %10 = xor i1 %9, true
  %11 = xor i1 %10, true
  %12 = zext i1 %11 to i32
  %13 = sext i32 %12 to i64
  %14 = call i64 @llvm.expect.i64(i64 %13, i64 0)
  %15 = icmp ne i64 %14, 0
  br i1 %15, label %16, label %22

16:                                               ; preds = %1
  %17 = load i32, ptr %4, align 4, !tbaa !9
  %18 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 0
  %19 = call i64 @vfs_read(i32 noundef %17, ptr noundef %18, i64 noundef 16)
  %20 = load i32, ptr %4, align 4, !tbaa !9
  %21 = call i32 @vfs_close(i32 noundef %20)
  br label %22

22:                                               ; preds = %16, %1
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #6
  %23 = call i32 @clock_gettime(i32 noundef 1, ptr noundef %5) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  %24 = call i32 @getpid() #6
  %25 = call i32 @getuid() #6
  %26 = xor i32 %24, %25
  %27 = zext i32 %26 to i64
  %28 = getelementptr inbounds %struct.timespec, ptr %5, i32 0, i32 0
  %29 = load i64, ptr %28, align 8, !tbaa !11
  %30 = xor i64 %27, %29
  %31 = getelementptr inbounds %struct.timespec, ptr %5, i32 0, i32 1
  %32 = load i64, ptr %31, align 8, !tbaa !14
  %33 = xor i64 %30, %32
  store i64 %33, ptr %6, align 8, !tbaa !15
  %34 = load i64, ptr %6, align 8, !tbaa !15
  %35 = call i32 @rand() #6
  %36 = sext i32 %35 to i64
  %37 = xor i64 %34, %36
  %38 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 0
  %39 = load i64, ptr %38, align 16, !tbaa !15
  %40 = xor i64 %39, %37
  store i64 %40, ptr %38, align 16, !tbaa !15
  %41 = load i64, ptr %6, align 8, !tbaa !15
  %42 = call i32 @rand() #6
  %43 = sext i32 %42 to i64
  %44 = xor i64 %41, %43
  %45 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 1
  %46 = load i64, ptr %45, align 8, !tbaa !15
  %47 = xor i64 %46, %44
  store i64 %47, ptr %45, align 8, !tbaa !15
  %48 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 0
  %49 = load i64, ptr %48, align 16, !tbaa !15
  %50 = load ptr, ptr %2, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.Random, ptr %50, i32 0, i32 1
  %52 = getelementptr inbounds [2 x i64], ptr %51, i64 0, i64 0
  store i64 %49, ptr %52, align 8, !tbaa !15
  %53 = getelementptr inbounds [2 x i64], ptr %3, i64 0, i64 1
  %54 = load i64, ptr %53, align 8, !tbaa !15
  %55 = load ptr, ptr %2, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.Random, ptr %55, i32 0, i32 1
  %57 = getelementptr inbounds [2 x i64], ptr %56, i64 0, i64 1
  store i64 %54, ptr %57, align 8, !tbaa !15
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %3) #6
  ret void
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare i32 @vfs_open(ptr noundef, i32 noundef, i32 noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.expect.i64(i64, i64) #4

declare i64 @vfs_read(i32 noundef, ptr noundef, i64 noundef) #3

declare i32 @vfs_close(i32 noundef) #3

; Function Attrs: nounwind
declare i32 @clock_gettime(i32 noundef, ptr noundef) #5

; Function Attrs: nounwind
declare i32 @getpid() #5

; Function Attrs: nounwind
declare i32 @getuid() #5

; Function Attrs: nounwind
declare i32 @rand() #5

; 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 nosync nounwind willreturn memory(none) }
attributes #5 = { 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 #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, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !13, i64 0}
!12 = !{!"timespec", !13, i64 0, !13, i64 8}
!13 = !{!"long", !7, i64 0}
!14 = !{!12, !13, i64 8}
!15 = !{!13, !13, 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.timespec = type { i64, i64 }

@.str = external hidden unnamed_addr constant [13 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local void @random_open(ptr nocapture noundef writeonly %0) local_unnamed_addr #0 {
  %2 = alloca [2 x i64], align 16
  %3 = alloca %struct.timespec, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #5
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  %4 = tail call i32 @vfs_open(ptr noundef nonnull @.str, i32 noundef 0, i32 noundef 420) #5
  %.not = icmp eq i32 %4, -1
  br i1 %.not, label %8, label %5, !prof !5

5:                                                ; preds = %1
  %6 = call i64 @vfs_read(i32 noundef %4, ptr noundef nonnull %2, i64 noundef 16) #5
  %7 = call i32 @vfs_close(i32 noundef %4) #5
  br label %8

8:                                                ; preds = %5, %1
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #5
  %9 = call i32 @clock_gettime(i32 noundef 1, ptr noundef nonnull %3) #5
  %10 = call i32 @getpid() #5
  %11 = call i32 @getuid() #5
  %12 = xor i32 %11, %10
  %13 = zext i32 %12 to i64
  %14 = load i64, ptr %3, align 8, !tbaa !6
  %15 = xor i64 %14, %13
  %16 = getelementptr inbounds i8, ptr %3, i64 8
  %17 = load i64, ptr %16, align 8, !tbaa !11
  %18 = xor i64 %15, %17
  %19 = call i32 @rand() #5
  %20 = sext i32 %19 to i64
  %21 = load i64, ptr %2, align 16, !tbaa !12
  %22 = xor i64 %21, %20
  %23 = xor i64 %22, %18
  store i64 %23, ptr %2, align 16, !tbaa !12
  %24 = call i32 @rand() #5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds i8, ptr %2, i64 8
  %27 = load i64, ptr %26, align 8, !tbaa !12
  %28 = xor i64 %27, %25
  %29 = xor i64 %28, %18
  %30 = load i64, ptr %2, align 16, !tbaa !12
  %31 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 %30, ptr %31, align 8, !tbaa !12
  %32 = getelementptr inbounds i8, ptr %0, i64 16
  store i64 %29, ptr %32, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #5
  ret void
}

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

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

declare i32 @vfs_open(ptr noundef, i32 noundef, i32 noundef) local_unnamed_addr #3

declare i64 @vfs_read(i32 noundef, ptr noundef, i64 noundef) local_unnamed_addr #3

declare i32 @vfs_close(i32 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind
declare i32 @getpid() local_unnamed_addr #4

; Function Attrs: nounwind
declare i32 @getuid() local_unnamed_addr #4

; Function Attrs: nounwind
declare i32 @rand() local_unnamed_addr #4

; Function Attrs: mustprogress 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 }

!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 = !{!"branch_weights", !"expected", i32 2000, i32 1}
!6 = !{!7, !8, i64 0}
!7 = !{!"timespec", !8, i64 0, !8, i64 8}
!8 = !{!"long", !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!7, !8, i64 8}
!12 = !{!8, !8, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,LowerExpectIntrinsicPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,TailCallElimPass