; LLVM IR from tfhe/spqlios-arithmetic :: test/testlib (sha3)

; 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.sha3_ctx_t = type { %union.anon, i32, i32, i32 }
%union.anon = type { [25 x i64] }

; Function Attrs: nounwind uwtable
declare dso_local void @sha3_keccakf(ptr 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 @sha3_update(ptr noundef %0, ptr noundef %1, i64 noundef %2) #0 {
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !5
  store i64 %2, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #2
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #2
  %9 = load ptr, ptr %4, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.sha3_ctx_t, ptr %9, i32 0, i32 1
  %11 = load i32, ptr %10, align 8, !tbaa !11
  store i32 %11, ptr %8, align 4, !tbaa !14
  store i64 0, ptr %7, align 8, !tbaa !9
  br label %12

12:                                               ; preds = %42, %3
  %13 = load i64, ptr %7, align 8, !tbaa !9
  %14 = load i64, ptr %6, align 8, !tbaa !9
  %15 = icmp ult i64 %13, %14
  br i1 %15, label %16, label %45

16:                                               ; preds = %12
  %17 = load ptr, ptr %5, align 8, !tbaa !5
  %18 = load i64, ptr %7, align 8, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %17, i64 %18
  %20 = load i8, ptr %19, align 1, !tbaa !15
  %21 = zext i8 %20 to i32
  %22 = load ptr, ptr %4, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.sha3_ctx_t, ptr %22, i32 0, i32 0
  %24 = load i32, ptr %8, align 4, !tbaa !14
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %8, align 4, !tbaa !14
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [200 x i8], ptr %23, i64 0, i64 %26
  %28 = load i8, ptr %27, align 1, !tbaa !15
  %29 = zext i8 %28 to i32
  %30 = xor i32 %29, %21
  %31 = trunc i32 %30 to i8
  store i8 %31, ptr %27, align 1, !tbaa !15
  %32 = load i32, ptr %8, align 4, !tbaa !14
  %33 = load ptr, ptr %4, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.sha3_ctx_t, ptr %33, i32 0, i32 2
  %35 = load i32, ptr %34, align 4, !tbaa !16
  %36 = icmp sge i32 %32, %35
  br i1 %36, label %37, label %41

37:                                               ; preds = %16
  %38 = load ptr, ptr %4, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.sha3_ctx_t, ptr %38, i32 0, i32 0
  %40 = getelementptr inbounds [25 x i64], ptr %39, i64 0, i64 0
  call void @sha3_keccakf(ptr noundef %40)
  store i32 0, ptr %8, align 4, !tbaa !14
  br label %41

41:                                               ; preds = %37, %16
  br label %42

42:                                               ; preds = %41
  %43 = load i64, ptr %7, align 8, !tbaa !9
  %44 = add i64 %43, 1
  store i64 %44, ptr %7, align 8, !tbaa !9
  br label %12, !llvm.loop !17

45:                                               ; preds = %12
  %46 = load i32, ptr %8, align 4, !tbaa !14
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = getelementptr inbounds %struct.sha3_ctx_t, ptr %47, i32 0, i32 1
  store i32 %46, ptr %48, align 8, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #2
  ret i32 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 = !{!"long", !7, i64 0}
!11 = !{!12, !13, i64 200}
!12 = !{!"", !7, i64 0, !13, i64 200, !13, i64 204, !13, i64 208}
!13 = !{!"int", !7, i64 0}
!14 = !{!13, !13, i64 0}
!15 = !{!7, !7, i64 0}
!16 = !{!12, !13, i64 204}
!17 = distinct !{!17, !18}
!18 = !{!"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: nounwind uwtable
declare dso_local void @sha3_keccakf(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @sha3_update(ptr noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2) local_unnamed_addr #0 {
  %4 = getelementptr inbounds i8, ptr %0, i64 200
  %5 = load i32, ptr %4, align 8, !tbaa !5
  %.not16 = icmp eq i64 %2, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %6 = getelementptr inbounds i8, ptr %0, i64 204
  br label %7

7:                                                ; preds = %.lr.ph, %17
  %.015 = phi i32 [ %5, %.lr.ph ], [ %.1, %17 ]
  %.01214 = phi i64 [ 0, %.lr.ph ], [ %18, %17 ]
  %8 = getelementptr inbounds i8, ptr %1, i64 %.01214
  %9 = load i8, ptr %8, align 1, !tbaa !10
  %10 = add nsw i32 %.015, 1
  %11 = sext i32 %.015 to i64
  %12 = getelementptr inbounds [200 x i8], ptr %0, i64 0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !10
  %14 = xor i8 %13, %9
  store i8 %14, ptr %12, align 1, !tbaa !10
  %15 = load i32, ptr %6, align 4, !tbaa !11
  %.not = icmp slt i32 %10, %15
  br i1 %.not, label %17, label %16

16:                                               ; preds = %7
  tail call void @sha3_keccakf(ptr noundef nonnull %0)
  br label %17

17:                                               ; preds = %7, %16
  %.1 = phi i32 [ 0, %16 ], [ %10, %7 ]
  %18 = add nuw i64 %.01214, 1
  %exitcond.not = icmp eq i64 %18, %2
  br i1 %exitcond.not, label %._crit_edge, label %7, !llvm.loop !12

._crit_edge:                                      ; preds = %17, %3
  %.0.lcssa = phi i32 [ %5, %3 ], [ %.1, %17 ]
  store i32 %.0.lcssa, ptr %4, align 8, !tbaa !5
  ret i32 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" }

!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, !9, i64 200}
!6 = !{!"", !7, i64 0, !9, i64 200, !9, i64 204, !9, i64 208}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"int", !7, i64 0}
!10 = !{!7, !7, i64 0}
!11 = !{!6, !9, i64 204}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass