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

; 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 @comet_64_cham_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 [8 x i8], align 1
  %20 = alloca [16 x i8], align 16
  %21 = alloca ptr, align 8
  %22 = alloca ptr, align 8
  %23 = alloca i32, align 4
  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 8, ptr %19) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %20) #5
  %24 = load ptr, ptr %16, align 8, !tbaa !5
  %25 = load i64, ptr %13, align 8, !tbaa !9
  %26 = add i64 %25, 8
  %27 = load ptr, ptr %11, align 8, !tbaa !5
  store i64 %26, ptr %27, align 8, !tbaa !9
  %28 = getelementptr inbounds [8 x i8], ptr %19, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %28, i8 0, i64 8, i1 false)
  %29 = load ptr, ptr %18, align 8, !tbaa !5
  %30 = getelementptr inbounds [8 x i8], ptr %19, i64 0, i64 0
  %31 = getelementptr inbounds [8 x i8], ptr %19, i64 0, i64 0
  call void @cham64_128_encrypt(ptr noundef %29, ptr noundef %30, ptr noundef %31)
  %32 = getelementptr inbounds [16 x i8], ptr %20, i64 0, i64 0
  %33 = load ptr, ptr %17, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %32, ptr align 1 %33, i64 15, i1 false)
  %34 = getelementptr inbounds [16 x i8], ptr %20, i64 0, i64 15
  store i8 0, ptr %34, align 1, !tbaa !11
  br label %35

35:                                               ; preds = %9
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #5
  %36 = getelementptr inbounds [16 x i8], ptr %20, i64 0, i64 0
  store ptr %36, ptr %21, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #5
  %37 = load ptr, ptr %18, align 8, !tbaa !5
  store ptr %37, ptr %22, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #5
  store i32 16, ptr %23, align 4, !tbaa !12
  br label %38

38:                                               ; preds = %41, %35
  %39 = load i32, ptr %23, align 4, !tbaa !12
  %40 = icmp ugt i32 %39, 0
  br i1 %40, label %41, label %54

41:                                               ; preds = %38
  %42 = load ptr, ptr %22, align 8, !tbaa !5
  %43 = getelementptr inbounds i8, ptr %42, i32 1
  store ptr %43, ptr %22, align 8, !tbaa !5
  %44 = load i8, ptr %42, align 1, !tbaa !11
  %45 = zext i8 %44 to i32
  %46 = load ptr, ptr %21, align 8, !tbaa !5
  %47 = getelementptr inbounds i8, ptr %46, i32 1
  store ptr %47, ptr %21, align 8, !tbaa !5
  %48 = load i8, ptr %46, align 1, !tbaa !11
  %49 = zext i8 %48 to i32
  %50 = xor i32 %49, %45
  %51 = trunc i32 %50 to i8
  store i8 %51, ptr %46, align 1, !tbaa !11
  %52 = load i32, ptr %23, align 4, !tbaa !12
  %53 = add i32 %52, -1
  store i32 %53, ptr %23, align 4, !tbaa !12
  br label %38, !llvm.loop !14

54:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #5
  br label %55

55:                                               ; preds = %54
  br label %56

56:                                               ; preds = %55
  %57 = load i64, ptr %15, align 8, !tbaa !9
  %58 = icmp ugt i64 %57, 0
  br i1 %58, label %59, label %64

59:                                               ; preds = %56
  %60 = getelementptr inbounds [8 x i8], ptr %19, i64 0, i64 0
  %61 = getelementptr inbounds [16 x i8], ptr %20, i64 0, i64 0
  %62 = load ptr, ptr %14, align 8, !tbaa !5
  %63 = load i64, ptr %15, align 8, !tbaa !9
  call void @comet_process_ad(ptr noundef %60, ptr noundef %61, i32 noundef 8, ptr noundef @cham64_128_encrypt, ptr noundef %62, i64 noundef %63)
  br label %64

64:                                               ; preds = %59, %56
  %65 = load i64, ptr %13, align 8, !tbaa !9
  %66 = icmp ugt i64 %65, 0
  br i1 %66, label %67, label %73

67:                                               ; preds = %64
  %68 = getelementptr inbounds [8 x i8], ptr %19, i64 0, i64 0
  %69 = getelementptr inbounds [16 x i8], ptr %20, i64 0, i64 0
  %70 = load ptr, ptr %10, align 8, !tbaa !5
  %71 = load ptr, ptr %12, align 8, !tbaa !5
  %72 = load i64, ptr %13, align 8, !tbaa !9
  call void @comet_encrypt_64(ptr noundef %68, ptr noundef %69, ptr noundef @cham64_128_encrypt, ptr noundef %70, ptr noundef %71, i64 noundef %72)
  br label %73

73:                                               ; preds = %67, %64
  %74 = getelementptr inbounds [16 x i8], ptr %20, i64 0, i64 15
  %75 = load i8, ptr %74, align 1, !tbaa !11
  %76 = zext i8 %75 to i32
  %77 = xor i32 %76, 128
  %78 = trunc i32 %77 to i8
  store i8 %78, ptr %74, align 1, !tbaa !11
  %79 = getelementptr inbounds [16 x i8], ptr %20, i64 0, i64 0
  call void @comet_adjust_block_key(ptr noundef %79)
  %80 = getelementptr inbounds [16 x i8], ptr %20, i64 0, i64 0
  %81 = load ptr, ptr %10, align 8, !tbaa !5
  %82 = load i64, ptr %13, align 8, !tbaa !9
  %83 = getelementptr inbounds i8, ptr %81, i64 %82
  %84 = getelementptr inbounds [8 x i8], ptr %19, i64 0, i64 0
  call void @cham64_128_encrypt(ptr noundef %80, ptr noundef %83, ptr noundef %84)
  call void @llvm.lifetime.end.p0(i64 16, ptr %20) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #5
  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 @comet_process_ad(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, i64 noundef) #0

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

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

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

declare void @cham64_128_encrypt(ptr noundef, ptr noundef, ptr noundef) #4

; Function Attrs: nounwind uwtable
declare hidden void @comet_encrypt_64(ptr noundef, 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: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 = { 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}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}


; 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 @comet_64_cham_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 noundef %8) local_unnamed_addr #0 {
  %10 = alloca [8 x i8], align 8
  %11 = alloca [16 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %11) #4
  %12 = add i64 %3, 8
  store i64 %12, ptr %1, align 8, !tbaa !5
  store i64 0, ptr %10, align 8
  call void @cham64_128_encrypt(ptr noundef %8, ptr noundef nonnull %10, ptr noundef nonnull %10) #4
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(15) %11, ptr noundef nonnull align 1 dereferenceable(15) %7, i64 15, i1 false)
  %13 = getelementptr inbounds i8, ptr %8, i64 8
  %14 = getelementptr inbounds i8, ptr %11, i64 8
  %15 = load <8 x i8>, ptr %8, align 1, !tbaa !9
  %16 = load <8 x i8>, ptr %11, align 16, !tbaa !9
  %17 = xor <8 x i8> %16, %15
  store <8 x i8> %17, ptr %11, align 16, !tbaa !9
  %18 = getelementptr inbounds i8, ptr %8, i64 12
  %19 = getelementptr inbounds i8, ptr %11, i64 12
  %20 = load <4 x i8>, ptr %13, align 1, !tbaa !9
  %21 = load <4 x i8>, ptr %14, align 8, !tbaa !9
  %22 = xor <4 x i8> %21, %20
  store <4 x i8> %22, ptr %14, align 8, !tbaa !9
  %23 = getelementptr inbounds i8, ptr %8, i64 13
  %24 = load i8, ptr %18, align 1, !tbaa !9
  %25 = getelementptr inbounds i8, ptr %11, i64 13
  %26 = load i8, ptr %19, align 4, !tbaa !9
  %27 = xor i8 %26, %24
  store i8 %27, ptr %19, align 4, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %8, i64 14
  %29 = load i8, ptr %23, align 1, !tbaa !9
  %30 = getelementptr inbounds i8, ptr %11, i64 14
  %31 = load i8, ptr %25, align 1, !tbaa !9
  %32 = xor i8 %31, %29
  store i8 %32, ptr %25, align 1, !tbaa !9
  %33 = getelementptr inbounds i8, ptr %8, i64 15
  %34 = load i8, ptr %28, align 1, !tbaa !9
  %35 = getelementptr inbounds i8, ptr %11, i64 15
  %36 = load i8, ptr %30, align 2, !tbaa !9
  %37 = xor i8 %36, %34
  store i8 %37, ptr %30, align 2, !tbaa !9
  %38 = load i8, ptr %33, align 1, !tbaa !9
  store i8 %38, ptr %35, align 1, !tbaa !9
  %.not22 = icmp eq i64 %5, 0
  br i1 %.not22, label %40, label %39

39:                                               ; preds = %9
  call void @comet_process_ad(ptr noundef nonnull %10, ptr noundef nonnull %11, i32 noundef 8, ptr noundef nonnull @cham64_128_encrypt, ptr noundef %4, i64 noundef %5)
  br label %40

40:                                               ; preds = %39, %9
  %.not23 = icmp eq i64 %3, 0
  br i1 %.not23, label %42, label %41

41:                                               ; preds = %40
  call void @comet_encrypt_64(ptr noundef nonnull %10, ptr noundef nonnull %11, ptr noundef nonnull @cham64_128_encrypt, ptr noundef %0, ptr noundef %2, i64 noundef %3)
  br label %42

42:                                               ; preds = %41, %40
  %43 = getelementptr inbounds i8, ptr %11, i64 15
  %44 = load i8, ptr %43, align 1, !tbaa !9
  %45 = xor i8 %44, -128
  store i8 %45, ptr %43, align 1, !tbaa !9
  call void @comet_adjust_block_key(ptr noundef nonnull %11)
  %46 = getelementptr inbounds i8, ptr %0, i64 %3
  call void @cham64_128_encrypt(ptr noundef nonnull %11, ptr noundef %46, ptr noundef nonnull %10) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %11) #4
  call void @llvm.lifetime.end.p0(i64 8, 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 @comet_process_ad(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #0

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

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

declare void @cham64_128_encrypt(ptr noundef, ptr noundef, ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @comet_encrypt_64(ptr noundef, 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: 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: DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass