; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/rijndael (aesxam)

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

@fillrand.a = external hidden global [2 x i64], align 16
@fillrand.mt = external hidden global i64, align 8
@fillrand.count = external hidden global i64, align 8
@fillrand.r = external hidden global [4 x i8], align 1

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

8:                                                ; preds = %2
  store i64 0, ptr @fillrand.mt, align 8, !tbaa !11
  store i64 60147, ptr @fillrand.a, align 16, !tbaa !11
  store i64 13822, ptr getelementptr inbounds ([2 x i64], ptr @fillrand.a, i64 0, i64 1), align 8, !tbaa !11
  br label %9

9:                                                ; preds = %8, %2
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %10

10:                                               ; preds = %41, %9
  %11 = load i32, ptr %5, align 4, !tbaa !9
  %12 = load i32, ptr %4, align 4, !tbaa !9
  %13 = icmp slt i32 %11, %12
  br i1 %13, label %14, label %44

14:                                               ; preds = %10
  %15 = load i64, ptr @fillrand.count, align 8, !tbaa !11
  %16 = icmp eq i64 %15, 4
  br i1 %16, label %17, label %32

17:                                               ; preds = %14
  %18 = load i64, ptr @fillrand.a, align 16, !tbaa !11
  %19 = and i64 %18, 65535
  %20 = mul i64 36969, %19
  %21 = load i64, ptr @fillrand.a, align 16, !tbaa !11
  %22 = lshr i64 %21, 16
  %23 = add i64 %20, %22
  store i64 %23, ptr @fillrand.a, align 16, !tbaa !11
  %24 = shl i64 %23, 16
  %25 = load i64, ptr getelementptr inbounds ([2 x i64], ptr @fillrand.a, i64 0, i64 1), align 8, !tbaa !11
  %26 = and i64 %25, 65535
  %27 = mul i64 18000, %26
  %28 = load i64, ptr getelementptr inbounds ([2 x i64], ptr @fillrand.a, i64 0, i64 1), align 8, !tbaa !11
  %29 = lshr i64 %28, 16
  %30 = add i64 %27, %29
  store i64 %30, ptr getelementptr inbounds ([2 x i64], ptr @fillrand.a, i64 0, i64 1), align 8, !tbaa !11
  %31 = add i64 %24, %30
  store i64 %31, ptr @fillrand.r, align 1, !tbaa !11
  store i64 0, ptr @fillrand.count, align 8, !tbaa !11
  br label %32

32:                                               ; preds = %17, %14
  %33 = load i64, ptr @fillrand.count, align 8, !tbaa !11
  %34 = add i64 %33, 1
  store i64 %34, ptr @fillrand.count, align 8, !tbaa !11
  %35 = getelementptr inbounds [4 x i8], ptr @fillrand.r, i64 0, i64 %33
  %36 = load i8, ptr %35, align 1, !tbaa !13
  %37 = load ptr, ptr %3, align 8, !tbaa !5
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %37, i64 %39
  store i8 %36, ptr %40, align 1, !tbaa !13
  br label %41

41:                                               ; preds = %32
  %42 = load i32, ptr %5, align 4, !tbaa !9
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %5, align 4, !tbaa !9
  br label %10, !llvm.loop !14

44:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  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

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 }

!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, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{!7, !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"

@fillrand.a = external hidden local_unnamed_addr global [2 x i64], align 16
@fillrand.mt = external hidden local_unnamed_addr global i64, align 8
@fillrand.count = external hidden local_unnamed_addr global i64, align 8
@fillrand.r = external hidden local_unnamed_addr global [4 x i8], align 1

; Function Attrs: nofree norecurse nosync nounwind memory(readwrite, argmem: write, inaccessiblemem: none) uwtable
define dso_local void @fillrand(ptr nocapture noundef writeonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %3 = load i64, ptr @fillrand.mt, align 8, !tbaa !5
  %.not = icmp eq i64 %3, 0
  br i1 %.not, label %5, label %4

4:                                                ; preds = %2
  store i64 0, ptr @fillrand.mt, align 8, !tbaa !5
  store i64 60147, ptr @fillrand.a, align 16, !tbaa !5
  store i64 13822, ptr getelementptr inbounds (i8, ptr @fillrand.a, i64 8), align 8, !tbaa !5
  br label %5

5:                                                ; preds = %4, %2
  %6 = icmp sgt i32 %1, 0
  br i1 %6, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %5
  %wide.trip.count = zext nneg i32 %1 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %23
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %23 ]
  %7 = load i64, ptr @fillrand.count, align 8, !tbaa !5
  %8 = icmp eq i64 %7, 4
  br i1 %8, label %9, label %.lr.ph._crit_edge

.lr.ph._crit_edge:                                ; preds = %.lr.ph
  %.phi.trans.insert = getelementptr inbounds [4 x i8], ptr @fillrand.r, i64 0, i64 %7
  %.pre = load i8, ptr %.phi.trans.insert, align 1, !tbaa !9
  br label %23

9:                                                ; preds = %.lr.ph
  %10 = load i64, ptr @fillrand.a, align 16, !tbaa !5
  %11 = and i64 %10, 65535
  %12 = mul nuw nsw i64 %11, 36969
  %13 = lshr i64 %10, 16
  %14 = add nuw nsw i64 %12, %13
  store i64 %14, ptr @fillrand.a, align 16, !tbaa !5
  %15 = shl i64 %14, 16
  %16 = load i64, ptr getelementptr inbounds (i8, ptr @fillrand.a, i64 8), align 8, !tbaa !5
  %17 = and i64 %16, 65535
  %18 = mul nuw nsw i64 %17, 18000
  %19 = lshr i64 %16, 16
  %20 = add nuw nsw i64 %18, %19
  store i64 %20, ptr getelementptr inbounds (i8, ptr @fillrand.a, i64 8), align 8, !tbaa !5
  %21 = add i64 %20, %15
  store i64 %21, ptr @fillrand.r, align 1, !tbaa !5
  %22 = trunc i64 %20 to i8
  br label %23

23:                                               ; preds = %.lr.ph._crit_edge, %9
  %24 = phi i8 [ %22, %9 ], [ %.pre, %.lr.ph._crit_edge ]
  %25 = phi i64 [ 0, %9 ], [ %7, %.lr.ph._crit_edge ]
  %26 = add i64 %25, 1
  store i64 %26, ptr @fillrand.count, align 8, !tbaa !5
  %27 = getelementptr inbounds i8, ptr %0, i64 %indvars.iv
  store i8 %24, ptr %27, align 1, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !10

._crit_edge:                                      ; preds = %23, %5
  ret void
}

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


; Effective O3 passes: BDCEPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass