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

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

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

; Function Attrs: nounwind uwtable
define dso_local void @CRYPTO_cfb128_1_encrypt(ptr noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, i32 noundef %6, ptr noundef %7) #1 {
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i64, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i64, align 8
  %18 = alloca [1 x i8], align 1
  %19 = alloca [1 x i8], align 1
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i64 %2, ptr %11, align 8, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store i32 %6, ptr %15, align 4, !tbaa !11
  store ptr %7, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %18) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr %19) #2
  store i64 0, ptr %17, align 8, !tbaa !9
  br label %20

20:                                               ; preds = %75, %8
  %21 = load i64, ptr %17, align 8, !tbaa !9
  %22 = load i64, ptr %11, align 8, !tbaa !9
  %23 = icmp ult i64 %21, %22
  br i1 %23, label %24, label %78

24:                                               ; preds = %20
  %25 = load ptr, ptr %9, align 8, !tbaa !5
  %26 = load i64, ptr %17, align 8, !tbaa !9
  %27 = udiv i64 %26, 8
  %28 = getelementptr inbounds i8, ptr %25, i64 %27
  %29 = load i8, ptr %28, align 1, !tbaa !13
  %30 = zext i8 %29 to i32
  %31 = load i64, ptr %17, align 8, !tbaa !9
  %32 = urem i64 %31, 8
  %33 = sub i64 7, %32
  %34 = trunc i64 %33 to i32
  %35 = shl i32 1, %34
  %36 = and i32 %30, %35
  %37 = icmp ne i32 %36, 0
  %38 = zext i1 %37 to i64
  %39 = select i1 %37, i32 128, i32 0
  %40 = trunc i32 %39 to i8
  %41 = getelementptr inbounds [1 x i8], ptr %18, i64 0, i64 0
  store i8 %40, ptr %41, align 1, !tbaa !13
  %42 = getelementptr inbounds [1 x i8], ptr %18, i64 0, i64 0
  %43 = getelementptr inbounds [1 x i8], ptr %19, i64 0, i64 0
  %44 = load ptr, ptr %12, align 8, !tbaa !5
  %45 = load ptr, ptr %13, align 8, !tbaa !5
  %46 = load i32, ptr %15, align 4, !tbaa !11
  %47 = load ptr, ptr %16, align 8, !tbaa !5
  call void @cfbr_encrypt_block(ptr noundef %42, ptr noundef %43, i32 noundef 1, ptr noundef %44, ptr noundef %45, i32 noundef %46, ptr noundef %47)
  %48 = load ptr, ptr %10, align 8, !tbaa !5
  %49 = load i64, ptr %17, align 8, !tbaa !9
  %50 = udiv i64 %49, 8
  %51 = getelementptr inbounds i8, ptr %48, i64 %50
  %52 = load i8, ptr %51, align 1, !tbaa !13
  %53 = zext i8 %52 to i32
  %54 = load i64, ptr %17, align 8, !tbaa !9
  %55 = urem i64 %54, 8
  %56 = sub i64 7, %55
  %57 = trunc i64 %56 to i32
  %58 = shl i32 1, %57
  %59 = xor i32 %58, -1
  %60 = and i32 %53, %59
  %61 = getelementptr inbounds [1 x i8], ptr %19, i64 0, i64 0
  %62 = load i8, ptr %61, align 1, !tbaa !13
  %63 = zext i8 %62 to i32
  %64 = and i32 %63, 128
  %65 = load i64, ptr %17, align 8, !tbaa !9
  %66 = urem i64 %65, 8
  %67 = trunc i64 %66 to i32
  %68 = ashr i32 %64, %67
  %69 = or i32 %60, %68
  %70 = trunc i32 %69 to i8
  %71 = load ptr, ptr %10, align 8, !tbaa !5
  %72 = load i64, ptr %17, align 8, !tbaa !9
  %73 = udiv i64 %72, 8
  %74 = getelementptr inbounds i8, ptr %71, i64 %73
  store i8 %70, ptr %74, align 1, !tbaa !13
  br label %75

75:                                               ; preds = %24
  %76 = load i64, ptr %17, align 8, !tbaa !9
  %77 = add i64 %76, 1
  store i64 %77, ptr %17, align 8, !tbaa !9
  br label %20, !llvm.loop !14

78:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 1, ptr %19) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %18) #2
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @cfbr_encrypt_block(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

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

; Function Attrs: nounwind uwtable
define dso_local void @CRYPTO_cfb128_1_encrypt(ptr nocapture noundef readonly %0, ptr nocapture noundef %1, i64 noundef %2, ptr noundef %3, ptr noundef %4, ptr nocapture noundef readnone %5, i32 noundef %6, ptr noundef %7) local_unnamed_addr #1 {
  %9 = alloca [1 x i8], align 1
  %10 = alloca [1 x i8], align 1
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %9) #2
  call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %10) #2
  %.not16 = icmp eq i64 %2, 0
  br i1 %.not16, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.015 = phi i64 [ %32, %.lr.ph ], [ 0, %8 ]
  %11 = lshr i64 %.015, 3
  %12 = getelementptr inbounds i8, ptr %0, i64 %11
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = zext i8 %13 to i32
  %15 = trunc i64 %.015 to i32
  %16 = and i32 %15, 7
  %17 = xor i32 %16, 7
  %18 = shl nuw nsw i32 1, %17
  %19 = and i32 %18, %14
  %.not = icmp eq i32 %19, 0
  %20 = select i1 %.not, i8 0, i8 -128
  store i8 %20, ptr %9, align 1, !tbaa !5
  call void @cfbr_encrypt_block(ptr noundef nonnull %9, ptr noundef nonnull %10, i32 noundef 1, ptr noundef %3, ptr noundef %4, i32 noundef %6, ptr noundef %7)
  %21 = getelementptr inbounds i8, ptr %1, i64 %11
  %22 = load i8, ptr %21, align 1, !tbaa !5
  %23 = zext i8 %22 to i32
  %24 = xor i32 %18, -1
  %25 = and i32 %23, %24
  %26 = load i8, ptr %10, align 1, !tbaa !5
  %27 = and i8 %26, -128
  %28 = zext i8 %27 to i32
  %29 = lshr exact i32 %28, %16
  %30 = or i32 %29, %25
  %31 = trunc nuw i32 %30 to i8
  store i8 %31, ptr %21, align 1, !tbaa !5
  %32 = add nuw i64 %.015, 1
  %exitcond.not = icmp eq i64 %32, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph, %8
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %10) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %9) #2
  ret void
}

; Function Attrs: nounwind uwtable
declare hidden void @cfbr_encrypt_block(ptr noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 = distinct !{!8, !9}
!9 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass