; LLVM IR from aws/s2n-tls :: bin (echo)

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

@stderr = external global ptr, align 8
@s2n_errno = external thread_local global i32, align 4
@.str.14 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.74 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.75 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @print_s2n_error(ptr noundef) #0

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

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) #3

; Function Attrs: nounwind uwtable
declare dso_local i32 @wait_for_event(i32 noundef, i32 noundef) #0

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

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

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

declare i32 @s2n_error_get_type(i32 noundef) #2

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

18:                                               ; preds = %65, %5
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #6
  %19 = load i64, ptr %11, align 8, !tbaa !11
  %20 = icmp ult i64 %19, 9223372036854775807
  br i1 %20, label %21, label %23

21:                                               ; preds = %18
  %22 = load i64, ptr %11, align 8, !tbaa !11
  br label %24

23:                                               ; preds = %18
  br label %24

24:                                               ; preds = %23, %21
  %25 = phi i64 [ %22, %21 ], [ 9223372036854775807, %23 ]
  store i64 %25, ptr %13, align 8, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #6
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  %28 = load i64, ptr %13, align 8, !tbaa !11
  %29 = load ptr, ptr %10, align 8, !tbaa !5
  %30 = call i64 @s2n_send(ptr noundef %26, ptr noundef %27, i64 noundef %28, ptr noundef %29)
  store i64 %30, ptr %14, align 8, !tbaa !11
  %31 = load i64, ptr %14, align 8, !tbaa !11
  %32 = icmp slt i64 %31, 0
  br i1 %32, label %33, label %55

33:                                               ; preds = %24
  %34 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  %35 = load i32, ptr %34, align 4, !tbaa !9
  %36 = call i32 @s2n_error_get_type(i32 noundef %35)
  %37 = icmp ne i32 %36, 3
  br i1 %37, label %38, label %44

38:                                               ; preds = %33
  %39 = load ptr, ptr @stderr, align 8, !tbaa !5
  %40 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  %41 = load i32, ptr %40, align 4, !tbaa !9
  %42 = call ptr @s2n_strerror(i32 noundef %41, ptr noundef @.str.14)
  %43 = call i32 (ptr, ptr, ...) @fprintf(ptr noundef %39, ptr noundef @.str.74, ptr noundef %42) #6
  call void @exit(i32 noundef 1) #7
  unreachable

44:                                               ; preds = %33
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = load ptr, ptr %10, align 8, !tbaa !5
  %48 = load i32, ptr %47, align 4, !tbaa !9
  %49 = call i32 @wait_for_event(i32 noundef %46, i32 noundef %48)
  %50 = icmp slt i32 %49, 0
  br i1 %50, label %51, label %52

51:                                               ; preds = %45
  call void @print_s2n_error(ptr noundef @.str.75)
  call void @exit(i32 noundef 1) #7
  unreachable

52:                                               ; preds = %45
  br label %53

53:                                               ; preds = %52
  br label %54

54:                                               ; preds = %53
  store i32 3, ptr %15, align 4
  br label %62

55:                                               ; preds = %24
  %56 = load i64, ptr %14, align 8, !tbaa !11
  %57 = load i64, ptr %11, align 8, !tbaa !11
  %58 = sub i64 %57, %56
  store i64 %58, ptr %11, align 8, !tbaa !11
  %59 = load i64, ptr %14, align 8, !tbaa !11
  %60 = load ptr, ptr %12, align 8, !tbaa !5
  %61 = getelementptr inbounds i8, ptr %60, i64 %59
  store ptr %61, ptr %12, align 8, !tbaa !5
  store i32 0, ptr %15, align 4
  br label %62

62:                                               ; preds = %55, %54
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #6
  %63 = load i32, ptr %15, align 4
  switch i32 %63, label %69 [
    i32 0, label %64
    i32 3, label %65
  ]

64:                                               ; preds = %62
  br label %65

65:                                               ; preds = %64, %62
  %66 = load i64, ptr %11, align 8, !tbaa !11
  %67 = icmp ugt i64 %66, 0
  br i1 %67, label %18, label %68, !llvm.loop !13

68:                                               ; preds = %65
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #6
  ret void

69:                                               ; preds = %62
  unreachable
}

declare i64 @s2n_send(ptr noundef, ptr noundef, i64 noundef, ptr noundef) #2

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" }
attributes #1 = { 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 = { "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 }
attributes #7 = { 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 = !{!"long", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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"

@stderr = external local_unnamed_addr global ptr, align 8
@s2n_errno = external thread_local local_unnamed_addr global i32, align 4
@.str.14 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.74 = external hidden unnamed_addr constant [35 x i8], align 1
@.str.75 = external hidden unnamed_addr constant [20 x i8], align 1

; Function Attrs: nounwind uwtable
declare dso_local void @print_s2n_error(ptr noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @wait_for_event(i32 noundef, i32 noundef) local_unnamed_addr #0

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

declare i32 @s2n_error_get_type(i32 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local void @send_data(ptr noundef %0, i32 noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = tail call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @s2n_errno)
  br label %7

7:                                                ; preds = %27, %5
  %.015 = phi ptr [ %2, %5 ], [ %.116, %27 ]
  %.0 = phi i64 [ %3, %5 ], [ %.1, %27 ]
  %8 = tail call i64 @llvm.umin.i64(i64 %.0, i64 9223372036854775807)
  %9 = tail call i64 @s2n_send(ptr noundef %0, ptr noundef %.015, i64 noundef %8, ptr noundef %4) #6
  %10 = icmp slt i64 %9, 0
  br i1 %10, label %11, label %24

11:                                               ; preds = %7
  %12 = load i32, ptr %6, align 4, !tbaa !5
  %13 = tail call i32 @s2n_error_get_type(i32 noundef %12) #6
  %.not = icmp eq i32 %13, 3
  br i1 %.not, label %19, label %14

14:                                               ; preds = %11
  %15 = load ptr, ptr @stderr, align 8, !tbaa !9
  %16 = load i32, ptr %6, align 4, !tbaa !5
  %17 = tail call ptr @s2n_strerror(i32 noundef %16, ptr noundef nonnull @.str.14) #6
  %18 = tail call i32 (ptr, ptr, ...) @fprintf(ptr noundef %15, ptr noundef nonnull @.str.74, ptr noundef %17) #7
  tail call void @exit(i32 noundef 1) #8
  unreachable

19:                                               ; preds = %11
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = tail call i32 @wait_for_event(i32 noundef %1, i32 noundef %20)
  %22 = icmp slt i32 %21, 0
  br i1 %22, label %23, label %27

23:                                               ; preds = %19
  tail call void @print_s2n_error(ptr noundef nonnull @.str.75)
  tail call void @exit(i32 noundef 1) #8
  unreachable

24:                                               ; preds = %7
  %25 = sub i64 %.0, %9
  %26 = getelementptr inbounds i8, ptr %.015, i64 %9
  br label %27

27:                                               ; preds = %19, %24
  %.116 = phi ptr [ %26, %24 ], [ %.015, %19 ]
  %.1 = phi i64 [ %25, %24 ], [ %.0, %19 ]
  %.not18 = icmp eq i64 %.1, 0
  br i1 %.not18, label %28, label %7, !llvm.loop !11

28:                                               ; preds = %27
  ret void
}

declare i64 @s2n_send(ptr noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.umin.i64(i64, i64) #5

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" }
attributes #1 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #6 = { nounwind }
attributes #7 = { cold nounwind }
attributes #8 = { 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LICMPass,SROAPass,SimplifyCFGPass,TailCallElimPass