; LLVM IR from ARMmbed/mbed-crypto :: library (des)

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

; 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
declare dso_local void @mbedtls_des_setkey(ptr noundef, ptr noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @mbedtls_des_setkey_dec(ptr noundef %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #2
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.mbedtls_des_context, ptr %8, i32 0, i32 0
  %10 = getelementptr inbounds [32 x i32], ptr %9, i64 0, i64 0
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  call void @mbedtls_des_setkey(ptr noundef %10, ptr noundef %11)
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %74, %2
  %13 = load i32, ptr %5, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 16
  br i1 %14, label %15, label %77

15:                                               ; preds = %12
  br label %16

16:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #2
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.mbedtls_des_context, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %5, align 4, !tbaa !9
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [32 x i32], ptr %18, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !9
  store i32 %22, ptr %6, align 4, !tbaa !9
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.mbedtls_des_context, ptr %23, i32 0, i32 0
  %25 = load i32, ptr %5, align 4, !tbaa !9
  %26 = sub nsw i32 30, %25
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [32 x i32], ptr %24, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = load ptr, ptr %3, align 8, !tbaa !5
  %31 = getelementptr inbounds %struct.mbedtls_des_context, ptr %30, i32 0, i32 0
  %32 = load i32, ptr %5, align 4, !tbaa !9
  %33 = sext i32 %32 to i64
  %34 = getelementptr inbounds [32 x i32], ptr %31, i64 0, i64 %33
  store i32 %29, ptr %34, align 4, !tbaa !9
  %35 = load i32, ptr %6, align 4, !tbaa !9
  %36 = load ptr, ptr %3, align 8, !tbaa !5
  %37 = getelementptr inbounds %struct.mbedtls_des_context, ptr %36, i32 0, i32 0
  %38 = load i32, ptr %5, align 4, !tbaa !9
  %39 = sub nsw i32 30, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [32 x i32], ptr %37, i64 0, i64 %40
  store i32 %35, ptr %41, align 4, !tbaa !9
  store i32 0, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  br label %42

42:                                               ; preds = %16
  br label %43

43:                                               ; preds = %42
  br label %44

44:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #2
  %45 = load ptr, ptr %3, align 8, !tbaa !5
  %46 = getelementptr inbounds %struct.mbedtls_des_context, ptr %45, i32 0, i32 0
  %47 = load i32, ptr %5, align 4, !tbaa !9
  %48 = add nsw i32 %47, 1
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [32 x i32], ptr %46, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !9
  store i32 %51, ptr %7, align 4, !tbaa !9
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.mbedtls_des_context, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %5, align 4, !tbaa !9
  %55 = sub nsw i32 31, %54
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [32 x i32], ptr %53, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !9
  %59 = load ptr, ptr %3, align 8, !tbaa !5
  %60 = getelementptr inbounds %struct.mbedtls_des_context, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %5, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [32 x i32], ptr %60, i64 0, i64 %63
  store i32 %58, ptr %64, align 4, !tbaa !9
  %65 = load i32, ptr %7, align 4, !tbaa !9
  %66 = load ptr, ptr %3, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.mbedtls_des_context, ptr %66, i32 0, i32 0
  %68 = load i32, ptr %5, align 4, !tbaa !9
  %69 = sub nsw i32 31, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [32 x i32], ptr %67, i64 0, i64 %70
  store i32 %65, ptr %71, align 4, !tbaa !9
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  br label %72

72:                                               ; preds = %44
  br label %73

73:                                               ; preds = %72
  br label %74

74:                                               ; preds = %73
  %75 = load i32, ptr %5, align 4, !tbaa !9
  %76 = add nsw i32 %75, 2
  store i32 %76, ptr %5, align 4, !tbaa !9
  br label %12, !llvm.loop !11

77:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #2
  ret i32 0
}

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 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"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: nounwind uwtable
declare dso_local void @mbedtls_des_setkey(ptr noundef, ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @mbedtls_des_setkey_dec(ptr noundef %0, ptr noundef %1) local_unnamed_addr #0 {
  tail call void @mbedtls_des_setkey(ptr noundef %0, ptr noundef %1)
  %3 = getelementptr inbounds i8, ptr %0, i64 112
  %4 = load <4 x i32>, ptr %3, align 4, !tbaa !5
  %5 = shufflevector <4 x i32> %4, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
  %6 = load <4 x i32>, ptr %0, align 4, !tbaa !5
  store <4 x i32> %5, ptr %0, align 4, !tbaa !5
  %7 = shufflevector <4 x i32> %6, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
  store <4 x i32> %7, ptr %3, align 4, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %0, i64 16
  %9 = getelementptr inbounds i8, ptr %0, i64 96
  %10 = load <4 x i32>, ptr %9, align 4, !tbaa !5
  %11 = shufflevector <4 x i32> %10, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
  %12 = load <4 x i32>, ptr %8, align 4, !tbaa !5
  store <4 x i32> %11, ptr %8, align 4, !tbaa !5
  %13 = shufflevector <4 x i32> %12, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
  store <4 x i32> %13, ptr %9, align 4, !tbaa !5
  %14 = getelementptr inbounds i8, ptr %0, i64 32
  %15 = getelementptr inbounds i8, ptr %0, i64 80
  %16 = load <4 x i32>, ptr %15, align 4, !tbaa !5
  %17 = shufflevector <4 x i32> %16, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
  %18 = load <4 x i32>, ptr %14, align 4, !tbaa !5
  store <4 x i32> %17, ptr %14, align 4, !tbaa !5
  %19 = shufflevector <4 x i32> %18, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
  store <4 x i32> %19, ptr %15, align 4, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %0, i64 48
  %21 = getelementptr inbounds i8, ptr %0, i64 64
  %22 = load <4 x i32>, ptr %21, align 4, !tbaa !5
  %23 = shufflevector <4 x i32> %22, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
  %24 = load <4 x i32>, ptr %20, align 4, !tbaa !5
  store <4 x i32> %23, ptr %20, align 4, !tbaa !5
  %25 = shufflevector <4 x i32> %24, <4 x i32> poison, <4 x i32> <i32 2, i32 3, i32 0, i32 1>
  store <4 x i32> %25, ptr %21, align 4, !tbaa !5
  ret i32 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" }

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass