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

; 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.saturnin_key_schedule_t = type { [16 x i32] }

; Function Attrs: nounwind uwtable
define dso_local i32 @saturnin_short_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 i32, align 4
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca ptr, align 8
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca %struct.saturnin_key_schedule_t, align 4
  %21 = alloca [32 x i8], align 16
  %22 = alloca i32, align 4
  %23 = 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 i64 %3, ptr %14, align 8, !tbaa !9
  store ptr %4, ptr %15, align 8, !tbaa !5
  store i64 %5, ptr %16, align 8, !tbaa !9
  store ptr %6, ptr %17, align 8, !tbaa !5
  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 64, ptr %20) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr %21) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #5
  %24 = load ptr, ptr %17, align 8, !tbaa !5
  %25 = load ptr, ptr %15, align 8, !tbaa !5
  %26 = load i64, ptr %16, align 8, !tbaa !9
  %27 = icmp ugt i64 %26, 0
  br i1 %27, label %31, label %28

28:                                               ; preds = %9
  %29 = load i64, ptr %14, align 8, !tbaa !9
  %30 = icmp ugt i64 %29, 15
  br i1 %30, label %31, label %32

31:                                               ; preds = %28, %9
  store i32 -2, ptr %10, align 4
  store i32 1, ptr %23, align 4
  br label %58

32:                                               ; preds = %28
  %33 = load i64, ptr %14, align 8, !tbaa !9
  %34 = trunc i64 %33 to i32
  store i32 %34, ptr %22, align 4, !tbaa !11
  %35 = getelementptr inbounds [32 x i8], ptr %21, i64 0, i64 0
  %36 = load ptr, ptr %18, align 8, !tbaa !5
  call void @llvm.memcpy.p0.p0.i64(ptr align 16 %35, ptr align 1 %36, i64 16, i1 false)
  %37 = getelementptr inbounds [32 x i8], ptr %21, i64 0, i64 0
  %38 = getelementptr inbounds i8, ptr %37, i64 16
  %39 = load ptr, ptr %13, align 8, !tbaa !5
  %40 = load i32, ptr %22, align 4, !tbaa !11
  %41 = zext i32 %40 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %38, ptr align 1 %39, i64 %41, i1 false)
  %42 = load i32, ptr %22, align 4, !tbaa !11
  %43 = add i32 16, %42
  %44 = zext i32 %43 to i64
  %45 = getelementptr inbounds [32 x i8], ptr %21, i64 0, i64 %44
  store i8 -128, ptr %45, align 1, !tbaa !13
  %46 = getelementptr inbounds [32 x i8], ptr %21, i64 0, i64 0
  %47 = getelementptr inbounds i8, ptr %46, i64 17
  %48 = load i32, ptr %22, align 4, !tbaa !11
  %49 = zext i32 %48 to i64
  %50 = getelementptr inbounds i8, ptr %47, i64 %49
  %51 = load i32, ptr %22, align 4, !tbaa !11
  %52 = sub i32 15, %51
  %53 = zext i32 %52 to i64
  call void @llvm.memset.p0.i64(ptr align 1 %50, i8 0, i64 %53, i1 false)
  %54 = load ptr, ptr %19, align 8, !tbaa !5
  call void @saturnin_setup_key(ptr noundef %20, ptr noundef %54)
  %55 = load ptr, ptr %11, align 8, !tbaa !5
  %56 = getelementptr inbounds [32 x i8], ptr %21, i64 0, i64 0
  call void @saturnin_encrypt_block(ptr noundef %20, ptr noundef %55, ptr noundef %56, i32 noundef 50)
  %57 = load ptr, ptr %12, align 8, !tbaa !5
  store i64 32, ptr %57, align 8, !tbaa !9
  store i32 0, ptr %10, align 4
  store i32 1, ptr %23, align 4
  br label %58

58:                                               ; preds = %32, %31
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #5
  call void @llvm.lifetime.end.p0(i64 32, ptr %21) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr %20) #5
  %59 = load i32, ptr %10, align 4
  ret i32 %59
}

; 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: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

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

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

declare void @saturnin_encrypt_block(ptr noundef, ptr noundef, ptr noundef, i32 noundef) #4

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 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!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"

%struct.saturnin_key_schedule_t = type { [16 x i32] }

; Function Attrs: nounwind uwtable
define dso_local range(i32 -2, 1) i32 @saturnin_short_aead_encrypt(ptr noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef readonly %2, i64 noundef %3, ptr nocapture noundef readnone %4, i64 noundef %5, ptr nocapture noundef readnone %6, ptr nocapture noundef readonly %7, ptr noundef %8) local_unnamed_addr #0 {
  %10 = alloca %struct.saturnin_key_schedule_t, align 4
  %11 = alloca [32 x i8], align 16
  call void @llvm.lifetime.start.p0(i64 64, ptr nonnull %10) #5
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %11) #5
  %12 = icmp ne i64 %5, 0
  %13 = icmp ugt i64 %3, 15
  %or.cond = or i1 %13, %12
  br i1 %or.cond, label %21, label %14

14:                                               ; preds = %9
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(16) %11, ptr noundef nonnull align 1 dereferenceable(16) %7, i64 16, i1 false)
  %15 = getelementptr inbounds i8, ptr %11, i64 16
  call void @llvm.memcpy.p0.p0.i64(ptr nonnull align 16 %15, ptr align 1 %2, i64 %3, i1 false)
  %16 = or disjoint i64 %3, 16
  %17 = getelementptr inbounds [32 x i8], ptr %11, i64 0, i64 %16
  store i8 -128, ptr %17, align 1, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %11, i64 17
  %19 = getelementptr inbounds i8, ptr %18, i64 %3
  %20 = sub nuw nsw i64 15, %3
  call void @llvm.memset.p0.i64(ptr nonnull align 1 %19, i8 0, i64 %20, i1 false)
  call void @saturnin_setup_key(ptr noundef nonnull %10, ptr noundef %8) #5
  call void @saturnin_encrypt_block(ptr noundef nonnull %10, ptr noundef %0, ptr noundef nonnull %11, i32 noundef 50) #5
  store i64 32, ptr %1, align 8, !tbaa !8
  br label %21

21:                                               ; preds = %9, %14
  %.0 = phi i32 [ 0, %14 ], [ -2, %9 ]
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %11) #5
  call void @llvm.lifetime.end.p0(i64 64, ptr nonnull %10) #5
  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: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #3

declare void @saturnin_setup_key(ptr noundef, ptr noundef) local_unnamed_addr #4

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

declare void @saturnin_encrypt_block(ptr noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #4

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 = { mustprogress 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !6, i64 0}


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