; LLVM IR from aws/s2n-tls :: tests/unit (s2n_self_talk_alerts_test)

; 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.alert_ctx = type { i32, i32, i32, i8, i8 }

; 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: noreturn nounwind
declare void @exit(i32 noundef) #1

; Function Attrs: nounwind uwtable
define dso_local i32 @client_hello_send_alerts(ptr noundef %0, ptr noundef %1) #2 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca [7 x i8], align 1
  %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 8, ptr %5) #4
  %8 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %8, ptr %5, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 7, ptr %6) #4
  store i8 21, ptr %6, align 1, !tbaa !9
  %9 = getelementptr inbounds i8, ptr %6, i64 1
  store i8 3, ptr %9, align 1, !tbaa !9
  %10 = getelementptr inbounds i8, ptr %6, i64 2
  store i8 3, ptr %10, align 1, !tbaa !9
  %11 = getelementptr inbounds i8, ptr %6, i64 3
  store i8 0, ptr %11, align 1, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %6, i64 4
  store i8 2, ptr %12, align 1, !tbaa !9
  %13 = getelementptr inbounds i8, ptr %6, i64 5
  %14 = load ptr, ptr %5, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.alert_ctx, ptr %14, i32 0, i32 3
  %16 = load i8, ptr %15, align 4, !tbaa !10
  store i8 %16, ptr %13, align 1, !tbaa !9
  %17 = getelementptr inbounds i8, ptr %6, i64 6
  %18 = load ptr, ptr %5, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.alert_ctx, ptr %18, i32 0, i32 4
  %20 = load i8, ptr %19, align 1, !tbaa !13
  store i8 %20, ptr %17, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !14
  br label %21

21:                                               ; preds = %41, %2
  %22 = load i32, ptr %7, align 4, !tbaa !14
  %23 = load ptr, ptr %5, align 8, !tbaa !5
  %24 = getelementptr inbounds %struct.alert_ctx, ptr %23, i32 0, i32 2
  %25 = load i32, ptr %24, align 4, !tbaa !15
  %26 = icmp slt i32 %22, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %21
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %44

28:                                               ; preds = %21
  %29 = load ptr, ptr %5, align 8, !tbaa !5
  %30 = getelementptr inbounds %struct.alert_ctx, ptr %29, i32 0, i32 0
  %31 = load i32, ptr %30, align 4, !tbaa !16
  %32 = getelementptr inbounds [7 x i8], ptr %6, i64 0, i64 0
  %33 = call i64 @write(i32 noundef %31, ptr noundef %32, i64 noundef 7)
  %34 = icmp ne i64 %33, 7
  br i1 %34, label %35, label %36

35:                                               ; preds = %28
  call void @exit(i32 noundef 100) #5
  unreachable

36:                                               ; preds = %28
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.alert_ctx, ptr %37, i32 0, i32 1
  %39 = load i32, ptr %38, align 4, !tbaa !17
  %40 = add nsw i32 %39, 1
  store i32 %40, ptr %38, align 4, !tbaa !17
  br label %41

41:                                               ; preds = %36
  %42 = load i32, ptr %7, align 4, !tbaa !14
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %7, align 4, !tbaa !14
  br label %21, !llvm.loop !18

44:                                               ; preds = %27
  call void @llvm.lifetime.end.p0(i64 7, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #4
  ret i32 0
}

declare i64 @write(i32 noundef, ptr noundef, i64 noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 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 = { "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 = { nounwind }
attributes #5 = { noreturn 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 = !{!7, !7, i64 0}
!10 = !{!11, !7, i64 12}
!11 = !{!"alert_ctx", !12, i64 0, !12, i64 4, !12, i64 8, !7, i64 12, !7, i64 13}
!12 = !{!"int", !7, i64 0}
!13 = !{!11, !7, i64 13}
!14 = !{!12, !12, i64 0}
!15 = !{!11, !12, i64 8}
!16 = !{!11, !12, i64 0}
!17 = !{!11, !12, i64 4}
!18 = distinct !{!18, !19}
!19 = !{!"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: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @client_hello_send_alerts(ptr nocapture noundef readnone %0, ptr nocapture noundef %1) local_unnamed_addr #2 {
  %3 = alloca [7 x i8], align 4
  call void @llvm.lifetime.start.p0(i64 7, ptr nonnull %3) #4
  store <4 x i8> <i8 21, i8 3, i8 3, i8 0>, ptr %3, align 4, !tbaa !5
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  store i8 2, ptr %4, align 4, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %3, i64 5
  %6 = getelementptr inbounds i8, ptr %1, i64 12
  %7 = load i8, ptr %6, align 4, !tbaa !8
  store i8 %7, ptr %5, align 1, !tbaa !5
  %8 = getelementptr inbounds i8, ptr %3, i64 6
  %9 = getelementptr inbounds i8, ptr %1, i64 13
  %10 = load i8, ptr %9, align 1, !tbaa !11
  store i8 %10, ptr %8, align 2, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %1, i64 8
  %12 = load i32, ptr %11, align 4, !tbaa !12
  %13 = icmp sgt i32 %12, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %2
  %14 = getelementptr inbounds i8, ptr %1, i64 4
  br label %15

._crit_edge:                                      ; preds = %19, %2
  call void @llvm.lifetime.end.p0(i64 7, ptr nonnull %3) #4
  ret i32 0

15:                                               ; preds = %.lr.ph, %19
  %.07 = phi i32 [ 0, %.lr.ph ], [ %22, %19 ]
  %16 = load i32, ptr %1, align 4, !tbaa !13
  %17 = call i64 @write(i32 noundef %16, ptr noundef nonnull %3, i64 noundef 7) #4
  %.not = icmp eq i64 %17, 7
  br i1 %.not, label %19, label %18

18:                                               ; preds = %15
  tail call void @exit(i32 noundef 100) #5
  unreachable

19:                                               ; preds = %15
  %20 = load i32, ptr %14, align 4, !tbaa !14
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr %14, align 4, !tbaa !14
  %22 = add nuw nsw i32 %.07, 1
  %23 = load i32, ptr %11, align 4, !tbaa !12
  %24 = icmp slt i32 %22, %23
  br i1 %24, label %15, label %._crit_edge, !llvm.loop !15
}

; Function Attrs: nofree
declare noundef i64 @write(i32 noundef, ptr nocapture noundef readonly, i64 noundef) local_unnamed_addr #3

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { noreturn nounwind "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 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 = { nofree "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 = { nounwind }
attributes #5 = { noreturn 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 = !{!9, !6, i64 12}
!9 = !{!"alert_ctx", !10, i64 0, !10, i64 4, !10, i64 8, !6, i64 12, !6, i64 13}
!10 = !{!"int", !6, i64 0}
!11 = !{!9, !6, i64 13}
!12 = !{!9, !10, i64 8}
!13 = !{!9, !10, i64 0}
!14 = !{!9, !10, i64 4}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass