; LLVM IR from libtcod/libtcod :: src/libtcod (mersenne_c)

; 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.TCOD_Random_MT_CMWC = type { i32, i32, [624 x i32], i32, [4096 x i32], i32, i32 }

; Function Attrs: nounwind uwtable
define dso_local ptr @TCOD_random_new_from_seed(i32 noundef %0, i32 noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store i32 %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %8 = call noalias ptr @calloc(i64 noundef 1, i64 noundef 18900) #4
  store ptr %8, ptr %5, align 8, !tbaa !9
  %9 = load i32, ptr %3, align 4, !tbaa !5
  %10 = icmp eq i32 %9, 0
  br i1 %10, label %11, label %20

11:                                               ; preds = %2
  %12 = load ptr, ptr %5, align 8, !tbaa !9
  %13 = getelementptr inbounds %struct.TCOD_Random_MT_CMWC, ptr %12, i32 0, i32 0
  store i32 0, ptr %13, align 4, !tbaa !11
  %14 = load ptr, ptr %5, align 8, !tbaa !9
  %15 = getelementptr inbounds %struct.TCOD_Random_MT_CMWC, ptr %14, i32 0, i32 3
  store i32 624, ptr %15, align 4, !tbaa !13
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = getelementptr inbounds %struct.TCOD_Random_MT_CMWC, ptr %17, i32 0, i32 2
  %19 = getelementptr inbounds [624 x i32], ptr %18, i64 0, i64 0
  call void @mt_init(i32 noundef %16, ptr noundef %19)
  br label %49

20:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %21 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %21, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %22

22:                                               ; preds = %35, %20
  %23 = load i32, ptr %7, align 4, !tbaa !5
  %24 = icmp slt i32 %23, 4096
  br i1 %24, label %26, label %25

25:                                               ; preds = %22
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %38

26:                                               ; preds = %22
  %27 = load i32, ptr %6, align 4, !tbaa !5
  %28 = mul i32 %27, 1103515245
  %29 = add i32 %28, 12345
  store i32 %29, ptr %6, align 4, !tbaa !5
  %30 = load ptr, ptr %5, align 8, !tbaa !9
  %31 = getelementptr inbounds %struct.TCOD_Random_MT_CMWC, ptr %30, i32 0, i32 4
  %32 = load i32, ptr %7, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [4096 x i32], ptr %31, i64 0, i64 %33
  store i32 %29, ptr %34, align 4, !tbaa !5
  br label %35

35:                                               ; preds = %26
  %36 = load i32, ptr %7, align 4, !tbaa !5
  %37 = add nsw i32 %36, 1
  store i32 %37, ptr %7, align 4, !tbaa !5
  br label %22, !llvm.loop !14

38:                                               ; preds = %25
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = mul i32 %39, 1103515245
  %41 = add i32 %40, 12345
  %42 = urem i32 %41, 809430660
  %43 = load ptr, ptr %5, align 8, !tbaa !9
  %44 = getelementptr inbounds %struct.TCOD_Random_MT_CMWC, ptr %43, i32 0, i32 5
  store i32 %42, ptr %44, align 4, !tbaa !16
  %45 = load ptr, ptr %5, align 8, !tbaa !9
  %46 = getelementptr inbounds %struct.TCOD_Random_MT_CMWC, ptr %45, i32 0, i32 6
  store i32 0, ptr %46, align 4, !tbaa !17
  %47 = load ptr, ptr %5, align 8, !tbaa !9
  %48 = getelementptr inbounds %struct.TCOD_Random_MT_CMWC, ptr %47, i32 0, i32 0
  store i32 1, ptr %48, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %49

49:                                               ; preds = %38, %11
  %50 = load ptr, ptr %5, align 8, !tbaa !9
  %51 = getelementptr inbounds %struct.TCOD_Random_MT_CMWC, ptr %50, i32 0, i32 1
  store i32 0, ptr %51, align 4, !tbaa !18
  %52 = load ptr, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret ptr %52
}

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

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #2

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

; 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 allocsize(0,1) "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 }
attributes #4 = { nounwind allocsize(0,1) }

!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 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !6, i64 0}
!12 = !{!"TCOD_Random_MT_CMWC", !6, i64 0, !6, i64 4, !7, i64 8, !6, i64 2504, !7, i64 2508, !6, i64 18892, !6, i64 18896}
!13 = !{!12, !6, i64 2504}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!12, !6, i64 18892}
!17 = !{!12, !6, i64 18896}
!18 = !{!12, !6, i64 4}


; 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 noundef ptr @TCOD_random_new_from_seed(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = tail call noalias dereferenceable_or_null(18900) ptr @calloc(i64 noundef 1, i64 noundef 18900) #2
  %4 = icmp eq i32 %0, 0
  br i1 %4, label %6, label %.preheader

.preheader:                                       ; preds = %2
  %5 = getelementptr inbounds i8, ptr %3, i64 2508
  br label %15

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %3, i64 2504
  store i32 624, ptr %7, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %3, i64 8
  tail call void @mt_init(i32 noundef %1, ptr noundef nonnull %8)
  br label %28

9:                                                ; preds = %15
  %10 = mul i32 %26, 1103515245
  %11 = add i32 %10, 12345
  %12 = urem i32 %11, 809430660
  %13 = getelementptr inbounds i8, ptr %3, i64 18892
  store i32 %12, ptr %13, align 4, !tbaa !10
  %14 = getelementptr inbounds i8, ptr %3, i64 18896
  store i32 0, ptr %14, align 4, !tbaa !11
  store i32 1, ptr %3, align 4, !tbaa !12
  br label %28

15:                                               ; preds = %15, %.preheader
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next.3, %15 ]
  %.01617 = phi i32 [ %1, %.preheader ], [ %26, %15 ]
  %16 = mul i32 %.01617, 1103515245
  %17 = add i32 %16, 12345
  %18 = getelementptr inbounds [4096 x i32], ptr %5, i64 0, i64 %indvars.iv
  store i32 %17, ptr %18, align 4, !tbaa !13
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %19 = mul i32 %17, 1103515245
  %20 = add i32 %19, 12345
  %21 = getelementptr inbounds [4096 x i32], ptr %5, i64 0, i64 %indvars.iv.next
  store i32 %20, ptr %21, align 4, !tbaa !13
  %indvars.iv.next.1 = or disjoint i64 %indvars.iv, 2
  %22 = mul i32 %20, 1103515245
  %23 = add i32 %22, 12345
  %24 = getelementptr inbounds [4096 x i32], ptr %5, i64 0, i64 %indvars.iv.next.1
  store i32 %23, ptr %24, align 4, !tbaa !13
  %indvars.iv.next.2 = or disjoint i64 %indvars.iv, 3
  %25 = mul i32 %23, 1103515245
  %26 = add i32 %25, 12345
  %27 = getelementptr inbounds [4096 x i32], ptr %5, i64 0, i64 %indvars.iv.next.2
  store i32 %26, ptr %27, align 4, !tbaa !13
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 4
  %exitcond.not.3 = icmp eq i64 %indvars.iv.next.3, 4096
  br i1 %exitcond.not.3, label %9, label %15, !llvm.loop !14

28:                                               ; preds = %9, %6
  %29 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 0, ptr %29, align 4, !tbaa !16
  ret ptr %3
}

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #1

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

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 nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0,1) }

!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 2504}
!6 = !{!"TCOD_Random_MT_CMWC", !7, i64 0, !7, i64 4, !8, i64 8, !7, i64 2504, !8, i64 2508, !7, i64 18892, !7, i64 18896}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 18892}
!11 = !{!6, !7, i64 18896}
!12 = !{!6, !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = !{!6, !7, i64 4}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass