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

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

; 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
define dso_local i32 @encfile(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca [16 x i8], align 16
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %5) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 0, ptr %7, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %10 = load ptr, ptr %4, align 8, !tbaa !5
  call void @fillrand(ptr noundef %10, i32 noundef 16)
  store i64 4096, ptr %6, align 8, !tbaa !9
  %11 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 0
  call void @fillrand(ptr noundef %11, i32 noundef 1)
  %12 = load i64, ptr %6, align 8, !tbaa !9
  %13 = trunc i64 %12 to i8
  %14 = sext i8 %13 to i32
  %15 = and i32 %14, 15
  %16 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 0
  %17 = load i8, ptr %16, align 16, !tbaa !11
  %18 = zext i8 %17 to i32
  %19 = and i32 %18, -16
  %20 = or i32 %15, %19
  %21 = trunc i32 %20 to i8
  %22 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 0
  store i8 %21, ptr %22, align 16, !tbaa !11
  store i64 0, ptr %8, align 8, !tbaa !9
  br label %23

23:                                               ; preds = %62, %2
  %24 = load i64, ptr %8, align 8, !tbaa !9
  %25 = icmp ult i64 %24, 256
  br i1 %25, label %26, label %65

26:                                               ; preds = %23
  store i64 0, ptr %9, align 8, !tbaa !9
  br label %27

27:                                               ; preds = %35, %26
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = icmp ult i64 %28, 16
  br i1 %29, label %30, label %38

30:                                               ; preds = %27
  %31 = call i32 @rand_beebs()
  %32 = trunc i32 %31 to i8
  %33 = load i64, ptr %9, align 8, !tbaa !9
  %34 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 %33
  store i8 %32, ptr %34, align 1, !tbaa !11
  br label %35

35:                                               ; preds = %30
  %36 = load i64, ptr %9, align 8, !tbaa !9
  %37 = add i64 %36, 1
  store i64 %37, ptr %9, align 8, !tbaa !9
  br label %27, !llvm.loop !12

38:                                               ; preds = %27
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %39

39:                                               ; preds = %54, %38
  %40 = load i64, ptr %7, align 8, !tbaa !9
  %41 = icmp ult i64 %40, 16
  br i1 %41, label %42, label %57

42:                                               ; preds = %39
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = load i64, ptr %7, align 8, !tbaa !9
  %45 = getelementptr inbounds i8, ptr %43, i64 %44
  %46 = load i8, ptr %45, align 1, !tbaa !11
  %47 = zext i8 %46 to i32
  %48 = load i64, ptr %7, align 8, !tbaa !9
  %49 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 %48
  %50 = load i8, ptr %49, align 1, !tbaa !11
  %51 = zext i8 %50 to i32
  %52 = xor i32 %51, %47
  %53 = trunc i32 %52 to i8
  store i8 %53, ptr %49, align 1, !tbaa !11
  br label %54

54:                                               ; preds = %42
  %55 = load i64, ptr %7, align 8, !tbaa !9
  %56 = add i64 %55, 1
  store i64 %56, ptr %7, align 8, !tbaa !9
  br label %39, !llvm.loop !14

57:                                               ; preds = %39
  %58 = getelementptr inbounds [16 x i8], ptr %5, i64 0, i64 0
  %59 = load ptr, ptr %4, align 8, !tbaa !5
  %60 = load ptr, ptr %3, align 8, !tbaa !5
  %61 = call signext i16 @encrypt(ptr noundef %58, ptr noundef %59, ptr noundef %60)
  br label %62

62:                                               ; preds = %57
  %63 = load i64, ptr %8, align 8, !tbaa !9
  %64 = add i64 %63, 1
  store i64 %64, ptr %8, align 8, !tbaa !9
  br label %23, !llvm.loop !15

65:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  call void @llvm.lifetime.end.p0(i64 16, ptr %5) #3
  ret i32 0
}

declare signext i16 @encrypt(ptr noundef, ptr noundef, ptr noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @rand_beebs() #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}


; 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
declare dso_local void @fillrand(ptr noundef, i32 noundef) local_unnamed_addr #0

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

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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @encfile(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  %3 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #3
  tail call void @fillrand(ptr noundef %1, i32 noundef 16)
  call void @fillrand(ptr noundef nonnull %3, i32 noundef 1)
  %4 = load i8, ptr %3, align 16, !tbaa !5
  %5 = and i8 %4, -16
  store i8 %5, ptr %3, align 16, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %3, i64 1
  %7 = getelementptr inbounds i8, ptr %3, i64 2
  %8 = getelementptr inbounds i8, ptr %3, i64 3
  %9 = getelementptr inbounds i8, ptr %3, i64 4
  %10 = getelementptr inbounds i8, ptr %3, i64 5
  %11 = getelementptr inbounds i8, ptr %3, i64 6
  %12 = getelementptr inbounds i8, ptr %3, i64 7
  %13 = getelementptr inbounds i8, ptr %3, i64 8
  %14 = getelementptr inbounds i8, ptr %3, i64 9
  %15 = getelementptr inbounds i8, ptr %3, i64 10
  %16 = getelementptr inbounds i8, ptr %3, i64 11
  %17 = getelementptr inbounds i8, ptr %3, i64 12
  %18 = getelementptr inbounds i8, ptr %3, i64 13
  %19 = getelementptr inbounds i8, ptr %3, i64 14
  br label %.preheader15

.preheader15:                                     ; preds = %2, %.preheader15
  %.01318 = phi i64 [ 0, %2 ], [ %66, %.preheader15 ]
  %20 = call i32 @rand_beebs()
  %21 = trunc i32 %20 to i8
  store i8 %21, ptr %3, align 16, !tbaa !5
  %22 = call i32 @rand_beebs()
  %23 = trunc i32 %22 to i8
  store i8 %23, ptr %6, align 1, !tbaa !5
  %24 = call i32 @rand_beebs()
  %25 = trunc i32 %24 to i8
  store i8 %25, ptr %7, align 2, !tbaa !5
  %26 = call i32 @rand_beebs()
  %27 = trunc i32 %26 to i8
  store i8 %27, ptr %8, align 1, !tbaa !5
  %28 = call i32 @rand_beebs()
  %29 = trunc i32 %28 to i8
  store i8 %29, ptr %9, align 4, !tbaa !5
  %30 = call i32 @rand_beebs()
  %31 = trunc i32 %30 to i8
  store i8 %31, ptr %10, align 1, !tbaa !5
  %32 = call i32 @rand_beebs()
  %33 = trunc i32 %32 to i8
  store i8 %33, ptr %11, align 2, !tbaa !5
  %34 = call i32 @rand_beebs()
  %35 = trunc i32 %34 to i8
  store i8 %35, ptr %12, align 1, !tbaa !5
  %36 = call i32 @rand_beebs()
  %37 = trunc i32 %36 to i8
  store i8 %37, ptr %13, align 8, !tbaa !5
  %38 = call i32 @rand_beebs()
  %39 = trunc i32 %38 to i8
  store i8 %39, ptr %14, align 1, !tbaa !5
  %40 = call i32 @rand_beebs()
  %41 = trunc i32 %40 to i8
  store i8 %41, ptr %15, align 2, !tbaa !5
  %42 = call i32 @rand_beebs()
  %43 = trunc i32 %42 to i8
  store i8 %43, ptr %16, align 1, !tbaa !5
  %44 = call i32 @rand_beebs()
  %45 = trunc i32 %44 to i8
  store i8 %45, ptr %17, align 4, !tbaa !5
  %46 = call i32 @rand_beebs()
  %47 = trunc i32 %46 to i8
  store i8 %47, ptr %18, align 1, !tbaa !5
  %48 = call i32 @rand_beebs()
  %49 = trunc i32 %48 to i8
  store i8 %49, ptr %19, align 2, !tbaa !5
  %50 = call i32 @rand_beebs()
  %51 = trunc i32 %50 to i8
  %52 = load <16 x i8>, ptr %3, align 16
  %53 = load <2 x i8>, ptr %6, align 1, !tbaa !5
  %54 = load <4 x i8>, ptr %8, align 1, !tbaa !5
  %55 = load <8 x i8>, ptr %12, align 1, !tbaa !5
  %56 = load <16 x i8>, ptr %1, align 1, !tbaa !5
  %57 = shufflevector <2 x i8> %53, <2 x i8> poison, <16 x i32> <i32 0, i32 1, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
  %58 = shufflevector <16 x i8> %52, <16 x i8> %57, <16 x i32> <i32 0, i32 16, i32 17, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
  %59 = shufflevector <4 x i8> %54, <4 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
  %60 = shufflevector <16 x i8> %58, <16 x i8> %59, <16 x i32> <i32 0, i32 1, i32 2, i32 16, i32 17, i32 18, i32 19, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
  %61 = shufflevector <8 x i8> %55, <8 x i8> poison, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison, i32 poison>
  %62 = shufflevector <16 x i8> %60, <16 x i8> %61, <16 x i32> <i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 16, i32 17, i32 18, i32 19, i32 20, i32 21, i32 22, i32 23, i32 poison>
  %63 = insertelement <16 x i8> %62, i8 %51, i64 15
  %64 = xor <16 x i8> %56, %63
  store <16 x i8> %64, ptr %3, align 16, !tbaa !5
  %65 = call signext i16 @encrypt(ptr noundef nonnull %3, ptr noundef nonnull %1, ptr noundef %0) #3
  %66 = add nuw nsw i64 %.01318, 1
  %exitcond.not = icmp eq i64 %66, 256
  br i1 %exitcond.not, label %67, label %.preheader15, !llvm.loop !8

67:                                               ; preds = %.preheader15
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #3
  ret i32 0
}

declare signext i16 @encrypt(ptr noundef, ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @rand_beebs() 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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass,VectorCombinePass