; LLVM IR from openssl/openssl :: test/testutil (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"

@test_random.pos = external hidden global i32, align 4
@test_random_state = external hidden global [31 x i32], align 16

; Function Attrs: nounwind uwtable
define dso_local i32 @test_random() #0 {
  %1 = load i32, ptr @test_random.pos, align 4, !tbaa !5
  %2 = icmp eq i32 %1, 31
  br i1 %2, label %3, label %4

3:                                                ; preds = %0
  store i32 0, ptr @test_random.pos, align 4, !tbaa !5
  br label %4

4:                                                ; preds = %3, %0
  %5 = load i32, ptr @test_random.pos, align 4, !tbaa !5
  %6 = add i32 %5, 28
  %7 = urem i32 %6, 31
  %8 = zext i32 %7 to i64
  %9 = getelementptr inbounds [31 x i32], ptr @test_random_state, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = load i32, ptr @test_random.pos, align 4, !tbaa !5
  %12 = zext i32 %11 to i64
  %13 = getelementptr inbounds [31 x i32], ptr @test_random_state, i64 0, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !5
  %15 = add i32 %14, %10
  store i32 %15, ptr %13, align 4, !tbaa !5
  %16 = load i32, ptr @test_random.pos, align 4, !tbaa !5
  %17 = add i32 %16, 1
  store i32 %17, ptr @test_random.pos, align 4, !tbaa !5
  %18 = zext i32 %16 to i64
  %19 = getelementptr inbounds [31 x i32], ptr @test_random_state, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = udiv i32 %20, 2
  ret i32 %21
}

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

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


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

@test_random.pos = external hidden local_unnamed_addr global i32, align 4
@test_random_state = external hidden local_unnamed_addr global [31 x i32], align 16

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(readwrite, argmem: none, inaccessiblemem: none) uwtable
define dso_local range(i32 0, -2147483648) i32 @test_random() local_unnamed_addr #0 {
  %1 = load i32, ptr @test_random.pos, align 4, !tbaa !5
  %2 = icmp eq i32 %1, 31
  %spec.select = select i1 %2, i32 0, i32 %1
  %3 = add i32 %spec.select, 28
  %4 = urem i32 %3, 31
  %5 = zext nneg i32 %4 to i64
  %6 = getelementptr inbounds [31 x i32], ptr @test_random_state, i64 0, i64 %5
  %7 = load i32, ptr %6, align 4, !tbaa !5
  %8 = zext i32 %spec.select to i64
  %9 = getelementptr inbounds [31 x i32], ptr @test_random_state, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = add i32 %10, %7
  store i32 %11, ptr %9, align 4, !tbaa !5
  %12 = add i32 %spec.select, 1
  store i32 %12, ptr @test_random.pos, align 4, !tbaa !5
  %13 = lshr i32 %11, 1
  ret i32 %13
}

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


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InstCombinePass,PostOrderFunctionAttrsPass,SimplifyCFGPass