; LLVM IR from cryspen/libcrux :: sys/hacl/c/src (Hacl_Hash_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.Hacl_Hash_SHA3_state_t_s = type { %struct.Hacl_Hash_SHA3_hash_buf_s, ptr, i64 }
%struct.Hacl_Hash_SHA3_hash_buf_s = type { i8, ptr }
%struct.hash_buf2_s = type { %struct.Hacl_Hash_SHA3_hash_buf_s, %struct.Hacl_Hash_SHA3_hash_buf_s }

@.str = external hidden unnamed_addr constant [70 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [81 x i8], align 1

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

; Function Attrs: nounwind uwtable
declare hidden i32 @block_len(i8 noundef zeroext) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

declare i32 @printf(ptr noundef, ...) #3

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) #4

; Function Attrs: nounwind allocsize(0,1)
declare noalias ptr @calloc(i64 noundef, i64 noundef) #5

; Function Attrs: nounwind allocsize(0)
declare noalias ptr @malloc(i64 noundef) #6

; Function Attrs: nounwind uwtable
define dso_local ptr @Hacl_Hash_SHA3_copy(ptr noundef %0) #1 {
  %2 = alloca ptr, align 8
  %3 = alloca %struct.Hacl_Hash_SHA3_state_t_s, align 8
  %4 = alloca %struct.Hacl_Hash_SHA3_hash_buf_s, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i8, align 1
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca %struct.Hacl_Hash_SHA3_hash_buf_s, align 8
  %11 = alloca %struct.hash_buf2_s, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca %struct.Hacl_Hash_SHA3_state_t_s, align 8
  %15 = alloca ptr, align 8
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %3) #7
  %16 = load ptr, ptr %2, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %3, ptr align 8 %16, i64 32, i1 false), !tbaa.struct !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %4) #7
  %17 = getelementptr inbounds %struct.Hacl_Hash_SHA3_state_t_s, ptr %3, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %4, ptr align 8 %17, i64 16, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #7
  %18 = getelementptr inbounds %struct.Hacl_Hash_SHA3_state_t_s, ptr %3, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !14
  store ptr %19, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #7
  %20 = getelementptr inbounds %struct.Hacl_Hash_SHA3_state_t_s, ptr %3, i32 0, i32 2
  %21 = load i64, ptr %20, align 8, !tbaa !17
  store i64 %21, ptr %6, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 1, ptr %7) #7
  %22 = getelementptr inbounds %struct.Hacl_Hash_SHA3_hash_buf_s, ptr %4, i32 0, i32 0
  %23 = load i8, ptr %22, align 8, !tbaa !18
  store i8 %23, ptr %7, align 1, !tbaa !10
  br label %24

24:                                               ; preds = %1
  %25 = load i8, ptr %7, align 1, !tbaa !10
  %26 = call i32 @block_len(i8 noundef zeroext %25)
  %27 = zext i32 %26 to i64
  %28 = icmp ugt i64 %27, -1
  br i1 %28, label %29, label %31

29:                                               ; preds = %24
  %30 = call i32 (ptr, ...) @printf(ptr noundef @.str, ptr noundef @.str.1, i32 noundef 207)
  call void @exit(i32 noundef 253) #8
  unreachable

31:                                               ; preds = %24
  br label %32

32:                                               ; preds = %31
  br label %33

33:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #7
  %34 = load i8, ptr %7, align 1, !tbaa !10
  %35 = call i32 @block_len(i8 noundef zeroext %34)
  %36 = zext i32 %35 to i64
  %37 = call noalias ptr @calloc(i64 noundef %36, i64 noundef 1) #9
  store ptr %37, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = load i8, ptr %7, align 1, !tbaa !10
  %41 = call i32 @block_len(i8 noundef zeroext %40)
  %42 = zext i32 %41 to i64
  %43 = mul i64 %42, 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %38, ptr align 1 %39, i64 %43, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #7
  %44 = call noalias ptr @calloc(i64 noundef 25, i64 noundef 8) #9
  store ptr %44, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %10) #7
  %45 = getelementptr inbounds %struct.Hacl_Hash_SHA3_hash_buf_s, ptr %10, i32 0, i32 0
  %46 = load i8, ptr %7, align 1, !tbaa !10
  store i8 %46, ptr %45, align 8, !tbaa !18
  %47 = getelementptr inbounds %struct.Hacl_Hash_SHA3_hash_buf_s, ptr %10, i32 0, i32 1
  %48 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %48, ptr %47, align 8, !tbaa !19
  call void @llvm.lifetime.start.p0(i64 32, ptr %11) #7
  %49 = getelementptr inbounds %struct.hash_buf2_s, ptr %11, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %49, ptr align 8 %4, i64 16, i1 false), !tbaa.struct !13
  %50 = getelementptr inbounds %struct.hash_buf2_s, ptr %11, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %50, ptr align 8 %10, i64 16, i1 false), !tbaa.struct !13
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #7
  %51 = getelementptr inbounds %struct.hash_buf2_s, ptr %11, i32 0, i32 1
  %52 = getelementptr inbounds %struct.Hacl_Hash_SHA3_hash_buf_s, ptr %51, i32 0, i32 1
  %53 = load ptr, ptr %52, align 8, !tbaa !20
  store ptr %53, ptr %12, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #7
  %54 = getelementptr inbounds %struct.hash_buf2_s, ptr %11, i32 0, i32 0
  %55 = getelementptr inbounds %struct.Hacl_Hash_SHA3_hash_buf_s, ptr %54, i32 0, i32 1
  %56 = load ptr, ptr %55, align 8, !tbaa !22
  store ptr %56, ptr %13, align 8, !tbaa !5
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  %58 = load ptr, ptr %13, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %57, ptr align 8 %58, i64 200, i1 false)
  call void @llvm.lifetime.start.p0(i64 32, ptr %14) #7
  %59 = getelementptr inbounds %struct.Hacl_Hash_SHA3_state_t_s, ptr %14, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %59, ptr align 8 %10, i64 16, i1 false), !tbaa.struct !13
  %60 = getelementptr inbounds %struct.Hacl_Hash_SHA3_state_t_s, ptr %14, i32 0, i32 1
  %61 = load ptr, ptr %8, align 8, !tbaa !5
  store ptr %61, ptr %60, align 8, !tbaa !14
  %62 = getelementptr inbounds %struct.Hacl_Hash_SHA3_state_t_s, ptr %14, i32 0, i32 2
  %63 = load i64, ptr %6, align 8, !tbaa !11
  store i64 %63, ptr %62, align 8, !tbaa !17
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #7
  %64 = call noalias ptr @malloc(i64 noundef 32) #10
  store ptr %64, ptr %15, align 8, !tbaa !5
  %65 = load ptr, ptr %15, align 8, !tbaa !5
  %66 = getelementptr inbounds %struct.Hacl_Hash_SHA3_state_t_s, ptr %65, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %66, ptr align 8 %14, i64 32, i1 false), !tbaa.struct !9
  %67 = load ptr, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #7
  call void @llvm.lifetime.end.p0(i64 32, ptr %14) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 32, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %10) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 1, ptr %7) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #7
  call void @llvm.lifetime.end.p0(i64 16, ptr %4) #7
  call void @llvm.lifetime.end.p0(i64 32, ptr %3) #7
  ret ptr %67
}

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: readwrite) }
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 = { noreturn nounwind "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 #5 = { nounwind allocsize(0,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 #6 = { nounwind allocsize(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 #7 = { nounwind }
attributes #8 = { noreturn nounwind }
attributes #9 = { nounwind allocsize(0,1) }
attributes #10 = { nounwind allocsize(0) }

!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 = !{i64 0, i64 1, !10, i64 8, i64 8, !5, i64 16, i64 8, !5, i64 24, i64 8, !11}
!10 = !{!7, !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !7, i64 0}
!13 = !{i64 0, i64 1, !10, i64 8, i64 8, !5}
!14 = !{!15, !6, i64 16}
!15 = !{!"Hacl_Hash_SHA3_state_t_s", !16, i64 0, !6, i64 16, !12, i64 24}
!16 = !{!"Hacl_Hash_SHA3_hash_buf_s", !7, i64 0, !6, i64 8}
!17 = !{!15, !12, i64 24}
!18 = !{!16, !7, i64 0}
!19 = !{!16, !6, i64 8}
!20 = !{!21, !6, i64 24}
!21 = !{!"hash_buf2_s", !16, i64 0, !16, i64 16}
!22 = !{!21, !6, i64 8}


; 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 hidden i32 @block_len(i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #1

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @calloc(i64 noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
define dso_local noalias noundef ptr @Hacl_Hash_SHA3_copy(ptr nocapture noundef readonly %0) local_unnamed_addr #0 {
  %.sroa.0.0.copyload27 = load i64, ptr %0, align 8
  %.sroa.428.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 8
  %.sroa.428.0.copyload = load ptr, ptr %.sroa.428.0..sroa_idx, align 8, !tbaa !5
  %.sroa.529.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 16
  %.sroa.529.0.copyload = load ptr, ptr %.sroa.529.0..sroa_idx, align 8, !tbaa !5
  %.sroa.6.0..sroa_idx = getelementptr inbounds i8, ptr %0, i64 24
  %.sroa.6.0.copyload = load i64, ptr %.sroa.6.0..sroa_idx, align 8, !tbaa !9
  %.sroa.0.sroa.026.0.extract.trunc = trunc i64 %.sroa.0.0.copyload27 to i8
  %2 = tail call i32 @block_len(i8 noundef zeroext %.sroa.0.sroa.026.0.extract.trunc)
  %3 = tail call i32 @block_len(i8 noundef zeroext %.sroa.0.sroa.026.0.extract.trunc)
  %4 = zext i32 %3 to i64
  %5 = tail call noalias ptr @calloc(i64 noundef %4, i64 noundef 1) #4
  %6 = tail call i32 @block_len(i8 noundef zeroext %.sroa.0.sroa.026.0.extract.trunc)
  %7 = zext i32 %6 to i64
  tail call void @llvm.memcpy.p0.p0.i64(ptr align 1 %5, ptr align 1 %.sroa.529.0.copyload, i64 %7, i1 false)
  %8 = tail call noalias dereferenceable_or_null(200) ptr @calloc(i64 noundef 25, i64 noundef 8) #4
  %.sroa.0.sroa.026.0.insert.ext = and i64 %.sroa.0.0.copyload27, 255
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(200) %8, ptr noundef nonnull align 8 dereferenceable(200) %.sroa.428.0.copyload, i64 200, i1 false)
  %9 = tail call noalias dereferenceable_or_null(32) ptr @malloc(i64 noundef 32) #5
  store i64 %.sroa.0.sroa.026.0.insert.ext, ptr %9, align 8
  %.sroa.0.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %9, i64 8
  store ptr %8, ptr %.sroa.0.sroa.4.0..sroa_idx, align 8, !tbaa !5
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %9, i64 16
  store ptr %5, ptr %.sroa.4.0..sroa_idx, align 8, !tbaa !5
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %9, i64 24
  store i64 %.sroa.6.0.copyload, ptr %.sroa.5.0..sroa_idx, align 8, !tbaa !9
  ret ptr %9
}

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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn allockind("alloc,zeroed") allocsize(0,1) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" "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 allocsize(0,1) }
attributes #5 = { nounwind allocsize(0) }

!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}


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