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

; 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"

; Function Attrs: nounwind uwtable
define dso_local i32 @photon_beetle_128_aead_encrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr noundef %6, ptr noundef %7, ptr noundef %8) #0 {
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i64, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i64, align 8
  %16 = alloca ptr, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca [32 x i8], align 16
  store ptr %0, ptr %10, align 8, !tbaa !5
  store ptr %1, ptr %11, align 8, !tbaa !5
  store ptr %2, ptr %12, align 8, !tbaa !5
  store i64 %3, ptr %13, align 8, !tbaa !9
  store ptr %4, ptr %14, align 8, !tbaa !5
  store i64 %5, ptr %15, align 8, !tbaa !9
  store ptr %6, ptr %16, align 8, !tbaa !5
  store ptr %7, ptr %17, align 8, !tbaa !5
  store ptr %8, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 32, ptr %19) #4
  %20 = load ptr, ptr %16, align 8, !tbaa !5
  %21 = load i64, ptr %13, align 8, !tbaa !9
  %22 = add i64 %21, 16
  %23 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 %22, ptr %23, align 8, !tbaa !9
  %24 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 0
  %25 = load ptr, ptr %17, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %24, ptr align 1 %25, i64 16, i1 false)
  %26 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 0
  %27 = getelementptr inbounds i8, ptr %26, i64 16
  %28 = load ptr, ptr %18, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %27, ptr align 1 %28, i64 16, i1 false)
  %29 = load i64, ptr %15, align 8, !tbaa !9
  %30 = icmp ugt i64 %29, 0
  br i1 %30, label %31, label %38

31:                                               ; preds = %9
  %32 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 0
  %33 = load ptr, ptr %14, align 8, !tbaa !5
  %34 = load i64, ptr %15, align 8, !tbaa !9
  %35 = load i64, ptr %13, align 8, !tbaa !9
  %36 = icmp eq i64 %35, 0
  %37 = zext i1 %36 to i32
  call void @photon_beetle_process_ad(ptr noundef %32, ptr noundef %33, i64 noundef %34, i32 noundef 16, i32 noundef %37)
  br label %48

38:                                               ; preds = %9
  %39 = load i64, ptr %13, align 8, !tbaa !9
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %41, label %47

41:                                               ; preds = %38
  %42 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 31
  %43 = load i8, ptr %42, align 1, !tbaa !11
  %44 = zext i8 %43 to i32
  %45 = xor i32 %44, 32
  %46 = trunc i32 %45 to i8
  store i8 %46, ptr %42, align 1, !tbaa !11
  br label %47

47:                                               ; preds = %41, %38
  br label %48

48:                                               ; preds = %47, %31
  %49 = load i64, ptr %13, align 8, !tbaa !9
  %50 = icmp ugt i64 %49, 0
  br i1 %50, label %51, label %59

51:                                               ; preds = %48
  %52 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 0
  %53 = load ptr, ptr %10, align 8, !tbaa !5
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = load i64, ptr %13, align 8, !tbaa !9
  %56 = load i64, ptr %15, align 8, !tbaa !9
  %57 = icmp eq i64 %56, 0
  %58 = zext i1 %57 to i32
  call void @photon_beetle_encrypt(ptr noundef %52, ptr noundef %53, ptr noundef %54, i64 noundef %55, i32 noundef 16, i32 noundef %58)
  br label %59

59:                                               ; preds = %51, %48
  %60 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 0
  call void @photon256_permute(ptr noundef %60)
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load i64, ptr %13, align 8, !tbaa !9
  %63 = getelementptr inbounds i8, ptr %61, i64 %62
  %64 = getelementptr inbounds [32 x i8], ptr %19, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %63, ptr align 16 %64, i64 16, i1 false)
  call void @llvm.lifetime.end.p0(i64 32, ptr %19) #4
  ret i32 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 nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #2

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

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

declare void @photon256_permute(ptr noundef) #3

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

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: 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 = { 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}
!11 = !{!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: nounwind uwtable
define dso_local noundef i32 @photon_beetle_128_aead_encrypt(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr noundef %2, i64 noundef %3, ptr noundef %4, i64 noundef %5, ptr nocapture noundef readnone %6, ptr nocapture noundef readonly %7, ptr nocapture noundef readonly %8) local_unnamed_addr #0 {
  %10 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %10) #4
  %11 = add i64 %3, 16
  store i64 %11, ptr %1, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %10, ptr noundef nonnull align 1 dereferenceable(16) %7, i64 16, i1 false)
  %12 = getelementptr inbounds i8, ptr %10, i64 16
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %12, ptr noundef nonnull align 1 dereferenceable(16) %8, i64 16, i1 false)
  %.not = icmp eq i64 %5, 0
  %cond = icmp eq i64 %3, 0
  br i1 %.not, label %13, label %17

13:                                               ; preds = %9
  br i1 %cond, label %.thread, label %19

.thread:                                          ; preds = %13
  %14 = getelementptr inbounds i8, ptr %10, i64 31
  %15 = load i8, ptr %14, align 1, !tbaa !9
  %16 = xor i8 %15, 32
  store i8 %16, ptr %14, align 1, !tbaa !9
  br label %21

17:                                               ; preds = %9
  %18 = zext i1 %cond to i32
  call void @photon_beetle_process_ad(ptr noundef nonnull %10, ptr noundef %4, i64 noundef %5, i32 noundef 16, i32 noundef %18)
  br i1 %cond, label %21, label %19

19:                                               ; preds = %13, %17
  %20 = zext i1 %.not to i32
  call void @photon_beetle_encrypt(ptr noundef nonnull %10, ptr noundef %0, ptr noundef %2, i64 noundef %3, i32 noundef 16, i32 noundef %20)
  br label %21

21:                                               ; preds = %.thread, %19, %17
  call void @photon256_permute(ptr noundef nonnull %10) #4
  %22 = getelementptr inbounds i8, ptr %0, i64 %3
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(16) %22, ptr noundef nonnull align 16 dereferenceable(16) %10, i64 16, i1 false)
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %10) #4
  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: 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) #2

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

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

declare void @photon256_permute(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

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: 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 = { 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"}
!9 = !{!7, !7, i64 0}


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