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

; 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.arcfour_ctx = type { [256 x i8], i8, i8 }

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

11:                                               ; preds = %22, %3
  %12 = load i32, ptr %7, align 4, !tbaa !9
  %13 = icmp ult i32 %12, 256
  br i1 %13, label %14, label %25

14:                                               ; preds = %11
  %15 = load i32, ptr %7, align 4, !tbaa !9
  %16 = trunc i32 %15 to i8
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.arcfour_ctx, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %7, align 4, !tbaa !9
  %20 = zext i32 %19 to i64
  %21 = getelementptr inbounds [256 x i8], ptr %18, i64 0, i64 %20
  store i8 %16, ptr %21, align 1, !tbaa !11
  br label %22

22:                                               ; preds = %14
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = add i32 %23, 1
  store i32 %24, ptr %7, align 4, !tbaa !9
  br label %11, !llvm.loop !12

25:                                               ; preds = %11
  store i32 0, ptr %9, align 4, !tbaa !9
  store i32 0, ptr %8, align 4, !tbaa !9
  store i32 0, ptr %7, align 4, !tbaa !9
  br label %26

26:                                               ; preds = %80, %25
  %27 = load i32, ptr %7, align 4, !tbaa !9
  %28 = icmp ult i32 %27, 256
  br i1 %28, label %29, label %83

29:                                               ; preds = %26
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.arcfour_ctx, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = zext i32 %32 to i64
  %34 = getelementptr inbounds [256 x i8], ptr %31, i64 0, i64 %33
  %35 = load i8, ptr %34, align 1, !tbaa !11
  %36 = zext i8 %35 to i32
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = load i32, ptr %9, align 4, !tbaa !9
  %39 = zext i32 %38 to i64
  %40 = getelementptr inbounds i8, ptr %37, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !11
  %42 = zext i8 %41 to i32
  %43 = add nsw i32 %36, %42
  %44 = load i32, ptr %8, align 4, !tbaa !9
  %45 = add i32 %44, %43
  store i32 %45, ptr %8, align 4, !tbaa !9
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = and i32 %46, 255
  store i32 %47, ptr %8, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %29
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #2
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.arcfour_ctx, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %7, align 4, !tbaa !9
  %52 = zext i32 %51 to i64
  %53 = getelementptr inbounds [256 x i8], ptr %50, i64 0, i64 %52
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = zext i8 %54 to i32
  store i32 %55, ptr %10, align 4, !tbaa !9
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = getelementptr inbounds %struct.arcfour_ctx, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %8, align 4, !tbaa !9
  %59 = zext i32 %58 to i64
  %60 = getelementptr inbounds [256 x i8], ptr %57, i64 0, i64 %59
  %61 = load i8, ptr %60, align 1, !tbaa !11
  %62 = load ptr, ptr %4, align 8, !tbaa !5
  %63 = getelementptr inbounds %struct.arcfour_ctx, ptr %62, i32 0, i32 0
  %64 = load i32, ptr %7, align 4, !tbaa !9
  %65 = zext i32 %64 to i64
  %66 = getelementptr inbounds [256 x i8], ptr %63, i64 0, i64 %65
  store i8 %61, ptr %66, align 1, !tbaa !11
  %67 = load i32, ptr %10, align 4, !tbaa !9
  %68 = trunc i32 %67 to i8
  %69 = load ptr, ptr %4, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.arcfour_ctx, ptr %69, i32 0, i32 0
  %71 = load i32, ptr %8, align 4, !tbaa !9
  %72 = zext i32 %71 to i64
  %73 = getelementptr inbounds [256 x i8], ptr %70, i64 0, i64 %72
  store i8 %68, ptr %73, align 1, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #2
  br label %74

74:                                               ; preds = %48
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %9, align 4, !tbaa !9
  %77 = add i32 %76, 1
  %78 = load i32, ptr %5, align 4, !tbaa !9
  %79 = urem i32 %77, %78
  store i32 %79, ptr %9, align 4, !tbaa !9
  br label %80

80:                                               ; preds = %75
  %81 = load i32, ptr %7, align 4, !tbaa !9
  %82 = add i32 %81, 1
  store i32 %82, ptr %7, align 4, !tbaa !9
  br label %26, !llvm.loop !14

83:                                               ; preds = %26
  %84 = load ptr, ptr %4, align 8, !tbaa !5
  %85 = getelementptr inbounds %struct.arcfour_ctx, ptr %84, i32 0, i32 2
  store i8 0, ptr %85, align 1, !tbaa !15
  %86 = load ptr, ptr %4, align 8, !tbaa !5
  %87 = getelementptr inbounds %struct.arcfour_ctx, ptr %86, i32 0, i32 1
  store i8 0, ptr %87, align 1, !tbaa !17
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #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 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = !{!16, !7, i64 257}
!16 = !{!"arcfour_ctx", !7, i64 0, !7, i64 256, !7, i64 257}
!17 = !{!16, !7, i64 256}


; 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: readwrite) uwtable
define dso_local void @arcfour_set_key(ptr nocapture noundef %0, i32 noundef %1, ptr nocapture noundef readonly %2) local_unnamed_addr #0 {
vector.ph:
  store <16 x i8> <i8 0, i8 1, i8 2, i8 3, i8 4, i8 5, i8 6, i8 7, i8 8, i8 9, i8 10, i8 11, i8 12, i8 13, i8 14, i8 15>, ptr %0, align 1, !tbaa !5
  %3 = getelementptr inbounds i8, ptr %0, i64 16
  store <16 x i8> <i8 16, i8 17, i8 18, i8 19, i8 20, i8 21, i8 22, i8 23, i8 24, i8 25, i8 26, i8 27, i8 28, i8 29, i8 30, i8 31>, ptr %3, align 1, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %0, i64 32
  store <16 x i8> <i8 32, i8 33, i8 34, i8 35, i8 36, i8 37, i8 38, i8 39, i8 40, i8 41, i8 42, i8 43, i8 44, i8 45, i8 46, i8 47>, ptr %4, align 1, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 48
  store <16 x i8> <i8 48, i8 49, i8 50, i8 51, i8 52, i8 53, i8 54, i8 55, i8 56, i8 57, i8 58, i8 59, i8 60, i8 61, i8 62, i8 63>, ptr %5, align 1, !tbaa !5
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  store <16 x i8> <i8 64, i8 65, i8 66, i8 67, i8 68, i8 69, i8 70, i8 71, i8 72, i8 73, i8 74, i8 75, i8 76, i8 77, i8 78, i8 79>, ptr %6, align 1, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 80
  store <16 x i8> <i8 80, i8 81, i8 82, i8 83, i8 84, i8 85, i8 86, i8 87, i8 88, i8 89, i8 90, i8 91, i8 92, i8 93, i8 94, i8 95>, ptr %7, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 96
  store <16 x i8> <i8 96, i8 97, i8 98, i8 99, i8 100, i8 101, i8 102, i8 103, i8 104, i8 105, i8 106, i8 107, i8 108, i8 109, i8 110, i8 111>, ptr %8, align 1, !tbaa !5
  %9 = getelementptr inbounds i8, ptr %0, i64 112
  store <16 x i8> <i8 112, i8 113, i8 114, i8 115, i8 116, i8 117, i8 118, i8 119, i8 120, i8 121, i8 122, i8 123, i8 124, i8 125, i8 126, i8 127>, ptr %9, align 1, !tbaa !5
  %10 = getelementptr inbounds i8, ptr %0, i64 128
  store <16 x i8> <i8 -128, i8 -127, i8 -126, i8 -125, i8 -124, i8 -123, i8 -122, i8 -121, i8 -120, i8 -119, i8 -118, i8 -117, i8 -116, i8 -115, i8 -114, i8 -113>, ptr %10, align 1, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %0, i64 144
  store <16 x i8> <i8 -112, i8 -111, i8 -110, i8 -109, i8 -108, i8 -107, i8 -106, i8 -105, i8 -104, i8 -103, i8 -102, i8 -101, i8 -100, i8 -99, i8 -98, i8 -97>, ptr %11, align 1, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 160
  store <16 x i8> <i8 -96, i8 -95, i8 -94, i8 -93, i8 -92, i8 -91, i8 -90, i8 -89, i8 -88, i8 -87, i8 -86, i8 -85, i8 -84, i8 -83, i8 -82, i8 -81>, ptr %12, align 1, !tbaa !5
  %13 = getelementptr inbounds i8, ptr %0, i64 176
  store <16 x i8> <i8 -80, i8 -79, i8 -78, i8 -77, i8 -76, i8 -75, i8 -74, i8 -73, i8 -72, i8 -71, i8 -70, i8 -69, i8 -68, i8 -67, i8 -66, i8 -65>, ptr %13, align 1, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 192
  store <16 x i8> <i8 -64, i8 -63, i8 -62, i8 -61, i8 -60, i8 -59, i8 -58, i8 -57, i8 -56, i8 -55, i8 -54, i8 -53, i8 -52, i8 -51, i8 -50, i8 -49>, ptr %14, align 1, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %0, i64 208
  store <16 x i8> <i8 -48, i8 -47, i8 -46, i8 -45, i8 -44, i8 -43, i8 -42, i8 -41, i8 -40, i8 -39, i8 -38, i8 -37, i8 -36, i8 -35, i8 -34, i8 -33>, ptr %15, align 1, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %0, i64 224
  store <16 x i8> <i8 -32, i8 -31, i8 -30, i8 -29, i8 -28, i8 -27, i8 -26, i8 -25, i8 -24, i8 -23, i8 -22, i8 -21, i8 -20, i8 -19, i8 -18, i8 -17>, ptr %16, align 1, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %0, i64 240
  store <16 x i8> <i8 -16, i8 -15, i8 -14, i8 -13, i8 -12, i8 -11, i8 -10, i8 -9, i8 -8, i8 -7, i8 -6, i8 -5, i8 -4, i8 -3, i8 -2, i8 -1>, ptr %17, align 1, !tbaa !5
  br label %.preheader

.preheader:                                       ; preds = %vector.ph, %.preheader
  %indvars.iv32 = phi i64 [ %indvars.iv.next33, %.preheader ], [ 0, %vector.ph ]
  %.02529 = phi i32 [ %27, %.preheader ], [ 0, %vector.ph ]
  %.02628 = phi i8 [ %.narrow, %.preheader ], [ 0, %vector.ph ]
  %18 = getelementptr inbounds [256 x i8], ptr %0, i64 0, i64 %indvars.iv32
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = zext i32 %.02529 to i64
  %21 = getelementptr inbounds i8, ptr %2, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %.tr = add i8 %.02628, %19
  %.narrow = add i8 %.tr, %22
  %23 = zext i8 %.narrow to i64
  %24 = getelementptr inbounds [256 x i8], ptr %0, i64 0, i64 %23
  %25 = load i8, ptr %24, align 1, !tbaa !5
  store i8 %25, ptr %18, align 1, !tbaa !5
  store i8 %19, ptr %24, align 1, !tbaa !5
  %26 = add i32 %.02529, 1
  %27 = urem i32 %26, %1
  %indvars.iv.next33 = add nuw nsw i64 %indvars.iv32, 1
  %exitcond34.not = icmp eq i64 %indvars.iv.next33, 256
  br i1 %exitcond34.not, label %28, label %.preheader, !llvm.loop !8

28:                                               ; preds = %.preheader
  %29 = getelementptr inbounds i8, ptr %0, i64 257
  store i8 0, ptr %29, align 1, !tbaa !10
  %30 = getelementptr inbounds i8, ptr %0, i64 256
  store i8 0, ptr %30, align 1, !tbaa !12
  ret void
}

attributes #0 = { nofree norecurse nosync nounwind memory(argmem: readwrite) 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"}
!10 = !{!11, !6, i64 257}
!11 = !{!"arcfour_ctx", !6, i64 0, !6, i64 256, !6, i64 257}
!12 = !{!11, !6, i64 256}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass