; LLVM IR from IanHarvey/minicrypt :: src (aesccm_mini)

; 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.AESCCMMini_ctx = type { %struct.AESMini_ctx, i32, i32 }
%struct.AESMini_ctx = type { %struct.AESMini_keys, %struct.AESMini_keys }
%struct.AESMini_keys = type { i32, [60 x i32] }

; Function Attrs: nounwind uwtable
declare dso_local i32 @AESCCMMini_EncryptLength(ptr noundef, i64 noundef, ptr noundef) #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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @AESCCMMini_Encrypt(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i64, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store i64 %2, ptr %9, align 8, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i64 %4, ptr %11, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  %14 = load ptr, ptr %7, align 8, !tbaa !5
  %15 = load i64, ptr %9, align 8, !tbaa !9
  %16 = call i32 @AESCCMMini_EncryptLength(ptr noundef %14, i64 noundef %15, ptr noundef %12)
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %22, label %18

18:                                               ; preds = %5
  %19 = load i64, ptr %12, align 8, !tbaa !9
  %20 = load i64, ptr %11, align 8, !tbaa !9
  %21 = icmp ne i64 %19, %20
  br i1 %21, label %22, label %23

22:                                               ; preds = %18, %5
  store i32 2, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %48

23:                                               ; preds = %18
  %24 = load ptr, ptr %7, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.AESCCMMini_ctx, ptr %24, i32 0, i32 1
  %26 = load i32, ptr %25, align 4, !tbaa !11
  %27 = sub i32 15, %26
  %28 = zext i32 %27 to i64
  store i64 %28, ptr %12, align 8, !tbaa !9
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = load i64, ptr %12, align 8, !tbaa !9
  %31 = call i32 @MC_GetRandom(ptr noundef %29, i64 noundef %30)
  %32 = icmp ne i32 %31, 0
  br i1 %32, label %33, label %34

33:                                               ; preds = %23
  store i32 5, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %48

34:                                               ; preds = %23
  %35 = load ptr, ptr %7, align 8, !tbaa !5
  %36 = load ptr, ptr %10, align 8, !tbaa !5
  %37 = load ptr, ptr %8, align 8, !tbaa !5
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = load i64, ptr %12, align 8, !tbaa !9
  %40 = getelementptr inbounds i8, ptr %38, i64 %39
  %41 = load i64, ptr %9, align 8, !tbaa !9
  %42 = load ptr, ptr %10, align 8, !tbaa !5
  %43 = load i64, ptr %12, align 8, !tbaa !9
  %44 = getelementptr inbounds i8, ptr %42, i64 %43
  %45 = load i64, ptr %9, align 8, !tbaa !9
  %46 = getelementptr inbounds i8, ptr %44, i64 %45
  %47 = call i32 @AESCCM_common(ptr noundef %35, ptr noundef %36, ptr noundef %37, ptr noundef %40, i64 noundef %41, ptr noundef %46, i32 noundef 0)
  store i32 %47, ptr %6, align 4
  store i32 1, ptr %13, align 4
  br label %48

48:                                               ; preds = %34, %33, %22
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %49 = load i32, ptr %6, align 4
  ret i32 %49
}

declare i32 @MC_GetRandom(ptr noundef, i64 noundef) #2

; Function Attrs: nounwind uwtable
declare hidden i32 @AESCCM_common(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, i32 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 = { "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 #3 = { 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", !7, i64 0}
!11 = !{!12, !15, i64 488}
!12 = !{!"", !13, i64 0, !15, i64 488, !15, i64 492}
!13 = !{!"", !14, i64 0, !14, i64 244}
!14 = !{!"", !15, i64 0, !7, i64 4}
!15 = !{!"int", !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
declare dso_local i32 @AESCCMMini_EncryptLength(ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #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 nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @AESCCMMini_Encrypt(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i64 noundef %4) local_unnamed_addr #0 {
  %6 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %7 = call i32 @AESCCMMini_EncryptLength(ptr noundef %0, i64 noundef %2, ptr noundef nonnull %6)
  %.not = icmp eq i32 %7, 0
  %8 = load i64, ptr %6, align 8
  %.not12 = icmp eq i64 %8, %4
  %or.cond = select i1 %.not, i1 %.not12, i1 false
  br i1 %or.cond, label %9, label %20

9:                                                ; preds = %5
  %10 = getelementptr inbounds i8, ptr %0, i64 488
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = sub i32 15, %11
  %13 = zext i32 %12 to i64
  store i64 %13, ptr %6, align 8, !tbaa !12
  %14 = call i32 @MC_GetRandom(ptr noundef %3, i64 noundef %13) #3
  %.not13 = icmp eq i32 %14, 0
  br i1 %.not13, label %15, label %20

15:                                               ; preds = %9
  %16 = load i64, ptr %6, align 8, !tbaa !12
  %17 = getelementptr inbounds i8, ptr %3, i64 %16
  %18 = getelementptr inbounds i8, ptr %17, i64 %2
  %19 = call i32 @AESCCM_common(ptr noundef nonnull %0, ptr noundef %3, ptr noundef %1, ptr noundef %17, i64 noundef %2, ptr noundef %18, i32 noundef 0)
  br label %20

20:                                               ; preds = %9, %5, %15
  %.0 = phi i32 [ %19, %15 ], [ 2, %5 ], [ 5, %9 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret i32 %.0
}

declare i32 @MC_GetRandom(ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden i32 @AESCCM_common(ptr noundef, ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef, i32 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 = { "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 #3 = { 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, !9, i64 488}
!6 = !{!"", !7, i64 0, !9, i64 488, !9, i64 492}
!7 = !{!"", !8, i64 0, !8, i64 244}
!8 = !{!"", !9, i64 0, !10, i64 4}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !11, i64 0}
!11 = !{!"Simple C/C++ TBAA"}
!12 = !{!13, !13, i64 0}
!13 = !{!"long", !10, i64 0}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,SROAPass,SimplifyCFGPass