; LLVM IR from devantler/software-engineering-f22-shared :: IOT/BudgetManagementExcercise-03-28/ESP-Project/components/components/nghttp (genrand)

; 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.mt_state = type { [624 x i64], i32, %union.anon, i64, i8 }
%union.anon = type { i64 }

; Function Attrs: nounwind uwtable
define dso_local void @mrb_random_init_genrand(ptr noundef %0, i64 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store i64 %1, ptr %4, align 8, !tbaa !9
  %5 = load i64, ptr %4, align 8, !tbaa !9
  %6 = and i64 %5, 4294967295
  %7 = load ptr, ptr %3, align 8, !tbaa !5
  %8 = getelementptr inbounds %struct.mt_state, ptr %7, i32 0, i32 0
  %9 = getelementptr inbounds [624 x i64], ptr %8, i64 0, i64 0
  store i64 %6, ptr %9, align 8, !tbaa !9
  %10 = load ptr, ptr %3, align 8, !tbaa !5
  %11 = getelementptr inbounds %struct.mt_state, ptr %10, i32 0, i32 1
  store i32 1, ptr %11, align 8, !tbaa !11
  br label %12

12:                                               ; preds = %60, %2
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.mt_state, ptr %13, i32 0, i32 1
  %15 = load i32, ptr %14, align 8, !tbaa !11
  %16 = icmp slt i32 %15, 624
  br i1 %16, label %17, label %65

17:                                               ; preds = %12
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.mt_state, ptr %18, i32 0, i32 0
  %20 = load ptr, ptr %3, align 8, !tbaa !5
  %21 = getelementptr inbounds %struct.mt_state, ptr %20, i32 0, i32 1
  %22 = load i32, ptr %21, align 8, !tbaa !11
  %23 = sub nsw i32 %22, 1
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [624 x i64], ptr %19, i64 0, i64 %24
  %26 = load i64, ptr %25, align 8, !tbaa !9
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.mt_state, ptr %27, i32 0, i32 0
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.mt_state, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %30, align 8, !tbaa !11
  %32 = sub nsw i32 %31, 1
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [624 x i64], ptr %28, i64 0, i64 %33
  %35 = load i64, ptr %34, align 8, !tbaa !9
  %36 = lshr i64 %35, 30
  %37 = xor i64 %26, %36
  %38 = mul i64 1812433253, %37
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.mt_state, ptr %39, i32 0, i32 1
  %41 = load i32, ptr %40, align 8, !tbaa !11
  %42 = sext i32 %41 to i64
  %43 = add i64 %38, %42
  %44 = load ptr, ptr %3, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.mt_state, ptr %44, i32 0, i32 0
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %struct.mt_state, ptr %46, i32 0, i32 1
  %48 = load i32, ptr %47, align 8, !tbaa !11
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [624 x i64], ptr %45, i64 0, i64 %49
  store i64 %43, ptr %50, align 8, !tbaa !9
  %51 = load ptr, ptr %3, align 8, !tbaa !5
  %52 = getelementptr inbounds %struct.mt_state, ptr %51, i32 0, i32 0
  %53 = load ptr, ptr %3, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.mt_state, ptr %53, i32 0, i32 1
  %55 = load i32, ptr %54, align 8, !tbaa !11
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [624 x i64], ptr %52, i64 0, i64 %56
  %58 = load i64, ptr %57, align 8, !tbaa !9
  %59 = and i64 %58, 4294967295
  store i64 %59, ptr %57, align 8, !tbaa !9
  br label %60

60:                                               ; preds = %17
  %61 = load ptr, ptr %3, align 8, !tbaa !5
  %62 = getelementptr inbounds %struct.mt_state, ptr %61, i32 0, i32 1
  %63 = load i32, ptr %62, align 8, !tbaa !11
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %62, align 8, !tbaa !11
  br label %12, !llvm.loop !14

65:                                               ; preds = %12
  ret void
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 4992}
!12 = !{!"", !7, i64 0, !13, i64 4992, !7, i64 5000, !10, i64 5008, !7, i64 5016}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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: nofree norecurse nosync nounwind memory(argmem: write) uwtable
define dso_local void @mrb_random_init_genrand(ptr nocapture noundef writeonly %0, i64 noundef %1) local_unnamed_addr #0 {
  %3 = and i64 %1, 4294967295
  store i64 %3, ptr %0, align 8, !tbaa !5
  br label %4

4:                                                ; preds = %12, %2
  %5 = phi i64 [ %3, %2 ], [ %18, %12 ]
  %indvars.iv = phi i64 [ 1, %2 ], [ %indvars.iv.next.1, %12 ]
  %6 = lshr i64 %5, 30
  %7 = xor i64 %6, %5
  %8 = mul nuw nsw i64 %7, 1812433253
  %9 = add nuw i64 %8, %indvars.iv
  %10 = getelementptr inbounds [624 x i64], ptr %0, i64 0, i64 %indvars.iv
  %11 = and i64 %9, 4294967295
  store i64 %11, ptr %10, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 624
  br i1 %exitcond.not, label %19, label %12, !llvm.loop !9

12:                                               ; preds = %4
  %13 = lshr i64 %11, 30
  %14 = xor i64 %13, %9
  %15 = mul i64 %14, 1812433253
  %16 = add i64 %15, %indvars.iv.next
  %17 = getelementptr inbounds [624 x i64], ptr %0, i64 0, i64 %indvars.iv.next
  %18 = and i64 %16, 4294967295
  store i64 %18, ptr %17, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  br label %4

19:                                               ; preds = %4
  %20 = getelementptr inbounds i8, ptr %0, i64 4992
  store i32 624, ptr %20, align 8, !tbaa !11
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: write) 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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !13, i64 4992}
!12 = !{!"", !7, i64 0, !13, i64 4992, !7, i64 5000, !6, i64 5008, !7, i64 5016}
!13 = !{!"int", !7, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InstCombinePass,LCSSAPass,LICMPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass