; LLVM IR from vteromero/VTEnc :: tests/tools (tinymt32)

; 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.TINYMT32_T = type { [4 x i32], i32, i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local void @tinymt32_init(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !9
  %7 = load i32, ptr %4, align 4, !tbaa !9
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.TINYMT32_T, ptr %8, i32 0, i32 0
  %10 = getelementptr inbounds [4 x i32], ptr %9, i64 0, i64 0
  store i32 %7, ptr %10, align 4, !tbaa !9
  %11 = load ptr, ptr %3, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.TINYMT32_T, ptr %11, i32 0, i32 1
  %13 = load i32, ptr %12, align 4, !tbaa !11
  %14 = load ptr, ptr %3, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.TINYMT32_T, ptr %14, i32 0, i32 0
  %16 = getelementptr inbounds [4 x i32], ptr %15, i64 0, i64 1
  store i32 %13, ptr %16, align 4, !tbaa !9
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TINYMT32_T, ptr %17, i32 0, i32 2
  %19 = load i32, ptr %18, align 4, !tbaa !13
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.TINYMT32_T, ptr %20, i32 0, i32 0
  %22 = getelementptr inbounds [4 x i32], ptr %21, i64 0, i64 2
  store i32 %19, ptr %22, align 4, !tbaa !9
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.TINYMT32_T, ptr %23, i32 0, i32 3
  %25 = load i32, ptr %24, align 4, !tbaa !14
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.TINYMT32_T, ptr %26, i32 0, i32 0
  %28 = getelementptr inbounds [4 x i32], ptr %27, i64 0, i64 3
  store i32 %25, ptr %28, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  store i32 1, ptr %5, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %63, %2
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = icmp slt i32 %30, 8
  br i1 %31, label %33, label %32

32:                                               ; preds = %29
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  br label %66

33:                                               ; preds = %29
  %34 = load i32, ptr %5, align 4, !tbaa !9
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = getelementptr inbounds %struct.TINYMT32_T, ptr %35, i32 0, i32 0
  %37 = load i32, ptr %5, align 4, !tbaa !9
  %38 = sub nsw i32 %37, 1
  %39 = and i32 %38, 3
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [4 x i32], ptr %36, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.TINYMT32_T, ptr %43, i32 0, i32 0
  %45 = load i32, ptr %5, align 4, !tbaa !9
  %46 = sub nsw i32 %45, 1
  %47 = and i32 %46, 3
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [4 x i32], ptr %44, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !9
  %51 = lshr i32 %50, 30
  %52 = xor i32 %42, %51
  %53 = mul i32 1812433253, %52
  %54 = add i32 %34, %53
  %55 = load ptr, ptr %3, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.TINYMT32_T, ptr %55, i32 0, i32 0
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = and i32 %57, 3
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [4 x i32], ptr %56, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !9
  %62 = xor i32 %61, %54
  store i32 %62, ptr %60, align 4, !tbaa !9
  br label %63

63:                                               ; preds = %33
  %64 = load i32, ptr %5, align 4, !tbaa !9
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %5, align 4, !tbaa !9
  br label %29, !llvm.loop !15

66:                                               ; preds = %32
  %67 = load ptr, ptr %3, align 8, !tbaa !5
  call void @period_certification(ptr noundef %67)
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !9
  br label %68

68:                                               ; preds = %74, %66
  %69 = load i32, ptr %6, align 4, !tbaa !9
  %70 = icmp slt i32 %69, 8
  br i1 %70, label %72, label %71

71:                                               ; preds = %68
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %77

72:                                               ; preds = %68
  %73 = load ptr, ptr %3, align 8, !tbaa !5
  call void @tinymt32_next_state(ptr noundef %73)
  br label %74

74:                                               ; preds = %72
  %75 = load i32, ptr %6, align 4, !tbaa !9
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %6, align 4, !tbaa !9
  br label %68, !llvm.loop !17

77:                                               ; preds = %71
  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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
declare hidden void @period_certification(ptr noundef) #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @tinymt32_next_state(ptr noundef) #2

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 = { inlinehint 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 #3 = { 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, !10, i64 16}
!12 = !{!"TINYMT32_T", !7, i64 0, !10, i64 16, !10, i64 20, !10, i64 24}
!13 = !{!12, !10, i64 20}
!14 = !{!12, !10, i64 24}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}


; 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: nounwind uwtable
define dso_local void @tinymt32_init(ptr noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  %4 = load i32, ptr %3, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 4
  %6 = getelementptr inbounds i8, ptr %0, i64 20
  %7 = load i32, ptr %6, align 4, !tbaa !10
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  %9 = getelementptr inbounds i8, ptr %0, i64 24
  %10 = load i32, ptr %9, align 4, !tbaa !11
  %11 = getelementptr inbounds i8, ptr %0, i64 12
  %12 = lshr i32 %1, 30
  %13 = xor i32 %12, %1
  %14 = mul i32 %13, 1812433253
  %15 = add i32 %14, 1
  %16 = xor i32 %15, %4
  %17 = lshr i32 %16, 30
  %18 = xor i32 %17, %16
  %19 = mul i32 %18, 1812433253
  %20 = add i32 %19, 2
  %21 = xor i32 %20, %7
  %22 = lshr i32 %21, 30
  %23 = xor i32 %22, %21
  %24 = mul i32 %23, 1812433253
  %25 = add i32 %24, 3
  %26 = xor i32 %25, %10
  %27 = lshr i32 %26, 30
  %28 = xor i32 %27, %26
  %29 = mul i32 %28, 1812433253
  %30 = add i32 %29, 4
  %31 = xor i32 %30, %1
  store i32 %31, ptr %0, align 4, !tbaa !12
  %32 = lshr i32 %31, 30
  %33 = xor i32 %32, %31
  %34 = mul i32 %33, 1812433253
  %35 = add i32 %34, 5
  %36 = xor i32 %35, %16
  store i32 %36, ptr %5, align 4, !tbaa !12
  %37 = lshr i32 %36, 30
  %38 = xor i32 %37, %36
  %39 = mul i32 %38, 1812433253
  %40 = add i32 %39, 6
  %41 = xor i32 %40, %21
  store i32 %41, ptr %8, align 4, !tbaa !12
  %42 = lshr i32 %41, 30
  %43 = xor i32 %42, %41
  %44 = mul i32 %43, 1812433253
  %45 = add i32 %44, 7
  %46 = xor i32 %45, %26
  store i32 %46, ptr %11, align 4, !tbaa !12
  tail call void @period_certification(ptr noundef nonnull %0)
  tail call void @tinymt32_next_state(ptr noundef nonnull %0)
  tail call void @tinymt32_next_state(ptr noundef nonnull %0)
  tail call void @tinymt32_next_state(ptr noundef nonnull %0)
  tail call void @tinymt32_next_state(ptr noundef nonnull %0)
  tail call void @tinymt32_next_state(ptr noundef nonnull %0)
  tail call void @tinymt32_next_state(ptr noundef nonnull %0)
  tail call void @tinymt32_next_state(ptr noundef nonnull %0)
  tail call void @tinymt32_next_state(ptr noundef nonnull %0)
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @period_certification(ptr noundef) local_unnamed_addr #0

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @tinymt32_next_state(ptr noundef) local_unnamed_addr #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 = { inlinehint 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, !9, i64 16}
!6 = !{!"TINYMT32_T", !7, i64 0, !9, i64 16, !9, i64 20, !9, i64 24}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!6, !9, i64 20}
!11 = !{!6, !9, i64 24}
!12 = !{!9, !9, i64 0}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass