; 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.s2n_result = type { i32 }

@s2n_use_color_in_output = external dso_local global i8, align 1
@test_count = external dso_local global i32, align 4
@stderr = external global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [101 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [84 x i8], align 1
@s2n_errno = external thread_local global i32, align 4
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [72 x i8], align 1

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

; Function Attrs: nounwind willreturn memory(none)
declare ptr @__errno_location() #1

declare i32 @s2n_print_stacktrace(ptr noundef) #2

; Function Attrs: nounwind
declare i32 @isatty(i32 noundef) #3

; Function Attrs: nounwind
declare i32 @fileno(ptr noundef) #3

; Function Attrs: nounwind
declare i32 @fprintf(ptr noundef, ptr noundef, ...) #3

declare ptr @s2n_strerror(i32 noundef, ptr noundef) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #4

declare ptr @s2n_strerror_debug(i32 noundef, ptr noundef) #2

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) #3

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

; Function Attrs: nounwind uwtable
define dso_local i32 @cleanup(ptr noundef %0, ptr noundef %1, ptr noundef %2) #6 {
  %4 = alloca %struct.s2n_result, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store ptr %1, ptr %6, align 8, !tbaa !5
  store ptr %2, ptr %7, align 8, !tbaa !5
  br label %9

9:                                                ; preds = %3
  %10 = load i32, ptr @test_count, align 4, !tbaa !9
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr @test_count, align 4, !tbaa !9
  %12 = load ptr, ptr %7, align 8, !tbaa !5
  %13 = load ptr, ptr %12, align 8, !tbaa !5
  %14 = call i32 @s2n_cert_chain_and_key_free(ptr noundef %13)
  %15 = icmp eq i32 %14, -1
  br i1 %15, label %16, label %67

16:                                               ; preds = %9
  br label %17

17:                                               ; preds = %16
  br label %18

18:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %19 = call ptr @__errno_location() #8
  %20 = load i32, ptr %19, align 4, !tbaa !9
  store i32 %20, ptr %8, align 4, !tbaa !9
  %21 = load ptr, ptr @stderr, align 8, !tbaa !5
  %22 = call i32 @s2n_print_stacktrace(ptr noundef %21)
  %23 = load i8, ptr @s2n_use_color_in_output, align 1, !tbaa !11, !range !13, !noundef !14
  %24 = trunc i8 %23 to i1
  br i1 %24, label %25, label %47

25:                                               ; preds = %18
  %26 = load ptr, ptr @stderr, align 8, !tbaa !5
  %27 = call i32 @fileno(ptr noundef %26) #7
  %28 = call i32 @isatty(i32 noundef %27) #7
  %29 = icmp ne i32 %28, 0
  br i1 %29, label %30, label %47

30:                                               ; preds = %25
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = call ptr @__errno_location() #8
  store i32 %31, ptr %32, align 4, !tbaa !9
  %33 = load ptr, ptr @stderr, align 8, !tbaa !5
  %34 = load i32, ptr @test_count, align 4, !tbaa !9
  %35 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  %36 = load i32, ptr %35, align 4, !tbaa !9
  %37 = call ptr @s2n_strerror(i32 noundef %36, ptr noundef @.str.4)
  %38 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = call ptr @s2n_strerror_debug(i32 noundef %39, ptr noundef @.str.4)
  %41 = call ptr @__errno_location() #8
  %42 = load i32, ptr %41, align 4, !tbaa !9
  %43 = call ptr @strerror(i32 noundef %42) #7
  %44 = call ptr @__errno_location() #8
  %45 = load i32, ptr %44, align 4, !tbaa !9
  %46 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %33, ptr noundef @.str.1, i32 noundef %34, ptr noundef @.str.6, ptr noundef @.str.3, i32 noundef 133, ptr noundef %37, ptr noundef %40, ptr noundef %43, i32 noundef %45) #7
  br label %64

47:                                               ; preds = %25, %18
  %48 = load i32, ptr %8, align 4, !tbaa !9
  %49 = call ptr @__errno_location() #8
  store i32 %48, ptr %49, align 4, !tbaa !9
  %50 = load ptr, ptr @stderr, align 8, !tbaa !5
  %51 = load i32, ptr @test_count, align 4, !tbaa !9
  %52 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  %53 = load i32, ptr %52, align 4, !tbaa !9
  %54 = call ptr @s2n_strerror(i32 noundef %53, ptr noundef @.str.4)
  %55 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  %56 = load i32, ptr %55, align 4, !tbaa !9
  %57 = call ptr @s2n_strerror_debug(i32 noundef %56, ptr noundef @.str.4)
  %58 = call ptr @__errno_location() #8
  %59 = load i32, ptr %58, align 4, !tbaa !9
  %60 = call ptr @strerror(i32 noundef %59) #7
  %61 = call ptr @__errno_location() #8
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %50, ptr noundef @.str.5, i32 noundef %51, ptr noundef @.str.6, ptr noundef @.str.3, i32 noundef 133, ptr noundef %54, ptr noundef %57, ptr noundef %60, i32 noundef %62) #7
  br label %64

64:                                               ; preds = %47, %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  br label %65

65:                                               ; preds = %64
  call void @exit(i32 noundef 1) #9
  unreachable

66:                                               ; No predecessors!
  br label %67

67:                                               ; preds = %66, %9
  br label %68

68:                                               ; preds = %67
  %69 = load ptr, ptr %5, align 8, !tbaa !5
  %70 = load ptr, ptr %69, align 8, !tbaa !5
  call void @free(ptr noundef %70) #7
  %71 = load ptr, ptr %6, align 8, !tbaa !5
  %72 = load ptr, ptr %71, align 8, !tbaa !5
  call void @free(ptr noundef %72) #7
  %73 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  store i32 0, ptr %73, align 4, !tbaa !15
  %74 = getelementptr inbounds %struct.s2n_result, ptr %4, i32 0, i32 0
  %75 = load i32, ptr %74, align 4
  ret i32 %75
}

declare i32 @s2n_cert_chain_and_key_free(ptr noundef) #2

; Function Attrs: nounwind
declare void @free(ptr noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind willreturn memory(none) "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 = { "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 "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 #6 = { 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 #7 = { nounwind }
attributes #8 = { nounwind willreturn memory(none) }
attributes #9 = { 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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = !{!16, !10, i64 0}
!16 = !{!"", !10, 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"

@s2n_use_color_in_output = external dso_local local_unnamed_addr global i8, align 1
@test_count = external dso_local local_unnamed_addr global i32, align 4
@stderr = external local_unnamed_addr global ptr, align 8
@.str.1 = external hidden unnamed_addr constant [101 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [84 x i8], align 1
@s2n_errno = external thread_local local_unnamed_addr global i32, align 4
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [90 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [72 x i8], align 1

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none)
declare ptr @__errno_location() local_unnamed_addr #0

declare i32 @s2n_print_stacktrace(ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare i32 @isatty(i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare noundef i32 @fileno(ptr nocapture noundef) local_unnamed_addr #3

; Function Attrs: nofree nounwind
declare noundef i32 @fprintf(ptr nocapture noundef, ptr nocapture noundef readonly, ...) local_unnamed_addr #3

declare ptr @s2n_strerror(i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull) #4

declare ptr @s2n_strerror_debug(i32 noundef, ptr noundef) local_unnamed_addr #1

; Function Attrs: nounwind
declare ptr @strerror(i32 noundef) local_unnamed_addr #2

; Function Attrs: noreturn nounwind
declare void @exit(i32 noundef) local_unnamed_addr #5

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @cleanup(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr nocapture noundef readonly %2) local_unnamed_addr #6 {
  %4 = load i32, ptr @test_count, align 4, !tbaa !5
  %5 = add nsw i32 %4, 1
  store i32 %5, ptr @test_count, align 4, !tbaa !5
  %6 = load ptr, ptr %2, align 8, !tbaa !9
  %7 = tail call i32 @s2n_cert_chain_and_key_free(ptr noundef %6) #8
  %8 = icmp eq i32 %7, -1
  br i1 %8, label %9, label %33

9:                                                ; preds = %3
  %10 = tail call ptr @__errno_location() #9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = load ptr, ptr @stderr, align 8, !tbaa !9
  %13 = tail call i32 @s2n_print_stacktrace(ptr noundef %12) #8
  %14 = load i8, ptr @s2n_use_color_in_output, align 1, !tbaa !11, !range !13, !noundef !14
  %15 = trunc nuw i8 %14 to i1
  br i1 %15, label %16, label %20

16:                                               ; preds = %9
  %17 = load ptr, ptr @stderr, align 8, !tbaa !9
  %18 = tail call i32 @fileno(ptr noundef %17) #8
  %19 = tail call i32 @isatty(i32 noundef %18) #8
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %20, label %21

20:                                               ; preds = %16, %9
  br label %21

21:                                               ; preds = %16, %20
  %.str.5.sink = phi ptr [ @.str.5, %20 ], [ @.str.1, %16 ]
  store i32 %11, ptr %10, align 4, !tbaa !5
  %22 = load ptr, ptr @stderr, align 8, !tbaa !9
  %23 = load i32, ptr @test_count, align 4, !tbaa !5
  %24 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = tail call ptr @s2n_strerror(i32 noundef %25, ptr noundef nonnull @.str.4) #8
  %27 = load i32, ptr %24, align 4, !tbaa !5
  %28 = tail call ptr @s2n_strerror_debug(i32 noundef %27, ptr noundef nonnull @.str.4) #8
  %29 = load i32, ptr %10, align 4, !tbaa !5
  %30 = tail call ptr @strerror(i32 noundef %29) #8
  %31 = load i32, ptr %10, align 4, !tbaa !5
  %32 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %22, ptr noundef nonnull %.str.5.sink, i32 noundef %23, ptr noundef nonnull @.str.6, ptr noundef nonnull @.str.3, i32 noundef 133, ptr noundef %26, ptr noundef %28, ptr noundef %30, i32 noundef %31) #10
  tail call void @exit(i32 noundef 1) #11
  unreachable

33:                                               ; preds = %3
  %34 = load ptr, ptr %0, align 8, !tbaa !9
  tail call void @free(ptr noundef %34) #8
  %35 = load ptr, ptr %1, align 8, !tbaa !9
  tail call void @free(ptr noundef %35) #8
  ret i32 0
}

declare i32 @s2n_cert_chain_and_key_free(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #7

attributes #0 = { mustprogress nofree nosync nounwind willreturn memory(none) "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 = { "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 "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 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 #4 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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 #6 = { 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 #7 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" "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 #8 = { nounwind }
attributes #9 = { nounwind willreturn memory(none) }
attributes #10 = { cold nounwind }
attributes #11 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}


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