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

; 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 @orange_zest_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 [32 x i8], align 16
  %21 = 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 32, ptr %20) #4
  %22 = load ptr, ptr %13, align 8, !tbaa !5
  %23 = load i64, ptr %15, align 8, !tbaa !9
  %24 = icmp ult i64 %23, 16
  br i1 %24, label %25, label %26

25:                                               ; preds = %9
  store i32 -1, ptr %10, align 4
  store i32 1, ptr %21, align 4
  br label %87

26:                                               ; preds = %9
  %27 = load i64, ptr %15, align 8, !tbaa !9
  %28 = sub i64 %27, 16
  %29 = load ptr, ptr %12, align 8, !tbaa !5
  store i64 %28, ptr %29, align 8, !tbaa !9
  %30 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 0
  %31 = load ptr, ptr %18, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %30, ptr align 1 %31, i64 16, i1 false)
  %32 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 0
  %33 = getelementptr inbounds i8, ptr %32, i64 16
  %34 = load ptr, ptr %19, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %33, ptr align 1 %34, i64 16, i1 false)
  %35 = load i64, ptr %15, align 8, !tbaa !9
  %36 = sub i64 %35, 16
  store i64 %36, ptr %15, align 8, !tbaa !9
  %37 = load i64, ptr %17, align 8, !tbaa !9
  %38 = icmp eq i64 %37, 0
  br i1 %38, label %39, label %65

39:                                               ; preds = %26
  %40 = load i64, ptr %15, align 8, !tbaa !9
  %41 = icmp eq i64 %40, 0
  br i1 %41, label %42, label %53

42:                                               ; preds = %39
  %43 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 16
  %44 = load i8, ptr %43, align 16, !tbaa !11
  %45 = zext i8 %44 to i32
  %46 = xor i32 %45, 2
  %47 = trunc i32 %46 to i8
  store i8 %47, ptr %43, align 16, !tbaa !11
  %48 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 0
  call void @photon256_permute(ptr noundef %48)
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  %50 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 0
  %51 = load ptr, ptr %14, align 8, !tbaa !5
  %52 = call i32 @aead_check_tag(ptr noundef %49, i64 noundef 0, ptr noundef %50, ptr noundef %51, i32 noundef 16)
  store i32 %52, ptr %10, align 4
  store i32 1, ptr %21, align 4
  br label %87

53:                                               ; preds = %39
  %54 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 16
  %55 = load i8, ptr %54, align 16, !tbaa !11
  %56 = zext i8 %55 to i32
  %57 = xor i32 %56, 1
  %58 = trunc i32 %57 to i8
  store i8 %58, ptr %54, align 16, !tbaa !11
  %59 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 0
  %60 = load ptr, ptr %19, align 8, !tbaa !5
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  %62 = load ptr, ptr %14, align 8, !tbaa !5
  %63 = load i64, ptr %15, align 8, !tbaa !9
  call void @orange_decrypt(ptr noundef %59, ptr noundef %60, ptr noundef %61, ptr noundef %62, i64 noundef %63)
  br label %64

64:                                               ; preds = %53
  br label %78

65:                                               ; preds = %26
  %66 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 0
  %67 = load ptr, ptr %16, align 8, !tbaa !5
  %68 = load i64, ptr %17, align 8, !tbaa !9
  call void @orange_process_hash(ptr noundef %66, ptr noundef %67, i64 noundef %68, i8 noundef zeroext 1, i8 noundef zeroext 2)
  %69 = load i64, ptr %15, align 8, !tbaa !9
  %70 = icmp ne i64 %69, 0
  br i1 %70, label %71, label %77

71:                                               ; preds = %65
  %72 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 0
  %73 = load ptr, ptr %19, align 8, !tbaa !5
  %74 = load ptr, ptr %11, align 8, !tbaa !5
  %75 = load ptr, ptr %14, align 8, !tbaa !5
  %76 = load i64, ptr %15, align 8, !tbaa !9
  call void @orange_decrypt(ptr noundef %72, ptr noundef %73, ptr noundef %74, ptr noundef %75, i64 noundef %76)
  br label %77

77:                                               ; preds = %71, %65
  br label %78

78:                                               ; preds = %77, %64
  %79 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 0
  call void @orange_generate_tag(ptr noundef %79)
  %80 = load ptr, ptr %11, align 8, !tbaa !5
  %81 = load i64, ptr %15, align 8, !tbaa !9
  %82 = getelementptr inbounds [32 x i8], ptr %20, i64 0, i64 0
  %83 = load ptr, ptr %14, align 8, !tbaa !5
  %84 = load i64, ptr %15, align 8, !tbaa !9
  %85 = getelementptr inbounds i8, ptr %83, i64 %84
  %86 = call i32 @aead_check_tag(ptr noundef %80, i64 noundef %81, ptr noundef %82, ptr noundef %85, i32 noundef 16)
  store i32 %86, ptr %10, align 4
  store i32 1, ptr %21, align 4
  br label %87

87:                                               ; preds = %78, %42, %25
  call void @llvm.lifetime.end.p0(i64 32, ptr %20) #4
  %88 = load i32, ptr %10, align 4
  ret i32 %88
}

; 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

declare void @photon256_permute(ptr noundef) #3

; Function Attrs: nounwind uwtable
declare hidden void @orange_process_hash(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext, i8 noundef zeroext) #0

; Function Attrs: nounwind uwtable
declare hidden void @orange_generate_tag(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: nounwind uwtable
declare hidden void @orange_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: 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 i32 @orange_zest_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 nocapture noundef readonly %7, ptr noundef %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 = icmp ult i64 %4, 16
  br i1 %11, label %28, label %12

12:                                               ; preds = %9
  %13 = add i64 %4, -16
  store i64 %13, 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)
  %14 = getelementptr inbounds i8, ptr %10, i64 16
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %14, ptr noundef nonnull align 1 dereferenceable(16) %8, i64 16, i1 false)
  %15 = icmp eq i64 %6, 0
  br i1 %15, label %16, label %24

16:                                               ; preds = %12
  %17 = icmp eq i64 %13, 0
  %18 = load i8, ptr %14, align 16, !tbaa !9
  br i1 %17, label %19, label %22

19:                                               ; preds = %16
  %20 = xor i8 %18, 2
  store i8 %20, ptr %14, align 16, !tbaa !9
  call void @photon256_permute(ptr noundef nonnull %10) #4
  %21 = call i32 @aead_check_tag(ptr noundef %0, i64 noundef 0, ptr noundef nonnull %10, ptr noundef %3, i32 noundef 16) #4
  br label %28

22:                                               ; preds = %16
  %23 = xor i8 %18, 1
  store i8 %23, ptr %14, align 16, !tbaa !9
  br label %.sink.split

24:                                               ; preds = %12
  call void @orange_process_hash(ptr noundef nonnull %10, ptr noundef %5, i64 noundef %6, i8 noundef zeroext 1, i8 noundef zeroext 2)
  %.not = icmp eq i64 %13, 0
  br i1 %.not, label %25, label %.sink.split

.sink.split:                                      ; preds = %24, %22
  call void @orange_decrypt(ptr noundef nonnull %10, ptr noundef nonnull %8, ptr noundef %0, ptr noundef %3, i64 noundef %13)
  br label %25

25:                                               ; preds = %.sink.split, %24
  call void @orange_generate_tag(ptr noundef nonnull %10)
  %26 = getelementptr inbounds i8, ptr %3, i64 %13
  %27 = call i32 @aead_check_tag(ptr noundef %0, i64 noundef %13, ptr noundef nonnull %10, ptr noundef %26, i32 noundef 16) #4
  br label %28

28:                                               ; preds = %9, %25, %19
  %.0 = phi i32 [ %21, %19 ], [ %27, %25 ], [ -1, %9 ]
  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

declare void @photon256_permute(ptr noundef) local_unnamed_addr #3

; Function Attrs: nounwind uwtable
declare hidden void @orange_process_hash(ptr noundef, ptr noundef, i64 noundef, i8 noundef zeroext, i8 noundef zeroext) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
declare hidden void @orange_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: 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: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass