; LLVM IR from uNetworking/uSockets :: examples (udp_benchmark)

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

@messages = external dso_local global float, align 4
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1
@send_buf = external dso_local global ptr, align 8

declare i32 @printf(ptr noundef, ...) #0

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

16:                                               ; preds = %52, %3
  %17 = load i32, ptr %7, align 4, !tbaa !9
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %55

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  %22 = load ptr, ptr %5, align 8, !tbaa !5
  %23 = load i32, ptr %7, align 4, !tbaa !9
  %24 = call ptr @us_udp_packet_buffer_payload(ptr noundef %22, i32 noundef %23)
  store ptr %24, ptr %8, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %25 = load ptr, ptr %5, align 8, !tbaa !5
  %26 = load i32, ptr %7, align 4, !tbaa !9
  %27 = call i32 @us_udp_packet_buffer_payload_length(ptr noundef %25, i32 noundef %26)
  store i32 %27, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %28 = load ptr, ptr %5, align 8, !tbaa !5
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = call i32 @us_udp_packet_buffer_ecn(ptr noundef %28, i32 noundef %29)
  store i32 %30, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = call ptr @us_udp_packet_buffer_peer(ptr noundef %31, i32 noundef %32)
  store ptr %33, ptr %11, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %34 = load ptr, ptr %5, align 8, !tbaa !5
  %35 = load i32, ptr %7, align 4, !tbaa !9
  %36 = getelementptr inbounds [16 x i8], ptr %12, i64 0, i64 0
  %37 = call i32 @us_udp_packet_buffer_local_ip(ptr noundef %34, i32 noundef %35, ptr noundef %36)
  store i32 %37, ptr %13, align 4, !tbaa !9
  %38 = load i32, ptr %13, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 0
  br i1 %39, label %42, label %40

40:                                               ; preds = %21
  %41 = call i32 (ptr, ...) @printf(ptr noundef @.str.1)
  call void @exit(i32 noundef 0) #5
  unreachable

42:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  %43 = load ptr, ptr %4, align 8, !tbaa !5
  %44 = call i32 @us_udp_socket_bound_port(ptr noundef %43)
  store i32 %44, ptr %14, align 4, !tbaa !9
  %45 = load ptr, ptr @send_buf, align 8, !tbaa !5
  %46 = load i32, ptr %7, align 4, !tbaa !9
  %47 = load ptr, ptr %8, align 8, !tbaa !5
  %48 = load i32, ptr %9, align 4, !tbaa !9
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  call void @us_udp_buffer_set_packet_payload(ptr noundef %45, i32 noundef %46, i32 noundef 0, ptr noundef %47, i32 noundef %48, ptr noundef %49)
  %50 = load float, ptr @messages, align 4, !tbaa !11
  %51 = fadd float %50, 1.000000e+00
  store float %51, ptr @messages, align 4, !tbaa !11
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 16, ptr %12) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %52

52:                                               ; preds = %42
  %53 = load i32, ptr %7, align 4, !tbaa !9
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %7, align 4, !tbaa !9
  br label %16, !llvm.loop !13

55:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #4
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  %57 = load ptr, ptr @send_buf, align 8, !tbaa !5
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = call i32 @us_udp_socket_send(ptr noundef %56, ptr noundef %57, i32 noundef %58)
  store i32 %59, ptr %15, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #4
  ret void
}

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

declare ptr @us_udp_packet_buffer_payload(ptr noundef, i32 noundef) #0

declare i32 @us_udp_packet_buffer_payload_length(ptr noundef, i32 noundef) #0

declare i32 @us_udp_packet_buffer_ecn(ptr noundef, i32 noundef) #0

declare ptr @us_udp_packet_buffer_peer(ptr noundef, i32 noundef) #0

declare i32 @us_udp_packet_buffer_local_ip(ptr noundef, i32 noundef, ptr noundef) #0

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

declare i32 @us_udp_socket_bound_port(ptr noundef) #0

declare void @us_udp_buffer_set_packet_payload(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) #0

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

declare i32 @us_udp_socket_send(ptr noundef, ptr noundef, i32 noundef) #0

attributes #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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"float", !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"

@messages = external dso_local local_unnamed_addr global float, align 4
@.str.1 = external hidden unnamed_addr constant [34 x i8], align 1
@send_buf = external dso_local local_unnamed_addr global ptr, align 8

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

; Function Attrs: nounwind uwtable
define dso_local void @on_server_data(ptr noundef %0, ptr noundef %1, i32 noundef %2) local_unnamed_addr #1 {
  %4 = alloca [16 x i8], align 16
  %5 = icmp sgt i32 %2, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %15, %3
  %6 = load ptr, ptr @send_buf, align 8, !tbaa !5
  %7 = call i32 @us_udp_socket_send(ptr noundef %0, ptr noundef %6, i32 noundef %2) #5
  ret void

.lr.ph:                                           ; preds = %3, %15
  %.021 = phi i32 [ %20, %15 ], [ 0, %3 ]
  %8 = call ptr @us_udp_packet_buffer_payload(ptr noundef %1, i32 noundef %.021) #5
  %9 = call i32 @us_udp_packet_buffer_payload_length(ptr noundef %1, i32 noundef %.021) #5
  %10 = call i32 @us_udp_packet_buffer_ecn(ptr noundef %1, i32 noundef %.021) #5
  %11 = call ptr @us_udp_packet_buffer_peer(ptr noundef %1, i32 noundef %.021) #5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #5
  %12 = call i32 @us_udp_packet_buffer_local_ip(ptr noundef %1, i32 noundef %.021, ptr noundef nonnull %4) #5
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %13, label %15

13:                                               ; preds = %.lr.ph
  %14 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1)
  call void @exit(i32 noundef 0) #6
  unreachable

15:                                               ; preds = %.lr.ph
  %16 = call i32 @us_udp_socket_bound_port(ptr noundef %0) #5
  %17 = load ptr, ptr @send_buf, align 8, !tbaa !5
  call void @us_udp_buffer_set_packet_payload(ptr noundef %17, i32 noundef %.021, i32 noundef 0, ptr noundef %8, i32 noundef %9, ptr noundef %11) #5
  %18 = load float, ptr @messages, align 4, !tbaa !9
  %19 = fadd float %18, 1.000000e+00
  store float %19, ptr @messages, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %4) #5
  %20 = add nuw nsw i32 %.021, 1
  %exitcond.not = icmp eq i32 %20, %2
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !11
}

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

declare ptr @us_udp_packet_buffer_payload(ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @us_udp_packet_buffer_payload_length(ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @us_udp_packet_buffer_ecn(ptr noundef, i32 noundef) local_unnamed_addr #3

declare ptr @us_udp_packet_buffer_peer(ptr noundef, i32 noundef) local_unnamed_addr #3

declare i32 @us_udp_packet_buffer_local_ip(ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

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

declare i32 @us_udp_socket_bound_port(ptr noundef) local_unnamed_addr #3

declare void @us_udp_buffer_set_packet_payload(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #3

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

declare i32 @us_udp_socket_send(ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

attributes #0 = { 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 #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 = { nounwind }
attributes #6 = { 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 = !{!"float", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass