; LLVM IR from uNetworking/uSockets :: examples (hammer_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.http_socket = type { double, i32, double, i32, [128 x i8] }

@closed_clients = external dso_local global i32, align 4
@closed_servers = external dso_local global i32, align 4
@closed_connections = external dso_local global i32, align 4
@opened_clients = external dso_local global i32, align 4
@.str.5 = external hidden unnamed_addr constant [61 x i8], align 1
@listen_socket = external dso_local global ptr, align 8

; Function Attrs: nounwind uwtable
declare dso_local void @print_progress(double noundef) #0

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

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

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

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

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

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

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

declare void @us_listen_socket_close(i32 noundef, ptr noundef) #2

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

17:                                               ; preds = %3
  %18 = load i32, ptr @closed_clients, align 4, !tbaa !9
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr @closed_clients, align 4, !tbaa !9
  br label %23

20:                                               ; preds = %3
  %21 = load i32, ptr @closed_servers, align 4, !tbaa !9
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr @closed_servers, align 4, !tbaa !9
  br label %23

23:                                               ; preds = %20, %17
  %24 = load i32, ptr @closed_connections, align 4, !tbaa !9
  %25 = sitofp i32 %24 to double
  %26 = fdiv double %25, 1.000000e+04
  call void @print_progress(double noundef %26)
  %27 = load i32, ptr @closed_connections, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @closed_connections, align 4, !tbaa !9
  %29 = load i32, ptr @closed_connections, align 4, !tbaa !9
  %30 = icmp eq i32 %29, 10000
  br i1 %30, label %31, label %39

31:                                               ; preds = %23
  %32 = load i32, ptr @opened_clients, align 4, !tbaa !9
  %33 = icmp ne i32 %32, 5000
  br i1 %33, label %34, label %37

34:                                               ; preds = %31
  %35 = load i32, ptr @opened_clients, align 4, !tbaa !9
  %36 = call i32 (ptr, ...) @printf(ptr noundef @.str.5, i32 noundef %35)
  call void @exit(i32 noundef 1) #5
  unreachable

37:                                               ; preds = %31
  %38 = load ptr, ptr @listen_socket, align 8, !tbaa !5
  call void @us_listen_socket_close(i32 noundef 1, ptr noundef %38)
  br label %42

39:                                               ; preds = %23
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = call ptr @perform_random_operation(ptr noundef %40)
  store ptr %41, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %44

42:                                               ; preds = %37
  %43 = load ptr, ptr %5, align 8, !tbaa !5
  store ptr %43, ptr %4, align 8
  store i32 1, ptr %9, align 4
  br label %44

44:                                               ; preds = %42, %39
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  %45 = load ptr, ptr %4, align 8
  ret ptr %45
}

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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, !10, i64 24}
!12 = !{!"http_socket", !13, i64 0, !10, i64 8, !13, i64 16, !10, i64 24, !7, i64 28}
!13 = !{!"double", !7, 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"

@closed_clients = external dso_local local_unnamed_addr global i32, align 4
@closed_servers = external dso_local local_unnamed_addr global i32, align 4
@closed_connections = external dso_local local_unnamed_addr global i32, align 4
@opened_clients = external dso_local local_unnamed_addr global i32, align 4
@.str.5 = external hidden unnamed_addr constant [61 x i8], align 1
@listen_socket = external dso_local local_unnamed_addr global ptr, align 8

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

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

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

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

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

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

declare void @us_listen_socket_close(i32 noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local ptr @on_http_socket_close(ptr noundef %0, i32 noundef %1, ptr nocapture noundef readnone %2) local_unnamed_addr #0 {
  tail call void @assume_state(ptr noundef %0, i32 noundef 1)
  %4 = tail call ptr @us_socket_ext(i32 noundef 1, ptr noundef %0) #4
  %5 = getelementptr inbounds i8, ptr %4, i64 24
  %6 = load i32, ptr %5, align 8, !tbaa !5
  %.not = icmp eq i32 %6, 0
  %closed_servers.closed_clients = select i1 %.not, ptr @closed_servers, ptr @closed_clients
  %7 = load i32, ptr %closed_servers.closed_clients, align 4, !tbaa !11
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %closed_servers.closed_clients, align 4, !tbaa !11
  %9 = load i32, ptr @closed_connections, align 4, !tbaa !11
  %10 = sitofp i32 %9 to double
  %11 = fdiv double %10, 1.000000e+04
  tail call void @print_progress(double noundef %11)
  %12 = load i32, ptr @closed_connections, align 4, !tbaa !11
  %13 = add nsw i32 %12, 1
  store i32 %13, ptr @closed_connections, align 4, !tbaa !11
  %14 = icmp eq i32 %13, 10000
  br i1 %14, label %15, label %21

15:                                               ; preds = %3
  %16 = load i32, ptr @opened_clients, align 4, !tbaa !11
  %.not7 = icmp eq i32 %16, 5000
  br i1 %.not7, label %19, label %17

17:                                               ; preds = %15
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.5, i32 noundef %16)
  tail call void @exit(i32 noundef 1) #5
  unreachable

19:                                               ; preds = %15
  %20 = load ptr, ptr @listen_socket, align 8, !tbaa !12
  tail call void @us_listen_socket_close(i32 noundef 1, ptr noundef %20) #4
  br label %23

21:                                               ; preds = %3
  %22 = tail call ptr @perform_random_operation(ptr noundef %0)
  br label %23

23:                                               ; preds = %19, %21
  %.0 = phi ptr [ %0, %19 ], [ %22, %21 ]
  ret ptr %.0
}

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 = { 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, !10, i64 24}
!6 = !{!"http_socket", !7, i64 0, !10, i64 8, !7, i64 16, !10, i64 24, !8, i64 28}
!7 = !{!"double", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!10, !10, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"any pointer", !8, i64 0}


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