; 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_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 [8 x i8], align 1
  %21 = alloca [16 x i8], align 16
  %22 = alloca i32, align 4
  %23 = alloca ptr, align 8
  %24 = alloca ptr, align 8
  %25 = 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 8, ptr %20) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr %21) #5
  %26 = load ptr, ptr %13, align 8, !tbaa !5
  %27 = load i64, ptr %15, align 8, !tbaa !9
  %28 = icmp ult i64 %27, 8
  br i1 %28, label %29, label %30

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

30:                                               ; preds = %9
  %31 = load i64, ptr %15, align 8, !tbaa !9
  %32 = sub i64 %31, 8
  %33 = load ptr, ptr %12, align 8, !tbaa !5
  store i64 %32, ptr %33, align 8, !tbaa !9
  %34 = getelementptr inbounds [8 x i8], ptr %20, i64 0, i64 0
  call void @llvm.memset.p0.i64(ptr align 1 %34, i8 0, i64 8, i1 false)
  %35 = load ptr, ptr %19, align 8, !tbaa !5
  %36 = getelementptr inbounds [8 x i8], ptr %20, i64 0, i64 0
  %37 = getelementptr inbounds [8 x i8], ptr %20, i64 0, i64 0
  call void @cham64_128_encrypt(ptr noundef %35, ptr noundef %36, ptr noundef %37)
  %38 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  %39 = load ptr, ptr %18, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %38, ptr align 1 %39, i64 15, i1 false)
  %40 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 15
  store i8 0, ptr %40, align 1, !tbaa !11
  br label %41

41:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #5
  %42 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  store ptr %42, ptr %23, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #5
  %43 = load ptr, ptr %19, align 8, !tbaa !5
  store ptr %43, ptr %24, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #5
  store i32 16, ptr %25, align 4, !tbaa !12
  br label %44

44:                                               ; preds = %47, %41
  %45 = load i32, ptr %25, align 4, !tbaa !12
  %46 = icmp ugt i32 %45, 0
  br i1 %46, label %47, label %60

47:                                               ; preds = %44
  %48 = load ptr, ptr %24, align 8, !tbaa !5
  %49 = getelementptr inbounds i8, ptr %48, i32 1
  store ptr %49, ptr %24, align 8, !tbaa !5
  %50 = load i8, ptr %48, align 1, !tbaa !11
  %51 = zext i8 %50 to i32
  %52 = load ptr, ptr %23, align 8, !tbaa !5
  %53 = getelementptr inbounds i8, ptr %52, i32 1
  store ptr %53, ptr %23, align 8, !tbaa !5
  %54 = load i8, ptr %52, align 1, !tbaa !11
  %55 = zext i8 %54 to i32
  %56 = xor i32 %55, %51
  %57 = trunc i32 %56 to i8
  store i8 %57, ptr %52, align 1, !tbaa !11
  %58 = load i32, ptr %25, align 4, !tbaa !12
  %59 = add i32 %58, -1
  store i32 %59, ptr %25, align 4, !tbaa !12
  br label %44, !llvm.loop !14

60:                                               ; preds = %44
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #5
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  %63 = load i64, ptr %17, align 8, !tbaa !9
  %64 = icmp ugt i64 %63, 0
  br i1 %64, label %65, label %70

65:                                               ; preds = %62
  %66 = getelementptr inbounds [8 x i8], ptr %20, i64 0, i64 0
  %67 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  %68 = load ptr, ptr %16, align 8, !tbaa !5
  %69 = load i64, ptr %17, align 8, !tbaa !9
  call void @comet_process_ad(ptr noundef %66, ptr noundef %67, i32 noundef 8, ptr noundef @cham64_128_encrypt, ptr noundef %68, i64 noundef %69)
  br label %70

70:                                               ; preds = %65, %62
  %71 = load i64, ptr %15, align 8, !tbaa !9
  %72 = icmp ugt i64 %71, 8
  br i1 %72, label %73, label %80

73:                                               ; preds = %70
  %74 = getelementptr inbounds [8 x i8], ptr %20, i64 0, i64 0
  %75 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  %76 = load ptr, ptr %11, align 8, !tbaa !5
  %77 = load ptr, ptr %14, align 8, !tbaa !5
  %78 = load ptr, ptr %12, align 8, !tbaa !5
  %79 = load i64, ptr %78, align 8, !tbaa !9
  call void @comet_decrypt_64(ptr noundef %74, ptr noundef %75, ptr noundef @cham64_128_encrypt, ptr noundef %76, ptr noundef %77, i64 noundef %79)
  br label %80

80:                                               ; preds = %73, %70
  %81 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 15
  %82 = load i8, ptr %81, align 1, !tbaa !11
  %83 = zext i8 %82 to i32
  %84 = xor i32 %83, 128
  %85 = trunc i32 %84 to i8
  store i8 %85, ptr %81, align 1, !tbaa !11
  %86 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  call void @comet_adjust_block_key(ptr noundef %86)
  %87 = getelementptr inbounds [16 x i8], ptr %21, i64 0, i64 0
  %88 = getelementptr inbounds [8 x i8], ptr %20, i64 0, i64 0
  %89 = getelementptr inbounds [8 x i8], ptr %20, i64 0, i64 0
  call void @cham64_128_encrypt(ptr noundef %87, ptr noundef %88, ptr noundef %89)
  %90 = load ptr, ptr %11, align 8, !tbaa !5
  %91 = load ptr, ptr %12, align 8, !tbaa !5
  %92 = load i64, ptr %91, align 8, !tbaa !9
  %93 = getelementptr inbounds [8 x i8], ptr %20, i64 0, i64 0
  %94 = load ptr, ptr %14, align 8, !tbaa !5
  %95 = load ptr, ptr %12, align 8, !tbaa !5
  %96 = load i64, ptr %95, align 8, !tbaa !9
  %97 = getelementptr inbounds i8, ptr %94, i64 %96
  %98 = call i32 @aead_check_tag(ptr noundef %90, i64 noundef %92, ptr noundef %93, ptr noundef %97, i32 noundef 8)
  store i32 %98, ptr %10, align 4
  store i32 1, ptr %22, align 4
  br label %99

99:                                               ; preds = %80, %29
  call void @llvm.lifetime.end.p0(i64 16, ptr %21) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #5
  %100 = load i32, ptr %10, align 4
  ret i32 %100
}

; 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

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

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

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

; Function Attrs: nounwind uwtable
declare hidden void @comet_decrypt_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 = { "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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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 i32 @comet_64_cham_aead_decrypt(ptr noundef %0, ptr nocapture noundef %1, ptr nocapture noundef readnone %2, ptr noundef %3, i64 noundef %4, ptr noundef %5, i64 noundef %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 = icmp ult i64 %4, 8
  br i1 %12, label %52, label %13

13:                                               ; preds = %9
  %14 = add i64 %4, -8
  store i64 %14, 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)
  %15 = getelementptr inbounds i8, ptr %11, i64 15
  %16 = getelementptr inbounds i8, ptr %8, i64 8
  %17 = getelementptr inbounds i8, ptr %11, i64 8
  %18 = load <8 x i8>, ptr %8, align 1, !tbaa !9
  %19 = load <8 x i8>, ptr %11, align 16, !tbaa !9
  %20 = xor <8 x i8> %19, %18
  store <8 x i8> %20, ptr %11, align 16, !tbaa !9
  %21 = getelementptr inbounds i8, ptr %8, i64 12
  %22 = getelementptr inbounds i8, ptr %11, i64 12
  %23 = load <4 x i8>, ptr %16, align 1, !tbaa !9
  %24 = load <4 x i8>, ptr %17, align 8, !tbaa !9
  %25 = xor <4 x i8> %24, %23
  store <4 x i8> %25, ptr %17, align 8, !tbaa !9
  %26 = getelementptr inbounds i8, ptr %8, i64 13
  %27 = load i8, ptr %21, align 1, !tbaa !9
  %28 = getelementptr inbounds i8, ptr %11, i64 13
  %29 = load i8, ptr %22, align 4, !tbaa !9
  %30 = xor i8 %29, %27
  store i8 %30, ptr %22, align 4, !tbaa !9
  %31 = getelementptr inbounds i8, ptr %8, i64 14
  %32 = load i8, ptr %26, align 1, !tbaa !9
  %33 = getelementptr inbounds i8, ptr %11, i64 14
  %34 = load i8, ptr %28, align 1, !tbaa !9
  %35 = xor i8 %34, %32
  store i8 %35, ptr %28, align 1, !tbaa !9
  %36 = getelementptr inbounds i8, ptr %8, i64 15
  %37 = load i8, ptr %31, align 1, !tbaa !9
  %38 = getelementptr inbounds i8, ptr %11, i64 15
  %39 = load i8, ptr %33, align 2, !tbaa !9
  %40 = xor i8 %39, %37
  store i8 %40, ptr %33, align 2, !tbaa !9
  %41 = load i8, ptr %36, align 1, !tbaa !9
  store i8 %41, ptr %38, align 1, !tbaa !9
  %.not27 = icmp eq i64 %6, 0
  br i1 %.not27, label %43, label %42

42:                                               ; preds = %13
  call void @comet_process_ad(ptr noundef nonnull %10, ptr noundef nonnull %11, i32 noundef 8, ptr noundef nonnull @cham64_128_encrypt, ptr noundef %5, i64 noundef %6)
  br label %43

43:                                               ; preds = %42, %13
  %.not28 = icmp eq i64 %4, 8
  br i1 %.not28, label %46, label %44

44:                                               ; preds = %43
  %45 = load i64, ptr %1, align 8, !tbaa !5
  call void @comet_decrypt_64(ptr noundef nonnull %10, ptr noundef nonnull %11, ptr noundef nonnull @cham64_128_encrypt, ptr noundef %0, ptr noundef %3, i64 noundef %45)
  br label %46

46:                                               ; preds = %44, %43
  %47 = load i8, ptr %15, align 1, !tbaa !9
  %48 = xor i8 %47, -128
  store i8 %48, ptr %15, align 1, !tbaa !9
  call void @comet_adjust_block_key(ptr noundef nonnull %11)
  call void @cham64_128_encrypt(ptr noundef nonnull %11, ptr noundef nonnull %10, ptr noundef nonnull %10) #4
  %49 = load i64, ptr %1, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %3, i64 %49
  %51 = call i32 @aead_check_tag(ptr noundef %0, i64 noundef %49, ptr noundef nonnull %10, ptr noundef %50, i32 noundef 8) #4
  br label %52

52:                                               ; preds = %9, %46
  %.024 = phi i32 [ %51, %46 ], [ -1, %9 ]
  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 %.024
}

; 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 i32 @aead_check_tag(ptr noundef, i64 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
declare hidden void @comet_decrypt_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