; LLVM IR from microsoft/vOW4SIKE_on_HW :: SIKE_sw/src/sha3 (fips202)

; 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: 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 hidden void @keccak_squeezeblocks(ptr noundef, i64 noundef, ptr noundef, i32 noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local void @cshake128_simple_absorb(ptr noundef, i16 noundef zeroext, ptr noundef, i64 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local void @cshake128_simple(ptr noundef %0, i64 noundef %1, i16 noundef zeroext %2, ptr noundef %3, i64 noundef %4) #1 {
  %6 = alloca ptr, align 8
  %7 = alloca i64, align 8
  %8 = alloca i16, align 2
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca [25 x i64], align 16
  %12 = alloca [168 x i8], align 16
  %13 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store i64 %1, ptr %7, align 8, !tbaa !9
  store i16 %2, ptr %8, align 2, !tbaa !11
  store ptr %3, ptr %9, align 8, !tbaa !5
  store i64 %4, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 200, ptr %11) #2
  call void @llvm.lifetime.start.p0(i64 168, ptr %12) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #2
  %14 = getelementptr inbounds [25 x i64], ptr %11, i64 0, i64 0
  %15 = load i16, ptr %8, align 2, !tbaa !11
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = load i64, ptr %10, align 8, !tbaa !9
  call void @cshake128_simple_absorb(ptr noundef %14, i16 noundef zeroext %15, ptr noundef %16, i64 noundef %17)
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = load i64, ptr %7, align 8, !tbaa !9
  %20 = udiv i64 %19, 168
  %21 = getelementptr inbounds [25 x i64], ptr %11, i64 0, i64 0
  call void @keccak_squeezeblocks(ptr noundef %18, i64 noundef %20, ptr noundef %21, i32 noundef 168)
  %22 = load i64, ptr %7, align 8, !tbaa !9
  %23 = udiv i64 %22, 168
  %24 = mul i64 %23, 168
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds i8, ptr %25, i64 %24
  store ptr %26, ptr %6, align 8, !tbaa !5
  %27 = load i64, ptr %7, align 8, !tbaa !9
  %28 = urem i64 %27, 168
  %29 = icmp ne i64 %28, 0
  br i1 %29, label %30, label %52

30:                                               ; preds = %5
  %31 = getelementptr inbounds [168 x i8], ptr %12, i64 0, i64 0
  %32 = getelementptr inbounds [25 x i64], ptr %11, i64 0, i64 0
  call void @keccak_squeezeblocks(ptr noundef %31, i64 noundef 1, ptr noundef %32, i32 noundef 168)
  store i32 0, ptr %13, align 4, !tbaa !13
  br label %33

33:                                               ; preds = %48, %30
  %34 = load i32, ptr %13, align 4, !tbaa !13
  %35 = zext i32 %34 to i64
  %36 = load i64, ptr %7, align 8, !tbaa !9
  %37 = urem i64 %36, 168
  %38 = icmp ult i64 %35, %37
  br i1 %38, label %39, label %51

39:                                               ; preds = %33
  %40 = load i32, ptr %13, align 4, !tbaa !13
  %41 = zext i32 %40 to i64
  %42 = getelementptr inbounds [168 x i8], ptr %12, i64 0, i64 %41
  %43 = load i8, ptr %42, align 1, !tbaa !15
  %44 = load ptr, ptr %6, align 8, !tbaa !5
  %45 = load i32, ptr %13, align 4, !tbaa !13
  %46 = zext i32 %45 to i64
  %47 = getelementptr inbounds i8, ptr %44, i64 %46
  store i8 %43, ptr %47, align 1, !tbaa !15
  br label %48

48:                                               ; preds = %39
  %49 = load i32, ptr %13, align 4, !tbaa !13
  %50 = add i32 %49, 1
  store i32 %50, ptr %13, align 4, !tbaa !13
  br label %33, !llvm.loop !16

51:                                               ; preds = %33
  br label %52

52:                                               ; preds = %51, %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #2
  call void @llvm.lifetime.end.p0(i64 168, ptr %12) #2
  call void @llvm.lifetime.end.p0(i64 200, ptr %11) #2
  ret void
}

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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"short", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"int", !7, i64 0}
!15 = !{!7, !7, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"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"

; 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 hidden void @keccak_squeezeblocks(ptr noundef, i64 noundef, ptr noundef, i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
declare dso_local void @cshake128_simple_absorb(ptr noundef, i16 noundef zeroext, ptr noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local void @cshake128_simple(ptr noundef %0, i64 noundef %1, i16 noundef zeroext %2, ptr noundef %3, i64 noundef %4) local_unnamed_addr #1 {
  %6 = alloca [25 x i64], align 16
  %7 = alloca [168 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 200, ptr nonnull %6) #2
  call void @llvm.lifetime.start.p0(i64 168, ptr nonnull %7) #2
  call void @cshake128_simple_absorb(ptr noundef nonnull %6, i16 noundef zeroext %2, ptr noundef %3, i64 noundef %4)
  %8 = udiv i64 %1, 168
  call void @keccak_squeezeblocks(ptr noundef %0, i64 noundef %8, ptr noundef nonnull %6, i32 noundef 168)
  %9 = mul nuw i64 %8, 168
  %10 = getelementptr inbounds i8, ptr %0, i64 %9
  %11 = urem i64 %1, 168
  %.not = icmp eq i64 %11, 0
  br i1 %.not, label %.loopexit, label %iter.check

iter.check:                                       ; preds = %5
  call void @keccak_squeezeblocks(ptr noundef nonnull %7, i64 noundef 1, ptr noundef nonnull %6, i32 noundef 168)
  %min.iters.check = icmp ult i64 %11, 8
  br i1 %min.iters.check, label %vec.epilog.scalar.ph.preheader, label %vector.scevcheck

vector.scevcheck:                                 ; preds = %iter.check
  %12 = xor i64 %9, -1
  %13 = add i64 %12, %1
  %14 = and i64 %13, 4294967295
  %15 = icmp eq i64 %14, 4294967295
  %16 = icmp ugt i64 %13, 4294967295
  %17 = or i1 %15, %16
  br i1 %17, label %vec.epilog.scalar.ph.preheader, label %vector.main.loop.iter.check

vector.main.loop.iter.check:                      ; preds = %vector.scevcheck
  %min.iters.check16 = icmp ult i64 %11, 32
  br i1 %min.iters.check16, label %vec.epilog.ph, label %vector.ph

vector.ph:                                        ; preds = %vector.main.loop.iter.check
  %n.vec = and i64 %11, 224
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %18 = getelementptr inbounds [168 x i8], ptr %7, i64 0, i64 %index
  %19 = getelementptr inbounds i8, ptr %18, i64 16
  %wide.load = load <16 x i8>, ptr %18, align 16, !tbaa !5
  %wide.load17 = load <16 x i8>, ptr %19, align 16, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %10, i64 %index
  %21 = getelementptr inbounds i8, ptr %20, i64 16
  store <16 x i8> %wide.load, ptr %20, align 1, !tbaa !5
  store <16 x i8> %wide.load17, ptr %21, align 1, !tbaa !5
  %index.next = add nuw i64 %index, 32
  %22 = icmp eq i64 %index.next, %n.vec
  br i1 %22, label %middle.block, label %vector.body, !llvm.loop !8

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %11, %n.vec
  br i1 %cmp.n, label %.loopexit, label %vec.epilog.iter.check

vec.epilog.iter.check:                            ; preds = %middle.block
  %ind.end20 = trunc nuw nsw i64 %n.vec to i32
  %n.vec.remaining = and i64 %11, 24
  %min.epilog.iters.check = icmp eq i64 %n.vec.remaining, 0
  br i1 %min.epilog.iters.check, label %vec.epilog.scalar.ph.preheader, label %vec.epilog.ph

vec.epilog.ph:                                    ; preds = %vector.main.loop.iter.check, %vec.epilog.iter.check
  %vec.epilog.resume.val = phi i64 [ %n.vec, %vec.epilog.iter.check ], [ 0, %vector.main.loop.iter.check ]
  %n.vec19 = and i64 %11, 248
  %ind.end = trunc nuw nsw i64 %n.vec19 to i32
  br label %vec.epilog.vector.body

vec.epilog.vector.body:                           ; preds = %vec.epilog.vector.body, %vec.epilog.ph
  %index22 = phi i64 [ %vec.epilog.resume.val, %vec.epilog.ph ], [ %index.next24, %vec.epilog.vector.body ]
  %23 = getelementptr inbounds [168 x i8], ptr %7, i64 0, i64 %index22
  %wide.load23 = load <8 x i8>, ptr %23, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %10, i64 %index22
  store <8 x i8> %wide.load23, ptr %24, align 1, !tbaa !5
  %index.next24 = add nuw i64 %index22, 8
  %25 = icmp eq i64 %index.next24, %n.vec19
  br i1 %25, label %vec.epilog.middle.block, label %vec.epilog.vector.body, !llvm.loop !12

vec.epilog.middle.block:                          ; preds = %vec.epilog.vector.body
  %cmp.n25 = icmp eq i64 %11, %n.vec19
  br i1 %cmp.n25, label %.loopexit, label %vec.epilog.scalar.ph.preheader

vec.epilog.scalar.ph.preheader:                   ; preds = %vec.epilog.middle.block, %vector.scevcheck, %iter.check, %vec.epilog.iter.check
  %.ph = phi i64 [ 0, %iter.check ], [ 0, %vector.scevcheck ], [ %n.vec, %vec.epilog.iter.check ], [ %n.vec19, %vec.epilog.middle.block ]
  %.015.ph = phi i32 [ 0, %iter.check ], [ 0, %vector.scevcheck ], [ %ind.end20, %vec.epilog.iter.check ], [ %ind.end, %vec.epilog.middle.block ]
  br label %vec.epilog.scalar.ph

vec.epilog.scalar.ph:                             ; preds = %vec.epilog.scalar.ph.preheader, %vec.epilog.scalar.ph
  %26 = phi i64 [ %31, %vec.epilog.scalar.ph ], [ %.ph, %vec.epilog.scalar.ph.preheader ]
  %.015 = phi i32 [ %30, %vec.epilog.scalar.ph ], [ %.015.ph, %vec.epilog.scalar.ph.preheader ]
  %27 = getelementptr inbounds [168 x i8], ptr %7, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !5
  %29 = getelementptr inbounds i8, ptr %10, i64 %26
  store i8 %28, ptr %29, align 1, !tbaa !5
  %30 = add i32 %.015, 1
  %31 = zext i32 %30 to i64
  %32 = icmp ugt i64 %11, %31
  br i1 %32, label %vec.epilog.scalar.ph, label %.loopexit, !llvm.loop !13

.loopexit:                                        ; preds = %vec.epilog.scalar.ph, %middle.block, %vec.epilog.middle.block, %5
  call void @llvm.lifetime.end.p0(i64 168, ptr nonnull %7) #2
  call void @llvm.lifetime.end.p0(i64 200, ptr nonnull %6) #2
  ret void
}

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 = { 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, !10, !11}
!9 = !{!"llvm.loop.mustprogress"}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !9, !10, !11}
!13 = distinct !{!13, !9, !10}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopLoadEliminationPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,LoopVectorizePass,SROAPass,SimplifyCFGPass