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

; 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.skinny_128_384_key_schedule_t = type { [16 x i8], [112 x i32] }

; Function Attrs: nounwind uwtable
define dso_local i32 @romulus_m1_aead_decrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, ptr noundef %8) #0 {
  %10 = alloca i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca %struct.skinny_128_384_key_schedule_t, align 4
  %21 = alloca [16 x i8], align 16
  %22 = alloca i32, align 4
  store ptr %0, ptr %11, align 8, !tbaa !5
  store ptr %1, ptr %12, align 8, !tbaa !5
  store ptr %2, ptr %13, align 8, !tbaa !5
  store ptr %3, ptr %14, align 8, !tbaa !5
  store i64 %4, ptr %15, align 8, !tbaa !9
  store ptr %5, ptr %16, align 8, !tbaa !5
  store i64 %6, ptr %17, align 8, !tbaa !9
  store ptr %7, ptr %18, align 8, !tbaa !5
  store ptr %8, ptr %19, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 464, ptr %20) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr %21) #6
  %23 = load ptr, ptr %13, align 8, !tbaa !5
  %24 = load i64, ptr %15, align 8, !tbaa !9
  %25 = icmp ult i64 %24, 16
  br i1 %25, label %26, label %27

26:                                               ; preds = %9
  store i32 -1, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %67

27:                                               ; preds = %9
  %28 = load i64, ptr %15, align 8, !tbaa !9
  %29 = sub i64 %28, 16
  %30 = load ptr, ptr %12, align 8, !tbaa !5
  store i64 %29, ptr %30, align 8, !tbaa !9
  %31 = load i64, ptr %17, align 8, !tbaa !9
  %32 = icmp ugt i64 %31, 134217728
  br i1 %32, label %36, label %33

33:                                               ; preds = %27
  %34 = load i64, ptr %15, align 8, !tbaa !9
  %35 = icmp ugt i64 %34, 134217744
  br i1 %35, label %36, label %37

36:                                               ; preds = %33, %27
  store i32 -2, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %67

37:                                               ; preds = %33
  %38 = load ptr, ptr %19, align 8, !tbaa !5
  %39 = load ptr, ptr %18, align 8, !tbaa !5
  call void @romulus1_init(ptr noundef %20, ptr noundef %38, ptr noundef %39)
  %40 = load i64, ptr %15, align 8, !tbaa !9
  %41 = sub i64 %40, 16
  store i64 %41, ptr %15, align 8, !tbaa !9
  %42 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  %43 = load ptr, ptr %14, align 8, !tbaa !5
  %44 = load i64, ptr %15, align 8, !tbaa !9
  %45 = getelementptr inbounds i8, ptr %43, i64 %44
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %42, ptr align 1 %45, i64 16, i1 false)
  %46 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  %47 = load ptr, ptr %11, align 8, !tbaa !5
  %48 = load ptr, ptr %14, align 8, !tbaa !5
  %49 = load i64, ptr %15, align 8, !tbaa !9
  call void @romulus_m1_decrypt(ptr noundef %20, ptr noundef %46, ptr noundef %47, ptr noundef %48, i64 noundef %49)
  %50 = load ptr, ptr %19, align 8, !tbaa !5
  call void @romulus1_init(ptr noundef %20, ptr noundef %50, ptr noundef null)
  %51 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 16 %51, i8 0, i64 16, i1 false)
  %52 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  %53 = load ptr, ptr %18, align 8, !tbaa !5
  %54 = load ptr, ptr %16, align 8, !tbaa !5
  %55 = load i64, ptr %17, align 8, !tbaa !9
  %56 = load ptr, ptr %11, align 8, !tbaa !5
  %57 = load i64, ptr %15, align 8, !tbaa !9
  call void @romulus_m1_process_ad(ptr noundef %20, ptr noundef %52, ptr noundef %53, ptr noundef %54, i64 noundef %55, ptr noundef %56, i64 noundef %57)
  %58 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  %59 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  call void @romulus_generate_tag(ptr noundef %58, ptr noundef %59)
  %60 = load ptr, ptr %11, align 8, !tbaa !5
  %61 = load i64, ptr %15, align 8, !tbaa !9
  %62 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  %63 = load ptr, ptr %14, align 8, !tbaa !5
  %64 = load i64, ptr %15, align 8, !tbaa !9
  %65 = getelementptr inbounds i8, ptr %63, i64 %64
  %66 = call i32 @aead_check_tag(ptr noundef %60, i64 noundef %61, ptr noundef %62, ptr noundef %65, i32 noundef 16)
  store i32 %66, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %67

67:                                               ; preds = %37, %36, %26
  call void @llvm.lifetime.end.p0(i64 16, ptr %21) #6
  call void @llvm.lifetime.end.p0(i64 464, ptr %20) #6
  %68 = load i32, ptr %10, align 4
  ret i32 %68
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @romulus_generate_tag(ptr noundef, ptr noundef) #3

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

declare i32 @aead_check_tag(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) #4

; Function Attrs: nounwind uwtable
declare hidden void @romulus_m1_process_ad(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 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) #5

; Function Attrs: nounwind uwtable
declare hidden void @romulus_m1_decrypt(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { inlinehint 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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 long", !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"

%struct.skinny_128_384_key_schedule_t = type { [16 x i8], [112 x i32] }

; Function Attrs: nounwind uwtable
define dso_local i32 @romulus_m1_aead_decrypt(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef readnone %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %6, ptr noundef %7, ptr noundef %8) local_unnamed_addr #0 {
  %10 = alloca %struct.skinny_128_384_key_schedule_t, align 4
  %11 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 464, ptr nonnull %10) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %11) #6
  %12 = icmp ult i64 %4, 16
  br i1 %12, label %20, label %13

13:                                               ; preds = %9
  %14 = add i64 %4, -16
  store i64 %14, ptr %1, align 8, !tbaa !5
  %15 = icmp ugt i64 %6, 134217728
  %16 = icmp ugt i64 %4, 134217744
  %or.cond = or i1 %16, %15
  br i1 %or.cond, label %20, label %17

17:                                               ; preds = %13
  call void @romulus1_init(ptr noundef nonnull %10, ptr noundef %8, ptr noundef %7)
  %18 = getelementptr inbounds i8, ptr %3, i64 %14
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %11, ptr noundef nonnull align 1 dereferenceable(16) %18, i64 16, i1 false)
  call void @romulus_m1_decrypt(ptr noundef nonnull %10, ptr noundef nonnull %11, ptr noundef %0, ptr noundef %3, i64 noundef %14)
  call void @romulus1_init(ptr noundef nonnull %10, ptr noundef %8, ptr noundef null)
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %11, i8 0, i64 16, i1 false)
  call void @romulus_m1_process_ad(ptr noundef nonnull %10, ptr noundef nonnull %11, ptr noundef %7, ptr noundef %5, i64 noundef %6, ptr noundef %0, i64 noundef %14)
  call void @romulus_generate_tag(ptr noundef nonnull %11, ptr noundef nonnull %11)
  %19 = call i32 @aead_check_tag(ptr noundef %0, i64 noundef %14, ptr noundef nonnull %11, ptr noundef %18, i32 noundef 16) #6
  br label %20

20:                                               ; preds = %13, %9, %17
  %.0 = phi i32 [ %19, %17 ], [ -1, %9 ], [ -2, %13 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %11) #6
  call void @llvm.lifetime.end.p0(i64 464, ptr nonnull %10) #6
  ret i32 %.0
}

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

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden void @romulus_generate_tag(ptr noundef, ptr noundef) local_unnamed_addr #3

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

declare i32 @aead_check_tag(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

; Function Attrs: nounwind uwtable
declare hidden void @romulus_m1_process_ad(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, i64 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) #5

; Function Attrs: nounwind uwtable
declare hidden void @romulus_m1_decrypt(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { inlinehint 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 = { "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


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