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

; 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"

%union.siv_block_u = type { [2 x i64] }
%struct.siv128_context = type { %union.siv_block_u, %union.siv_block_u, ptr, ptr, ptr, i32, 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: 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @siv128_do_s2v_p(ptr noundef, ptr noundef, ptr noundef, i64 noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @siv128_do_encrypt(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) #2

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

19:                                               ; preds = %4
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %90

20:                                               ; preds = %4
  %21 = load ptr, ptr %6, align 8, !tbaa !5
  %22 = getelementptr inbounds %struct.siv128_context, ptr %21, i32 0, i32 6
  %23 = load i32, ptr %22, align 4, !tbaa !11
  %24 = add nsw i32 %23, -1
  store i32 %24, ptr %22, align 4, !tbaa !11
  %25 = load ptr, ptr %6, align 8, !tbaa !5
  %26 = getelementptr inbounds %struct.siv128_context, ptr %25, i32 0, i32 1
  %27 = getelementptr inbounds [16 x i8], ptr %26, i64 0, i64 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %12, ptr align 8 %27, i64 16, i1 false)
  %28 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 8
  %29 = load i8, ptr %28, align 8, !tbaa !14
  %30 = zext i8 %29 to i32
  %31 = and i32 %30, 127
  %32 = trunc i32 %31 to i8
  store i8 %32, ptr %28, align 8, !tbaa !14
  %33 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 12
  %34 = load i8, ptr %33, align 4, !tbaa !14
  %35 = zext i8 %34 to i32
  %36 = and i32 %35, 127
  %37 = trunc i32 %36 to i8
  store i8 %37, ptr %33, align 4, !tbaa !14
  %38 = load ptr, ptr %6, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.siv128_context, ptr %38, i32 0, i32 2
  %40 = load ptr, ptr %39, align 8, !tbaa !15
  %41 = load ptr, ptr %8, align 8, !tbaa !5
  %42 = load ptr, ptr %7, align 8, !tbaa !5
  %43 = load i64, ptr %9, align 8, !tbaa !9
  %44 = call i32 @siv128_do_encrypt(ptr noundef %40, ptr noundef %41, ptr noundef %42, i64 noundef %43, ptr noundef %12)
  %45 = icmp ne i32 %44, 0
  br i1 %45, label %46, label %52

46:                                               ; preds = %20
  %47 = load ptr, ptr %6, align 8, !tbaa !5
  %48 = load ptr, ptr %8, align 8, !tbaa !5
  %49 = load i64, ptr %9, align 8, !tbaa !9
  %50 = call i32 @siv128_do_s2v_p(ptr noundef %47, ptr noundef %11, ptr noundef %48, i64 noundef %49)
  %51 = icmp ne i32 %50, 0
  br i1 %51, label %53, label %52

52:                                               ; preds = %46, %20
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %90

53:                                               ; preds = %46
  %54 = load ptr, ptr %6, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.siv128_context, ptr %54, i32 0, i32 1
  %56 = getelementptr inbounds [16 x i8], ptr %55, i64 0, i64 0
  store ptr %56, ptr %10, align 8, !tbaa !5
  store i32 0, ptr %13, align 4, !tbaa !16
  br label %57

57:                                               ; preds = %74, %53
  %58 = load i32, ptr %13, align 4, !tbaa !16
  %59 = icmp slt i32 %58, 16
  br i1 %59, label %60, label %77

60:                                               ; preds = %57
  %61 = load ptr, ptr %10, align 8, !tbaa !5
  %62 = load i32, ptr %13, align 4, !tbaa !16
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i8, ptr %61, i64 %63
  %65 = load i8, ptr %64, align 1, !tbaa !14
  %66 = zext i8 %65 to i32
  %67 = load i32, ptr %13, align 4, !tbaa !16
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [16 x i8], ptr %11, i64 0, i64 %68
  %70 = load i8, ptr %69, align 1, !tbaa !14
  %71 = zext i8 %70 to i32
  %72 = xor i32 %71, %66
  %73 = trunc i32 %72 to i8
  store i8 %73, ptr %69, align 1, !tbaa !14
  br label %74

74:                                               ; preds = %60
  %75 = load i32, ptr %13, align 4, !tbaa !16
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %13, align 4, !tbaa !16
  br label %57, !llvm.loop !17

77:                                               ; preds = %57
  %78 = getelementptr inbounds [2 x i64], ptr %11, i64 0, i64 0
  %79 = load i64, ptr %78, align 8, !tbaa !14
  %80 = getelementptr inbounds [2 x i64], ptr %11, i64 0, i64 1
  %81 = load i64, ptr %80, align 8, !tbaa !14
  %82 = or i64 %79, %81
  %83 = icmp ne i64 %82, 0
  br i1 %83, label %84, label %87

84:                                               ; preds = %77
  %85 = load ptr, ptr %8, align 8, !tbaa !5
  %86 = load i64, ptr %9, align 8, !tbaa !9
  call void @OPENSSL_cleanse(ptr noundef %85, i64 noundef %86)
  store i32 0, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %90

87:                                               ; preds = %77
  %88 = load ptr, ptr %6, align 8, !tbaa !5
  %89 = getelementptr inbounds %struct.siv128_context, ptr %88, i32 0, i32 5
  store i32 0, ptr %89, align 8, !tbaa !19
  store i32 1, ptr %5, align 4
  store i32 1, ptr %14, align 4
  br label %90

90:                                               ; preds = %87, %84, %52, %19
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  %91 = load i32, ptr %5, align 4
  ret i32 %91
}

declare void @OPENSSL_cleanse(ptr noundef, i64 noundef) #4

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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 #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", !7, i64 0}
!11 = !{!12, !13, i64 60}
!12 = !{!"siv128_context", !7, i64 0, !7, i64 16, !6, i64 32, !6, i64 40, !6, i64 48, !13, i64 56, !13, i64 60}
!13 = !{!"int", !7, i64 0}
!14 = !{!7, !7, i64 0}
!15 = !{!12, !6, i64 32}
!16 = !{!13, !13, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = !{!12, !13, i64 56}


; 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"

%union.siv_block_u = type { [2 x i64] }

; 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: 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

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @siv128_do_s2v_p(ptr noundef, ptr noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden i32 @siv128_do_encrypt(ptr noundef, ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local range(i32 0, 2) i32 @ossl_siv128_decrypt(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3) local_unnamed_addr #3 {
  %5 = alloca %union.siv_block_u, align 16
  %6 = alloca %union.siv_block_u, align 8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %5) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %6) #5
  %7 = getelementptr inbounds i8, ptr %0, i64 60
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %34, label %10

10:                                               ; preds = %4
  %11 = add nsw i32 %8, -1
  store i32 %11, ptr %7, align 4, !tbaa !5
  %12 = getelementptr inbounds i8, ptr %0, i64 16
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %6, ptr noundef nonnull align 8 dereferenceable(16) %12, i64 16, i1 false)
  %13 = getelementptr inbounds i8, ptr %6, i64 8
  %14 = load i8, ptr %13, align 8, !tbaa !11
  %15 = and i8 %14, 127
  store i8 %15, ptr %13, align 8, !tbaa !11
  %16 = getelementptr inbounds i8, ptr %6, i64 12
  %17 = load i8, ptr %16, align 4, !tbaa !11
  %18 = and i8 %17, 127
  store i8 %18, ptr %16, align 4, !tbaa !11
  %19 = getelementptr inbounds i8, ptr %0, i64 32
  %20 = load ptr, ptr %19, align 8, !tbaa !12
  %21 = call i32 @siv128_do_encrypt(ptr noundef %20, ptr noundef %2, ptr noundef %1, i64 noundef %3, ptr noundef nonnull %6)
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %34, label %22

22:                                               ; preds = %10
  %23 = call i32 @siv128_do_s2v_p(ptr noundef nonnull %0, ptr noundef nonnull %5, ptr noundef %2, i64 noundef %3)
  %.not21 = icmp eq i32 %23, 0
  br i1 %.not21, label %34, label %.preheader.preheader

.preheader.preheader:                             ; preds = %22
  %24 = getelementptr inbounds i8, ptr %5, i64 8
  %25 = load <16 x i8>, ptr %12, align 1, !tbaa !11
  %26 = load <16 x i8>, ptr %5, align 16, !tbaa !11
  %27 = xor <16 x i8> %26, %25
  store <16 x i8> %27, ptr %5, align 16, !tbaa !11
  %28 = load i64, ptr %5, align 16, !tbaa !11
  %29 = load i64, ptr %24, align 8, !tbaa !11
  %30 = or i64 %29, %28
  %.not22 = icmp eq i64 %30, 0
  br i1 %.not22, label %32, label %31

31:                                               ; preds = %.preheader.preheader
  call void @OPENSSL_cleanse(ptr noundef %2, i64 noundef %3) #5
  br label %34

32:                                               ; preds = %.preheader.preheader
  %33 = getelementptr inbounds i8, ptr %0, i64 56
  store i32 0, ptr %33, align 8, !tbaa !13
  br label %34

34:                                               ; preds = %10, %22, %4, %32, %31
  %.019 = phi i32 [ 0, %31 ], [ 1, %32 ], [ 0, %4 ], [ 0, %22 ], [ 0, %10 ]
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %6) #5
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %5) #5
  ret i32 %.019
}

declare void @OPENSSL_cleanse(ptr noundef, i64 noundef) local_unnamed_addr #4

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { inlinehint 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 #3 = { 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 #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, !10, i64 60}
!6 = !{!"siv128_context", !7, i64 0, !7, i64 16, !9, i64 32, !9, i64 40, !9, i64 48, !10, i64 56, !10, i64 60}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!"any pointer", !7, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!6, !9, i64 32}
!13 = !{!6, !10, i64 56}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LoopRotatePass,LoopSimplifyPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass