; LLVM IR from openssl/openssl :: crypto/modes (ccm128)

; 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.ccm128_context = type { %union.anon, %union.anon, i64, ptr, ptr }
%union.anon = type { [2 x i64] }

; Function Attrs: nounwind uwtable
define dso_local i32 @CRYPTO_ccm128_setiv(ptr noundef %0, ptr noundef %1, i64 noundef %2, i64 noundef %3) #0 {
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  store ptr %0, ptr %6, align 8, !tbaa !5
  store ptr %1, ptr %7, align 8, !tbaa !5
  store i64 %2, ptr %8, align 8, !tbaa !9
  store i64 %3, ptr %9, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %12 = load ptr, ptr %6, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.ccm128_context, ptr %12, i32 0, i32 0
  %14 = getelementptr inbounds [16 x i8], ptr %13, i64 0, i64 0
  %15 = load i8, ptr %14, align 8, !tbaa !11
  %16 = zext i8 %15 to i32
  %17 = and i32 %16, 7
  store i32 %17, ptr %10, align 4, !tbaa !12
  %18 = load i64, ptr %8, align 8, !tbaa !9
  %19 = load i32, ptr %10, align 4, !tbaa !12
  %20 = sub i32 14, %19
  %21 = zext i32 %20 to i64
  %22 = icmp ult i64 %18, %21
  br i1 %22, label %23, label %24

23:                                               ; preds = %4
  store i32 -1, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %94

24:                                               ; preds = %4
  %25 = load i32, ptr %10, align 4, !tbaa !12
  %26 = icmp uge i32 %25, 3
  br i1 %26, label %27, label %52

27:                                               ; preds = %24
  %28 = load i64, ptr %9, align 8, !tbaa !9
  %29 = lshr i64 %28, 56
  %30 = trunc i64 %29 to i8
  %31 = load ptr, ptr %6, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.ccm128_context, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds [16 x i8], ptr %32, i64 0, i64 8
  store i8 %30, ptr %33, align 8, !tbaa !11
  %34 = load i64, ptr %9, align 8, !tbaa !9
  %35 = lshr i64 %34, 48
  %36 = trunc i64 %35 to i8
  %37 = load ptr, ptr %6, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.ccm128_context, ptr %37, i32 0, i32 0
  %39 = getelementptr inbounds [16 x i8], ptr %38, i64 0, i64 9
  store i8 %36, ptr %39, align 1, !tbaa !11
  %40 = load i64, ptr %9, align 8, !tbaa !9
  %41 = lshr i64 %40, 40
  %42 = trunc i64 %41 to i8
  %43 = load ptr, ptr %6, align 8, !tbaa !5
  %44 = getelementptr inbounds %struct.ccm128_context, ptr %43, i32 0, i32 0
  %45 = getelementptr inbounds [16 x i8], ptr %44, i64 0, i64 10
  store i8 %42, ptr %45, align 2, !tbaa !11
  %46 = load i64, ptr %9, align 8, !tbaa !9
  %47 = lshr i64 %46, 32
  %48 = trunc i64 %47 to i8
  %49 = load ptr, ptr %6, align 8, !tbaa !5
  %50 = getelementptr inbounds %struct.ccm128_context, ptr %49, i32 0, i32 0
  %51 = getelementptr inbounds [16 x i8], ptr %50, i64 0, i64 11
  store i8 %48, ptr %51, align 1, !tbaa !11
  br label %56

52:                                               ; preds = %24
  %53 = load ptr, ptr %6, align 8, !tbaa !5
  %54 = getelementptr inbounds %struct.ccm128_context, ptr %53, i32 0, i32 0
  %55 = getelementptr inbounds [2 x i64], ptr %54, i64 0, i64 1
  store i64 0, ptr %55, align 8, !tbaa !11
  br label %56

56:                                               ; preds = %52, %27
  %57 = load i64, ptr %9, align 8, !tbaa !9
  %58 = lshr i64 %57, 24
  %59 = trunc i64 %58 to i8
  %60 = load ptr, ptr %6, align 8, !tbaa !5
  %61 = getelementptr inbounds %struct.ccm128_context, ptr %60, i32 0, i32 0
  %62 = getelementptr inbounds [16 x i8], ptr %61, i64 0, i64 12
  store i8 %59, ptr %62, align 4, !tbaa !11
  %63 = load i64, ptr %9, align 8, !tbaa !9
  %64 = lshr i64 %63, 16
  %65 = trunc i64 %64 to i8
  %66 = load ptr, ptr %6, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.ccm128_context, ptr %66, i32 0, i32 0
  %68 = getelementptr inbounds [16 x i8], ptr %67, i64 0, i64 13
  store i8 %65, ptr %68, align 1, !tbaa !11
  %69 = load i64, ptr %9, align 8, !tbaa !9
  %70 = lshr i64 %69, 8
  %71 = trunc i64 %70 to i8
  %72 = load ptr, ptr %6, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.ccm128_context, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds [16 x i8], ptr %73, i64 0, i64 14
  store i8 %71, ptr %74, align 2, !tbaa !11
  %75 = load i64, ptr %9, align 8, !tbaa !9
  %76 = trunc i64 %75 to i8
  %77 = load ptr, ptr %6, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.ccm128_context, ptr %77, i32 0, i32 0
  %79 = getelementptr inbounds [16 x i8], ptr %78, i64 0, i64 15
  store i8 %76, ptr %79, align 1, !tbaa !11
  %80 = load ptr, ptr %6, align 8, !tbaa !5
  %81 = getelementptr inbounds %struct.ccm128_context, ptr %80, i32 0, i32 0
  %82 = getelementptr inbounds [16 x i8], ptr %81, i64 0, i64 0
  %83 = load i8, ptr %82, align 8, !tbaa !11
  %84 = zext i8 %83 to i32
  %85 = and i32 %84, -65
  %86 = trunc i32 %85 to i8
  store i8 %86, ptr %82, align 8, !tbaa !11
  %87 = load ptr, ptr %6, align 8, !tbaa !5
  %88 = getelementptr inbounds %struct.ccm128_context, ptr %87, i32 0, i32 0
  %89 = getelementptr inbounds [16 x i8], ptr %88, i64 0, i64 1
  %90 = load ptr, ptr %7, align 8, !tbaa !5
  %91 = load i32, ptr %10, align 4, !tbaa !12
  %92 = sub i32 14, %91
  %93 = zext i32 %92 to i64
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %89, ptr align 1 %90, i64 %93, i1 false)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %11, align 4
  br label %94

94:                                               ; preds = %56, %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  %95 = load i32, ptr %5, align 4
  ret i32 %95
}

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

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 = { 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 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"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: mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) uwtable
define dso_local range(i32 -1, 1) i32 @CRYPTO_ccm128_setiv(ptr nocapture noundef %0, ptr nocapture noundef readonly %1, i64 noundef %2, i64 noundef %3) local_unnamed_addr #0 {
  %5 = load i8, ptr %0, align 8, !tbaa !5
  %6 = and i8 %5, 7
  %narrow = sub nuw nsw i8 14, %6
  %7 = zext nneg i8 %narrow to i64
  %8 = icmp ugt i64 %7, %2
  br i1 %8, label %40, label %9

9:                                                ; preds = %4
  %10 = icmp ugt i8 %6, 2
  br i1 %10, label %11, label %24

11:                                               ; preds = %9
  %12 = lshr i64 %3, 56
  %13 = trunc nuw i64 %12 to i8
  %14 = getelementptr inbounds i8, ptr %0, i64 8
  store i8 %13, ptr %14, align 8, !tbaa !5
  %15 = lshr i64 %3, 48
  %16 = trunc i64 %15 to i8
  %17 = getelementptr inbounds i8, ptr %0, i64 9
  store i8 %16, ptr %17, align 1, !tbaa !5
  %18 = lshr i64 %3, 40
  %19 = trunc i64 %18 to i8
  %20 = getelementptr inbounds i8, ptr %0, i64 10
  store i8 %19, ptr %20, align 2, !tbaa !5
  %21 = lshr i64 %3, 32
  %22 = trunc i64 %21 to i8
  %23 = getelementptr inbounds i8, ptr %0, i64 11
  store i8 %22, ptr %23, align 1, !tbaa !5
  br label %26

24:                                               ; preds = %9
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  store i64 0, ptr %25, align 8, !tbaa !5
  br label %26

26:                                               ; preds = %24, %11
  %27 = lshr i64 %3, 24
  %28 = trunc i64 %27 to i8
  %29 = getelementptr inbounds i8, ptr %0, i64 12
  store i8 %28, ptr %29, align 4, !tbaa !5
  %30 = lshr i64 %3, 16
  %31 = trunc i64 %30 to i8
  %32 = getelementptr inbounds i8, ptr %0, i64 13
  store i8 %31, ptr %32, align 1, !tbaa !5
  %33 = lshr i64 %3, 8
  %34 = trunc i64 %33 to i8
  %35 = getelementptr inbounds i8, ptr %0, i64 14
  store i8 %34, ptr %35, align 2, !tbaa !5
  %36 = trunc i64 %3 to i8
  %37 = getelementptr inbounds i8, ptr %0, i64 15
  store i8 %36, ptr %37, align 1, !tbaa !5
  %38 = and i8 %5, -65
  store i8 %38, ptr %0, align 8, !tbaa !5
  %39 = getelementptr inbounds i8, ptr %0, i64 1
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1) %39, ptr noundef nonnull align 1 dereferenceable(1) %1, i64 %7, i1 false)
  br label %40

40:                                               ; preds = %4, %26
  %.0 = phi i32 [ 0, %26 ], [ -1, %4 ]
  ret i32 %.0
}

; 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) #1

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(argmem: readwrite) 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 nounwind willreturn memory(argmem: readwrite) }

!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"}


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