; LLVM IR from rweather/lightweight-crypto :: src/combined (internal-drysponge)

; 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.drysponge256_state_t = type { %union.gascon256_state_t, %union.drysponge256_rate_t, %union.drysponge256_x_t, i32, i32 }
%union.gascon256_state_t = type { [9 x i64] }
%union.drysponge256_rate_t = type { [2 x i64] }
%union.drysponge256_x_t = type { [2 x i64] }

; Function Attrs: nounwind uwtable
declare dso_local void @gascon256_core_round(ptr noundef, i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare dso_local void @drysponge256_g(ptr noundef) #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) #1

; Function Attrs: nounwind uwtable
declare dso_local void @drysponge256_f_absorb(ptr noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind uwtable
declare hidden i32 @drysponge_x_words_are_same(ptr noundef) #0

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

23:                                               ; preds = %26, %4
  %24 = load ptr, ptr %5, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.drysponge256_state_t, ptr %24, i32 0, i32 0
  call void @gascon256_core_round(ptr noundef %25, i8 noundef zeroext 0)
  br label %26

26:                                               ; preds = %23
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %struct.drysponge256_state_t, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds [18 x i32], ptr %28, i64 0, i64 0
  %30 = call i32 @drysponge_x_words_are_same(ptr noundef %29)
  %31 = icmp ne i32 %30, 0
  br i1 %31, label %23, label %32, !llvm.loop !11

32:                                               ; preds = %26
  %33 = load ptr, ptr %5, align 8, !tbaa !5
  %34 = getelementptr inbounds %struct.drysponge256_state_t, ptr %33, i32 0, i32 2
  %35 = getelementptr inbounds [4 x i32], ptr %34, i64 0, i64 0
  %36 = load ptr, ptr %5, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.drysponge256_state_t, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds [18 x i32], ptr %37, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %35, ptr align 8 %38, i64 16, i1 false)
  %39 = load ptr, ptr %5, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.drysponge256_state_t, ptr %39, i32 0, i32 0
  %41 = getelementptr inbounds [18 x i32], ptr %40, i64 0, i64 0
  %42 = load ptr, ptr %6, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %41, ptr align 1 %42, i64 16, i1 false)
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.drysponge256_state_t, ptr %43, i32 0, i32 4
  store i32 12, ptr %44, align 4, !tbaa !13
  %45 = load ptr, ptr %5, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.drysponge256_state_t, ptr %45, i32 0, i32 3
  store i32 16, ptr %46, align 8, !tbaa !15
  %47 = load i32, ptr %8, align 4, !tbaa !9
  %48 = icmp ne i32 %47, 0
  br i1 %48, label %49, label %54

49:                                               ; preds = %32
  %50 = load ptr, ptr %5, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.drysponge256_state_t, ptr %50, i32 0, i32 3
  %52 = load i32, ptr %51, align 8, !tbaa !15
  %53 = or i32 %52, 8
  store i32 %53, ptr %51, align 8, !tbaa !15
  br label %54

54:                                               ; preds = %49, %32
  %55 = load ptr, ptr %5, align 8, !tbaa !5
  %56 = load ptr, ptr %7, align 8, !tbaa !5
  call void @drysponge256_f_absorb(ptr noundef %55, ptr noundef %56, i32 noundef 16)
  %57 = load ptr, ptr %5, align 8, !tbaa !5
  call void @drysponge256_g(ptr noundef %57)
  %58 = load ptr, ptr %5, align 8, !tbaa !5
  %59 = getelementptr inbounds %struct.drysponge256_state_t, ptr %58, i32 0, i32 4
  store i32 8, ptr %59, align 4, !tbaa !13
  ret void
}

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 nounwind willreturn memory(argmem: readwrite) }

!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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!14, !10, i64 108}
!14 = !{!"", !7, i64 0, !7, i64 72, !7, i64 88, !10, i64 104, !10, i64 108}
!15 = !{!14, !10, i64 104}


; 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 @gascon256_core_round(ptr noundef, i8 noundef zeroext) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local void @drysponge256_g(ptr noundef) 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: nounwind uwtable
declare dso_local void @drysponge256_f_absorb(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare hidden i32 @drysponge_x_words_are_same(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local void @drysponge256_setup(ptr noundef %0, ptr nocapture noundef readonly %1, ptr noundef %2, i32 noundef %3) local_unnamed_addr #0 {
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(32) %0, ptr noundef nonnull align 1 dereferenceable(32) %1, i64 32, i1 false)
  %5 = getelementptr inbounds i8, ptr %0, i64 32
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(32) %5, ptr noundef nonnull align 1 dereferenceable(32) %1, i64 32, i1 false)
  %6 = getelementptr inbounds i8, ptr %0, i64 64
  %7 = load i64, ptr %1, align 1
  store i64 %7, ptr %6, align 1
  br label %8

8:                                                ; preds = %8, %4
  tail call void @gascon256_core_round(ptr noundef %0, i8 noundef zeroext 0)
  %9 = tail call i32 @drysponge_x_words_are_same(ptr noundef %0)
  %.not = icmp eq i32 %9, 0
  br i1 %.not, label %10, label %8, !llvm.loop !5

10:                                               ; preds = %8
  %11 = getelementptr inbounds i8, ptr %0, i64 88
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %11, ptr noundef nonnull align 8 dereferenceable(16) %0, i64 16, i1 false)
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %0, ptr noundef nonnull align 1 dereferenceable(16) %1, i64 16, i1 false)
  %12 = getelementptr inbounds i8, ptr %0, i64 108
  store i32 12, ptr %12, align 4, !tbaa !7
  %.not19 = icmp eq i32 %3, 0
  %spec.select = select i1 %.not19, i32 16, i32 24
  %13 = getelementptr inbounds i8, ptr %0, i64 104
  store i32 %spec.select, ptr %13, align 8, !tbaa !12
  tail call void @drysponge256_f_absorb(ptr noundef %0, ptr noundef %2, i32 noundef 16)
  tail call void @drysponge256_g(ptr noundef %0)
  store i32 8, ptr %12, align 4, !tbaa !7
  ret void
}

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

!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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = !{!8, !11, i64 108}
!8 = !{!"", !9, i64 0, !9, i64 72, !9, i64 88, !11, i64 104, !11, i64 108}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
!11 = !{!"int", !9, i64 0}
!12 = !{!8, !11, i64 104}


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