; LLVM IR from openanolis/openssl :: crypto/sha (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.keccak_st = type { [5 x [5 x i64]], i64, i64, i64, [168 x i8], i8, %struct.prov_sha3_meth_st }
%struct.prov_sha3_meth_st = type { ptr, ptr }

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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

declare i64 @SHA3_absorb(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @ossl_sha3_final(ptr noundef %0, ptr noundef %1) #3 {
  %3 = alloca i32, align 4
  %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
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %9 = load ptr, ptr %5, align 8, !tbaa !5
  %10 = getelementptr inbounds %struct.keccak_st, ptr %9, i32 0, i32 1
  %11 = load i64, ptr %10, align 8, !tbaa !9
  store i64 %11, ptr %6, align 8, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  %12 = load ptr, ptr %5, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.keccak_st, ptr %12, i32 0, i32 3
  %14 = load i64, ptr %13, align 8, !tbaa !14
  store i64 %14, ptr %7, align 8, !tbaa !13
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %struct.keccak_st, ptr %15, i32 0, i32 2
  %17 = load i64, ptr %16, align 8, !tbaa !15
  %18 = icmp eq i64 %17, 0
  br i1 %18, label %19, label %20

19:                                               ; preds = %2
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %62

20:                                               ; preds = %2
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.keccak_st, ptr %21, i32 0, i32 4
  %23 = getelementptr inbounds [168 x i8], ptr %22, i64 0, i64 0
  %24 = load i64, ptr %7, align 8, !tbaa !13
  %25 = getelementptr inbounds i8, ptr %23, i64 %24
  %26 = load i64, ptr %6, align 8, !tbaa !13
  %27 = load i64, ptr %7, align 8, !tbaa !13
  %28 = sub i64 %26, %27
  call void @llvm.memset.p0.i64(ptr align 1 %25, i8 0, i64 %28, i1 false)
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.keccak_st, ptr %29, i32 0, i32 5
  %31 = load i8, ptr %30, align 8, !tbaa !16
  %32 = load ptr, ptr %5, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.keccak_st, ptr %32, i32 0, i32 4
  %34 = load i64, ptr %7, align 8, !tbaa !13
  %35 = getelementptr inbounds [168 x i8], ptr %33, i64 0, i64 %34
  store i8 %31, ptr %35, align 1, !tbaa !17
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.keccak_st, ptr %36, i32 0, i32 4
  %38 = load i64, ptr %6, align 8, !tbaa !13
  %39 = sub i64 %38, 1
  %40 = getelementptr inbounds [168 x i8], ptr %37, i64 0, i64 %39
  %41 = load i8, ptr %40, align 1, !tbaa !17
  %42 = zext i8 %41 to i32
  %43 = or i32 %42, 128
  %44 = trunc i32 %43 to i8
  store i8 %44, ptr %40, align 1, !tbaa !17
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.keccak_st, ptr %45, i32 0, i32 0
  %47 = getelementptr inbounds [5 x [5 x i64]], ptr %46, i64 0, i64 0
  %48 = load ptr, ptr %5, align 8, !tbaa !5
  %49 = getelementptr inbounds %struct.keccak_st, ptr %48, i32 0, i32 4
  %50 = getelementptr inbounds [168 x i8], ptr %49, i64 0, i64 0
  %51 = load i64, ptr %6, align 8, !tbaa !13
  %52 = load i64, ptr %6, align 8, !tbaa !13
  %53 = call i64 @SHA3_absorb(ptr noundef %47, ptr noundef %50, i64 noundef %51, i64 noundef %52)
  %54 = load ptr, ptr %5, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.keccak_st, ptr %54, i32 0, i32 0
  %56 = getelementptr inbounds [5 x [5 x i64]], ptr %55, i64 0, i64 0
  %57 = load ptr, ptr %4, align 8, !tbaa !5
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.keccak_st, ptr %58, i32 0, i32 2
  %60 = load i64, ptr %59, align 8, !tbaa !15
  %61 = load i64, ptr %6, align 8, !tbaa !13
  call void @SHA3_squeeze(ptr noundef %56, ptr noundef %57, i64 noundef %60, i64 noundef %61)
  store i32 1, ptr %3, align 4
  store i32 1, ptr %8, align 4
  br label %62

62:                                               ; preds = %20, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  %63 = load i32, ptr %3, align 4
  ret i32 %63
}

declare void @SHA3_squeeze(ptr noundef, ptr noundef, i64 noundef, i64 noundef) #2

attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 #3 = { 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 #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 = !{!10, !11, i64 200}
!10 = !{!"keccak_st", !7, i64 0, !11, i64 200, !11, i64 208, !11, i64 216, !7, i64 224, !7, i64 392, !12, i64 400}
!11 = !{!"long", !7, i64 0}
!12 = !{!"prov_sha3_meth_st", !6, i64 0, !6, i64 8}
!13 = !{!11, !11, i64 0}
!14 = !{!10, !11, i64 216}
!15 = !{!10, !11, i64 208}
!16 = !{!10, !7, i64 392}
!17 = !{!7, !7, i64 0}


; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0

declare i64 @SHA3_absorb(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @ossl_sha3_final(ptr noundef %0, ptr noundef %1) local_unnamed_addr #2 {
  %3 = getelementptr inbounds i8, ptr %1, i64 208
  %4 = load i64, ptr %3, align 8, !tbaa !5
  %5 = icmp eq i64 %4, 0
  br i1 %5, label %22, label %6

6:                                                ; preds = %2
  %7 = getelementptr inbounds i8, ptr %1, i64 216
  %8 = load i64, ptr %7, align 8, !tbaa !12
  %9 = getelementptr inbounds i8, ptr %1, i64 200
  %10 = load i64, ptr %9, align 8, !tbaa !13
  %11 = getelementptr inbounds i8, ptr %1, i64 224
  %12 = getelementptr inbounds i8, ptr %11, i64 %8
  %13 = sub i64 %10, %8
  tail call void @llvm.memset.p0.i64(ptr nonnull align 1 %12, i8 0, i64 %13, i1 false)
  %14 = getelementptr inbounds i8, ptr %1, i64 392
  %15 = load i8, ptr %14, align 8, !tbaa !14
  store i8 %15, ptr %12, align 1, !tbaa !15
  %16 = add i64 %10, -1
  %17 = getelementptr inbounds [168 x i8], ptr %11, i64 0, i64 %16
  %18 = load i8, ptr %17, align 1, !tbaa !15
  %19 = or i8 %18, -128
  store i8 %19, ptr %17, align 1, !tbaa !15
  %20 = tail call i64 @SHA3_absorb(ptr noundef nonnull %1, ptr noundef nonnull %11, i64 noundef %10, i64 noundef %10) #3
  %21 = load i64, ptr %3, align 8, !tbaa !5
  tail call void @SHA3_squeeze(ptr noundef nonnull %1, ptr noundef %0, i64 noundef %21, i64 noundef %10) #3
  br label %22

22:                                               ; preds = %2, %6
  ret i32 1
}

declare void @SHA3_squeeze(ptr noundef, ptr noundef, i64 noundef, i64 noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #1 = { "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 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 #3 = { 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, !9, i64 208}
!6 = !{!"keccak_st", !7, i64 0, !9, i64 200, !9, i64 208, !9, i64 216, !7, i64 224, !7, i64 392, !10, i64 400}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"long", !7, i64 0}
!10 = !{!"prov_sha3_meth_st", !11, i64 0, !11, i64 8}
!11 = !{!"any pointer", !7, i64 0}
!12 = !{!6, !9, i64 216}
!13 = !{!6, !9, i64 200}
!14 = !{!6, !7, i64 392}
!15 = !{!7, !7, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass