; 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.drysponge128_state_t = type { %union.gascon128_state_t, i32, i32, %union.drysponge128_rate_t, %union.drysponge128_x_t }
%union.gascon128_state_t = type { [5 x i64] }
%union.drysponge128_rate_t = type { [2 x i64] }
%union.drysponge128_x_t = type { [2 x i64] }

; Function Attrs: nounwind uwtable
declare dso_local void @drygascon128_f_wrap(ptr noundef, ptr noundef, i32 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
define dso_local void @drysponge128_setup(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) #0 {
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i32 %2, ptr %8, align 4, !tbaa !9
  store ptr %3, ptr %9, align 8, !tbaa !5
  store i32 %4, ptr %10, align 4, !tbaa !9
  %11 = load i32, ptr %8, align 4, !tbaa !9
  %12 = icmp eq i32 56, %11
  br i1 %12, label %13, label %31

13:                                               ; preds = %5
  %14 = load ptr, ptr %6, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.drysponge128_state_t, ptr %14, i32 0, i32 0
  %16 = getelementptr inbounds [40 x i8], ptr %15, i64 0, i64 0
  %17 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %16, ptr align 1 %17, i64 40, i1 false)
  %18 = load ptr, ptr %6, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.drysponge128_state_t, ptr %18, i32 0, i32 4
  %20 = getelementptr inbounds [16 x i8], ptr %19, i64 0, i64 0
  %21 = load ptr, ptr %7, align 8, !tbaa !5
  %22 = getelementptr inbounds i8, ptr %21, i64 40
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %20, ptr align 1 %22, i64 16, i1 false)
  br label %23

23:                                               ; preds = %29, %13
  %24 = load ptr, ptr %6, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.drysponge128_state_t, ptr %24, i32 0, i32 4
  %26 = getelementptr inbounds [4 x i32], ptr %25, i64 0, i64 0
  %27 = call i32 @drysponge_x_words_are_same(ptr noundef %26)
  %28 = icmp ne i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %23
  br label %23, !llvm.loop !11

30:                                               ; preds = %23
  br label %87

31:                                               ; preds = %5
  %32 = load ptr, ptr %6, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.drysponge128_state_t, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds [40 x i8], ptr %33, i64 0, i64 0
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %34, ptr align 1 %35, i64 16, i1 false)
  %36 = load ptr, ptr %6, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.drysponge128_state_t, ptr %36, i32 0, i32 0
  %38 = getelementptr inbounds [40 x i8], ptr %37, i64 0, i64 0
  %39 = getelementptr inbounds i8, ptr %38, i64 16
  %40 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %39, ptr align 1 %40, i64 16, i1 false)
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.drysponge128_state_t, ptr %41, i32 0, i32 0
  %43 = getelementptr inbounds [40 x i8], ptr %42, i64 0, i64 0
  %44 = getelementptr inbounds i8, ptr %43, i64 32
  %45 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %44, ptr align 1 %45, i64 8, i1 false)
  %46 = load i32, ptr %8, align 4, !tbaa !9
  %47 = icmp eq i32 32, %46
  br i1 %47, label %48, label %62

48:                                               ; preds = %31
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.drysponge128_state_t, ptr %49, i32 0, i32 4
  %51 = getelementptr inbounds [16 x i8], ptr %50, i64 0, i64 0
  %52 = load ptr, ptr %7, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i64 16
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %51, ptr align 1 %53, i64 16, i1 false)
  br label %54

54:                                               ; preds = %60, %48
  %55 = load ptr, ptr %6, align 8, !tbaa !5
  %56 = getelementptr inbounds %struct.drysponge128_state_t, ptr %55, i32 0, i32 4
  %57 = getelementptr inbounds [4 x i32], ptr %56, i64 0, i64 0
  %58 = call i32 @drysponge_x_words_are_same(ptr noundef %57)
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %60, label %61

60:                                               ; preds = %54
  br label %54, !llvm.loop !13

61:                                               ; preds = %54
  br label %86

62:                                               ; preds = %31
  %63 = load i32, ptr %8, align 4, !tbaa !9
  %64 = icmp eq i32 16, %63
  br i1 %64, label %65, label %85

65:                                               ; preds = %62
  br label %66

66:                                               ; preds = %68, %65
  %67 = load ptr, ptr %6, align 8, !tbaa !5
  call void @gascon128_g0(ptr noundef %67)
  br label %68

68:                                               ; preds = %66
  %69 = load ptr, ptr %6, align 8, !tbaa !5
  %70 = getelementptr inbounds %struct.drysponge128_state_t, ptr %69, i32 0, i32 0
  %71 = getelementptr inbounds [10 x i32], ptr %70, i64 0, i64 0
  %72 = call i32 @drysponge_x_words_are_same(ptr noundef %71)
  %73 = icmp ne i32 %72, 0
  br i1 %73, label %66, label %74, !llvm.loop !14

74:                                               ; preds = %68
  %75 = load ptr, ptr %6, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.drysponge128_state_t, ptr %75, i32 0, i32 4
  %77 = getelementptr inbounds [4 x i32], ptr %76, i64 0, i64 0
  %78 = load ptr, ptr %6, align 8, !tbaa !5
  %79 = getelementptr inbounds %struct.drysponge128_state_t, ptr %78, i32 0, i32 0
  %80 = getelementptr inbounds [10 x i32], ptr %79, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %77, ptr align 16 %80, i64 16, i1 false)
  %81 = load ptr, ptr %6, align 8, !tbaa !5
  %82 = getelementptr inbounds %struct.drysponge128_state_t, ptr %81, i32 0, i32 0
  %83 = getelementptr inbounds [10 x i32], ptr %82, i64 0, i64 0
  %84 = load ptr, ptr %7, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %83, ptr align 1 %84, i64 16, i1 false)
  br label %85

85:                                               ; preds = %74, %62
  br label %86

86:                                               ; preds = %85, %61
  br label %87

87:                                               ; preds = %86, %30
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.drysponge128_state_t, ptr %88, i32 0, i32 2
  store i32 11, ptr %89, align 4, !tbaa !15
  %90 = load ptr, ptr %6, align 8, !tbaa !5
  %91 = getelementptr inbounds %struct.drysponge128_state_t, ptr %90, i32 0, i32 1
  store i32 1024, ptr %91, align 8, !tbaa !17
  %92 = load i32, ptr %10, align 4, !tbaa !9
  %93 = icmp ne i32 %92, 0
  br i1 %93, label %94, label %99

94:                                               ; preds = %87
  %95 = load ptr, ptr %6, align 8, !tbaa !5
  %96 = getelementptr inbounds %struct.drysponge128_state_t, ptr %95, i32 0, i32 1
  %97 = load i32, ptr %96, align 8, !tbaa !17
  %98 = or i32 %97, 512
  store i32 %98, ptr %96, align 8, !tbaa !17
  br label %99

99:                                               ; preds = %94, %87
  %100 = load ptr, ptr %6, align 8, !tbaa !5
  %101 = load ptr, ptr %9, align 8, !tbaa !5
  call void @drygascon128_f_wrap(ptr noundef %100, ptr noundef %101, i32 noundef 16)
  %102 = load ptr, ptr %6, align 8, !tbaa !5
  %103 = getelementptr inbounds %struct.drysponge128_state_t, ptr %102, i32 0, i32 2
  store i32 7, ptr %103, align 4, !tbaa !15
  ret void
}

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

; Function Attrs: nounwind uwtable
declare hidden void @gascon128_g0(ptr noundef) #0

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 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = !{!16, !10, i64 44}
!16 = !{!"", !7, i64 0, !10, i64 40, !10, i64 44, !7, i64 48, !7, i64 64}
!17 = !{!16, !10, i64 40}


; 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 @drygascon128_f_wrap(ptr noundef, ptr noundef, i32 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
define dso_local void @drysponge128_setup(ptr noundef %0, ptr nocapture noundef readonly %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #0 {
  %6 = icmp eq i32 %2, 56
  br i1 %6, label %7, label %12

7:                                                ; preds = %5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(40) %0, ptr noundef nonnull align 1 dereferenceable(40) %1, i64 40, i1 false)
  %8 = getelementptr inbounds i8, ptr %0, i64 64
  %9 = getelementptr inbounds i8, ptr %1, i64 40
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %8, ptr noundef nonnull align 1 dereferenceable(16) %9, i64 16, i1 false)
  br label %10

10:                                               ; preds = %10, %7
  %11 = tail call i32 @drysponge_x_words_are_same(ptr noundef nonnull %8)
  %.not30 = icmp eq i32 %11, 0
  br i1 %.not30, label %.loopexit, label %10, !llvm.loop !5

12:                                               ; preds = %5
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %0, ptr noundef nonnull align 1 dereferenceable(16) %1, i64 16, i1 false)
  %13 = getelementptr inbounds i8, ptr %0, i64 16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %13, ptr noundef nonnull align 1 dereferenceable(16) %1, i64 16, i1 false)
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = load i64, ptr %1, align 1
  store i64 %15, ptr %14, align 1
  switch i32 %2, label %.loopexit [
    i32 32, label %16
    i32 16, label %.preheader
  ]

16:                                               ; preds = %12
  %17 = getelementptr inbounds i8, ptr %0, i64 64
  %18 = getelementptr inbounds i8, ptr %1, i64 16
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %17, ptr noundef nonnull align 1 dereferenceable(16) %18, i64 16, i1 false)
  br label %19

19:                                               ; preds = %19, %16
  %20 = tail call i32 @drysponge_x_words_are_same(ptr noundef nonnull %17)
  %.not29 = icmp eq i32 %20, 0
  br i1 %.not29, label %.loopexit, label %19, !llvm.loop !7

.preheader:                                       ; preds = %12, %.preheader
  tail call void @gascon128_g0(ptr noundef %0)
  %21 = tail call i32 @drysponge_x_words_are_same(ptr noundef %0)
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %22, label %.preheader, !llvm.loop !8

22:                                               ; preds = %.preheader
  %23 = getelementptr inbounds i8, ptr %0, i64 64
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %23, ptr noundef nonnull align 16 dereferenceable(16) %0, i64 16, i1 false)
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %0, ptr noundef nonnull align 1 dereferenceable(16) %1, i64 16, i1 false)
  br label %.loopexit

.loopexit:                                        ; preds = %19, %10, %12, %22
  %24 = getelementptr inbounds i8, ptr %0, i64 44
  store i32 11, ptr %24, align 4, !tbaa !9
  %.not31 = icmp eq i32 %4, 0
  %spec.select = select i1 %.not31, i32 1024, i32 1536
  %25 = getelementptr inbounds i8, ptr %0, i64 40
  store i32 %spec.select, ptr %25, align 8, !tbaa !14
  tail call void @drygascon128_f_wrap(ptr noundef %0, ptr noundef %3, i32 noundef 16)
  store i32 7, ptr %24, align 4, !tbaa !9
  ret void
}

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

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

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 = distinct !{!7, !6}
!8 = distinct !{!8, !6}
!9 = !{!10, !13, i64 44}
!10 = !{!"", !11, i64 0, !13, i64 40, !13, i64 44, !11, i64 48, !11, i64 64}
!11 = !{!"omnipotent char", !12, i64 0}
!12 = !{!"Simple C/C++ TBAA"}
!13 = !{!"int", !11, i64 0}
!14 = !{!10, !13, i64 40}


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