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

%struct.aes = type { i64, i64, [64 x i64], [64 x i64], i8 }

@presetkey = external dso_local global ptr, align 8

; 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
declare dso_local i32 @encfile(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @decfile(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @benchmark_rijndael() #1 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca [32 x i8], align 16
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca [16 x i8], align 16
  %10 = alloca [16 x i8], align 16
  %11 = alloca %struct.aes, align 8
  %12 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store ptr null, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #4
  store i8 0, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #4
  call void @llvm.memset.p0.i64(ptr align 16 %4, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 0, ptr %5, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !10
  call void @llvm.lifetime.start.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 1048, ptr %11) #4
  call void @llvm.memset.p0.i64(ptr align 8 %11, i8 0, i64 1048, i1 false)
  store i32 0, ptr %6, align 4, !tbaa !10
  store i32 0, ptr %7, align 4, !tbaa !10
  store i32 0, ptr %8, align 4, !tbaa !10
  %13 = load ptr, ptr @presetkey, align 8, !tbaa !5
  store ptr %13, ptr %2, align 8, !tbaa !5
  store i32 0, ptr %5, align 4, !tbaa !10
  br label %14

14:                                               ; preds = %74, %0
  %15 = load i32, ptr %5, align 4, !tbaa !10
  %16 = icmp slt i32 %15, 64
  br i1 %16, label %17, label %22

17:                                               ; preds = %14
  %18 = load ptr, ptr %2, align 8, !tbaa !5
  %19 = load i8, ptr %18, align 1, !tbaa !9
  %20 = sext i8 %19 to i32
  %21 = icmp ne i32 %20, 0
  br label %22

22:                                               ; preds = %17, %14
  %23 = phi i1 [ false, %14 ], [ %21, %17 ]
  br i1 %23, label %24, label %75

24:                                               ; preds = %22
  %25 = load ptr, ptr %2, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i32 1
  store ptr %26, ptr %2, align 8, !tbaa !5
  %27 = load i8, ptr %25, align 1, !tbaa !9
  store i8 %27, ptr %3, align 1, !tbaa !9
  %28 = load i8, ptr %3, align 1, !tbaa !9
  %29 = sext i8 %28 to i32
  %30 = icmp sge i32 %29, 48
  br i1 %30, label %31, label %42

31:                                               ; preds = %24
  %32 = load i8, ptr %3, align 1, !tbaa !9
  %33 = sext i8 %32 to i32
  %34 = icmp sle i32 %33, 57
  br i1 %34, label %35, label %42

35:                                               ; preds = %31
  %36 = load i32, ptr %6, align 4, !tbaa !10
  %37 = shl i32 %36, 4
  %38 = load i8, ptr %3, align 1, !tbaa !9
  %39 = sext i8 %38 to i32
  %40 = add nsw i32 %37, %39
  %41 = sub nsw i32 %40, 48
  store i32 %41, ptr %6, align 4, !tbaa !10
  br label %60

42:                                               ; preds = %31, %24
  %43 = load i8, ptr %3, align 1, !tbaa !9
  %44 = sext i8 %43 to i32
  %45 = icmp sge i32 %44, 65
  br i1 %45, label %46, label %58

46:                                               ; preds = %42
  %47 = load i8, ptr %3, align 1, !tbaa !9
  %48 = sext i8 %47 to i32
  %49 = icmp sle i32 %48, 70
  br i1 %49, label %50, label %58

50:                                               ; preds = %46
  %51 = load i32, ptr %6, align 4, !tbaa !10
  %52 = shl i32 %51, 4
  %53 = load i8, ptr %3, align 1, !tbaa !9
  %54 = sext i8 %53 to i32
  %55 = add nsw i32 %52, %54
  %56 = sub nsw i32 %55, 65
  %57 = add nsw i32 %56, 10
  store i32 %57, ptr %6, align 4, !tbaa !10
  br label %59

58:                                               ; preds = %46, %42
  store i32 -2, ptr %8, align 4, !tbaa !10
  store i32 4, ptr %12, align 4
  br label %104

59:                                               ; preds = %50
  br label %60

60:                                               ; preds = %59, %35
  %61 = load i32, ptr %5, align 4, !tbaa !10
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %5, align 4, !tbaa !10
  %63 = and i32 %61, 1
  %64 = icmp ne i32 %63, 0
  br i1 %64, label %65, label %74

65:                                               ; preds = %60
  %66 = load i32, ptr %6, align 4, !tbaa !10
  %67 = and i32 %66, 255
  %68 = trunc i32 %67 to i8
  %69 = load i32, ptr %5, align 4, !tbaa !10
  %70 = sdiv i32 %69, 2
  %71 = sub nsw i32 %70, 1
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [32 x i8], ptr %4, i64 0, i64 %72
  store i8 %68, ptr %73, align 1, !tbaa !9
  br label %74

74:                                               ; preds = %65, %60
  br label %14, !llvm.loop !12

75:                                               ; preds = %22
  %76 = load ptr, ptr %2, align 8, !tbaa !5
  %77 = load i8, ptr %76, align 1, !tbaa !9
  %78 = icmp ne i8 %77, 0
  br i1 %78, label %79, label %80

79:                                               ; preds = %75
  store i32 -3, ptr %8, align 4, !tbaa !10
  store i32 4, ptr %12, align 4
  br label %104

80:                                               ; preds = %75
  %81 = load i32, ptr %5, align 4, !tbaa !10
  %82 = icmp slt i32 %81, 32
  br i1 %82, label %87, label %83

83:                                               ; preds = %80
  %84 = load i32, ptr %5, align 4, !tbaa !10
  %85 = and i32 %84, 15
  %86 = icmp ne i32 %85, 0
  br i1 %86, label %87, label %88

87:                                               ; preds = %83, %80
  store i32 -4, ptr %8, align 4, !tbaa !10
  store i32 4, ptr %12, align 4
  br label %104

88:                                               ; preds = %83
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %5, align 4, !tbaa !10
  %91 = sdiv i32 %90, 2
  store i32 %91, ptr %7, align 4, !tbaa !10
  %92 = getelementptr inbounds [32 x i8], ptr %4, i64 0, i64 0
  %93 = load i32, ptr %7, align 4, !tbaa !10
  %94 = sext i32 %93 to i64
  %95 = call signext i16 @set_key(ptr noundef %92, i64 noundef %94, i32 noundef 1, ptr noundef %11)
  %96 = getelementptr inbounds [16 x i8], ptr %9, i64 0, i64 0
  %97 = call i32 @encfile(ptr noundef %11, ptr noundef %96)
  store i32 %97, ptr %8, align 4, !tbaa !10
  %98 = getelementptr inbounds [32 x i8], ptr %4, i64 0, i64 0
  %99 = load i32, ptr %7, align 4, !tbaa !10
  %100 = sext i32 %99 to i64
  %101 = call signext i16 @set_key(ptr noundef %98, i64 noundef %100, i32 noundef 2, ptr noundef %11)
  %102 = getelementptr inbounds [16 x i8], ptr %10, i64 0, i64 0
  %103 = call i32 @decfile(ptr noundef %11, ptr noundef %102)
  store i32 %103, ptr %8, align 4, !tbaa !10
  store i32 0, ptr %12, align 4
  br label %104

104:                                              ; preds = %89, %87, %79, %58
  call void @llvm.lifetime.end.p0(i64 1048, ptr %11) #4
  %105 = load i32, ptr %12, align 4
  switch i32 %105, label %109 [
    i32 0, label %106
    i32 4, label %107
  ]

106:                                              ; preds = %104
  br label %107

107:                                              ; preds = %106, %104
  %108 = load i32, ptr %8, align 4, !tbaa !10
  store i32 %108, ptr %1, align 4
  store i32 1, ptr %12, align 4
  br label %109

109:                                              ; preds = %107, %104
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %110 = load i32, ptr %1, align 4
  ret i32 %110
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare signext i16 @set_key(ptr noundef, i64 noundef, i32 noundef, ptr noundef) #3

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 #4 = { 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 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

%struct.aes = type { i64, i64, [64 x i64], [64 x i64], i8 }

@presetkey = external dso_local local_unnamed_addr global ptr, align 8

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @encfile(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local i32 @decfile(ptr noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local i32 @benchmark_rijndael() local_unnamed_addr #1 {
  %1 = alloca [32 x i8], align 16
  %2 = alloca [16 x i8], align 16
  %3 = alloca [16 x i8], align 16
  %4 = alloca %struct.aes, align 8
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %1) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(32) %1, i8 0, i64 32, i1 false)
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 1048, ptr nonnull %4) #4
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(1048) %4, i8 0, i64 1048, i1 false)
  %5 = load ptr, ptr @presetkey, align 8, !tbaa !5
  br label %6

6:                                                ; preds = %0, %23
  %.02845 = phi i8 [ 0, %0 ], [ %.1, %23 ]
  %.02944 = phi i32 [ 0, %0 ], [ %16, %23 ]
  %.03043 = phi ptr [ %5, %0 ], [ %9, %23 ]
  %7 = load i8, ptr %.03043, align 1, !tbaa !9
  %.not = icmp eq i8 %7, 0
  br i1 %.not, label %.critedge.thread, label %8

8:                                                ; preds = %6
  %9 = getelementptr inbounds i8, ptr %.03043, i64 1
  %10 = add i8 %7, -48
  %or.cond = icmp ult i8 %10, 10
  br i1 %or.cond, label %13, label %11

11:                                               ; preds = %8
  %12 = add i8 %7, -65
  %or.cond5 = icmp ult i8 %12, 6
  br i1 %or.cond5, label %13, label %.loopexit

13:                                               ; preds = %11, %8
  %.sink53 = phi i8 [ -48, %8 ], [ -55, %11 ]
  %14 = shl i8 %.02845, 4
  %15 = add i8 %14, %.sink53
  %.1 = add i8 %15, %7
  %16 = add nuw nsw i32 %.02944, 1
  %17 = and i32 %.02944, 1
  %.not35 = icmp eq i32 %17, 0
  br i1 %.not35, label %23, label %18

18:                                               ; preds = %13
  %19 = lshr exact i32 %16, 1
  %20 = add nsw i32 %19, -1
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds [32 x i8], ptr %1, i64 0, i64 %21
  store i8 %.1, ptr %22, align 1, !tbaa !9
  br label %23

23:                                               ; preds = %18, %13
  %exitcond.not = icmp eq i32 %16, 64
  br i1 %exitcond.not, label %.critedge, label %6, !llvm.loop !10

.critedge:                                        ; preds = %23
  %.pr = load i8, ptr %9, align 1, !tbaa !9
  %.not33 = icmp eq i8 %.pr, 0
  br i1 %.not33, label %.critedge.thread, label %.loopexit

.critedge.thread:                                 ; preds = %6, %.critedge
  %.02940 = phi i32 [ 64, %.critedge ], [ %.02944, %6 ]
  %24 = icmp ugt i32 %.02940, 31
  %25 = and i32 %.02940, 15
  %.not34 = icmp eq i32 %25, 0
  %or.cond36 = and i1 %24, %.not34
  br i1 %or.cond36, label %26, label %.loopexit

26:                                               ; preds = %.critedge.thread
  %27 = lshr exact i32 %.02940, 1
  %28 = zext nneg i32 %27 to i64
  %29 = call signext i16 @set_key(ptr noundef nonnull %1, i64 noundef %28, i32 noundef 1, ptr noundef nonnull %4) #4
  %30 = call i32 @encfile(ptr noundef nonnull %4, ptr noundef nonnull %2)
  %31 = call signext i16 @set_key(ptr noundef nonnull %1, i64 noundef %28, i32 noundef 2, ptr noundef nonnull %4) #4
  %32 = call i32 @decfile(ptr noundef nonnull %4, ptr noundef nonnull %3)
  br label %.loopexit

.loopexit:                                        ; preds = %11, %.critedge.thread, %.critedge, %26
  %.027 = phi i32 [ %32, %26 ], [ -3, %.critedge ], [ -4, %.critedge.thread ], [ -2, %11 ]
  call void @llvm.lifetime.end.p0(i64 1048, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %1) #4
  ret i32 %.027
}

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

declare signext i16 @set_key(ptr noundef, i64 noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

attributes #0 = { mustprogress 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { "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 #4 = { 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 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: AggressiveInstCombinePass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass