; LLVM IR from CactiLab/Sherloc-Cortex-M-CFVD :: Sherloc_runtime/evaluation/src/nettle_aes (nettle-aes)

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

@plaintext = external dso_local global [256 x i8], align 16
@expected = external dso_local global [256 x i8], align 16
@encrypted = external dso_local global [256 x i8], align 16
@decrypted = external dso_local global [256 x i8], align 16

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @verify_benchmark_aes(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  store i32 %0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #2
  store i8 1, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %5

5:                                                ; preds = %36, %1
  %6 = load i32, ptr %4, align 4, !tbaa !5
  %7 = icmp ult i32 %6, 256
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  br label %39

9:                                                ; preds = %5
  %10 = load i32, ptr %4, align 4, !tbaa !5
  %11 = zext i32 %10 to i64
  %12 = getelementptr inbounds [256 x i8], ptr @encrypted, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !11
  %14 = zext i8 %13 to i32
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = zext i32 %15 to i64
  %17 = getelementptr inbounds [256 x i8], ptr @expected, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %19 = zext i8 %18 to i32
  %20 = icmp ne i32 %14, %19
  br i1 %20, label %21, label %22

21:                                               ; preds = %9
  store i8 0, ptr %3, align 1, !tbaa !9
  br label %22

22:                                               ; preds = %21, %9
  %23 = load i32, ptr %4, align 4, !tbaa !5
  %24 = zext i32 %23 to i64
  %25 = getelementptr inbounds [256 x i8], ptr @plaintext, i64 0, i64 %24
  %26 = load i8, ptr %25, align 1, !tbaa !11
  %27 = zext i8 %26 to i32
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = zext i32 %28 to i64
  %30 = getelementptr inbounds [256 x i8], ptr @decrypted, i64 0, i64 %29
  %31 = load i8, ptr %30, align 1, !tbaa !11
  %32 = zext i8 %31 to i32
  %33 = icmp ne i32 %27, %32
  br i1 %33, label %34, label %35

34:                                               ; preds = %22
  store i8 0, ptr %3, align 1, !tbaa !9
  br label %35

35:                                               ; preds = %34, %22
  br label %36

36:                                               ; preds = %35
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = add i32 %37, 1
  store i32 %38, ptr %4, align 4, !tbaa !5
  br label %5, !llvm.loop !12

39:                                               ; preds = %8
  %40 = load i8, ptr %3, align 1, !tbaa !9, !range !14, !noundef !15
  %41 = trunc i8 %40 to i1
  %42 = zext i1 %41 to i32
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #2
  ret i32 %42
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"_Bool", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = !{i8 0, i8 2}
!15 = !{}


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

@plaintext = external dso_local local_unnamed_addr global [256 x i8], align 16
@expected = external dso_local local_unnamed_addr global [256 x i8], align 16
@encrypted = external dso_local local_unnamed_addr global [256 x i8], align 16
@decrypted = external dso_local local_unnamed_addr global [256 x i8], align 16

; Function Attrs: nofree norecurse nosync nounwind memory(read, argmem: none, inaccessiblemem: none) uwtable
define dso_local range(i32 0, 2) i32 @verify_benchmark_aes(i32 noundef %0) local_unnamed_addr #0 {
  br label %5

2:                                                ; preds = %5
  %3 = and i8 %.2.1, 1
  %4 = zext nneg i8 %3 to i32
  ret i32 %4

5:                                                ; preds = %5, %1
  %indvars.iv = phi i64 [ 0, %1 ], [ %indvars.iv.next.1, %5 ]
  %.079 = phi i8 [ 1, %1 ], [ %.2.1, %5 ]
  %6 = getelementptr inbounds [256 x i8], ptr @encrypted, i64 0, i64 %indvars.iv
  %7 = load i8, ptr %6, align 2, !tbaa !5
  %8 = getelementptr inbounds [256 x i8], ptr @expected, i64 0, i64 %indvars.iv
  %9 = load i8, ptr %8, align 2, !tbaa !5
  %.not = icmp eq i8 %7, %9
  %10 = getelementptr inbounds [256 x i8], ptr @plaintext, i64 0, i64 %indvars.iv
  %11 = load i8, ptr %10, align 2, !tbaa !5
  %12 = getelementptr inbounds [256 x i8], ptr @decrypted, i64 0, i64 %indvars.iv
  %13 = load i8, ptr %12, align 2, !tbaa !5
  %.not8 = icmp eq i8 %11, %13
  %indvars.iv.next = or disjoint i64 %indvars.iv, 1
  %14 = getelementptr inbounds [256 x i8], ptr @encrypted, i64 0, i64 %indvars.iv.next
  %15 = load i8, ptr %14, align 1, !tbaa !5
  %16 = getelementptr inbounds [256 x i8], ptr @expected, i64 0, i64 %indvars.iv.next
  %17 = load i8, ptr %16, align 1, !tbaa !5
  %.not.1 = icmp eq i8 %15, %17
  %18 = getelementptr inbounds [256 x i8], ptr @plaintext, i64 0, i64 %indvars.iv.next
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = getelementptr inbounds [256 x i8], ptr @decrypted, i64 0, i64 %indvars.iv.next
  %21 = load i8, ptr %20, align 1, !tbaa !5
  %.not8.1 = icmp eq i8 %19, %21
  %22 = select i1 %.not8.1, i1 %.not.1, i1 false
  %23 = select i1 %22, i1 %.not8, i1 false
  %24 = select i1 %23, i1 %.not, i1 false
  %.2.1 = select i1 %24, i8 %.079, i8 0
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %exitcond.not.1 = icmp eq i64 %indvars.iv.next.1, 256
  br i1 %exitcond.not.1, label %2, label %5, !llvm.loop !8
}

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass