; 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] }

@opened_clients = external dso_local global i32, align 4
@opened_connections = external dso_local global i32, align 4
@opened_servers = external dso_local global i32, align 4

; 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: nounwind uwtable
declare dso_local void @assume_state(ptr noundef, i32 noundef) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local ptr @next_connection() #1

; Function Attrs: nounwind uwtable
define dso_local ptr @on_http_socket_open(ptr noundef %0, i32 noundef %1, ptr noundef %2, i32 noundef %3) #1 {
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  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
  store i32 %3, ptr %8, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %10 = load ptr, ptr %5, align 8, !tbaa !5
  %11 = call ptr @us_socket_ext(i32 noundef 1, ptr noundef %10)
  store ptr %11, ptr %9, align 8, !tbaa !5
  %12 = load ptr, ptr %9, align 8, !tbaa !5
  %13 = getelementptr inbounds %struct.http_socket, ptr %12, i32 0, i32 1
  store i32 1, ptr %13, align 8, !tbaa !11
  %14 = load ptr, ptr %9, align 8, !tbaa !5
  %15 = getelementptr inbounds %struct.http_socket, ptr %14, i32 0, i32 0
  store double 0x402D4E358298CC14, ptr %15, align 8, !tbaa !14
  %16 = load ptr, ptr %9, align 8, !tbaa !5
  %17 = getelementptr inbounds %struct.http_socket, ptr %16, i32 0, i32 2
  store double 0x402D4E358298CC14, ptr %17, align 8, !tbaa !15
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = load ptr, ptr %9, align 8, !tbaa !5
  %20 = getelementptr inbounds %struct.http_socket, ptr %19, i32 0, i32 3
  store i32 %18, ptr %20, align 8, !tbaa !16
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  call void @assume_state(ptr noundef %21, i32 noundef 1)
  %22 = load i32, ptr @opened_connections, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr @opened_connections, align 4, !tbaa !9
  %24 = load i32, ptr %6, align 4, !tbaa !9
  %25 = icmp ne i32 %24, 0
  br i1 %25, label %26, label %29

26:                                               ; preds = %4
  %27 = load i32, ptr @opened_clients, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @opened_clients, align 4, !tbaa !9
  br label %32

29:                                               ; preds = %4
  %30 = load i32, ptr @opened_servers, align 4, !tbaa !9
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr @opened_servers, align 4, !tbaa !9
  br label %32

32:                                               ; preds = %29, %26
  %33 = load i32, ptr %6, align 4, !tbaa !9
  %34 = icmp ne i32 %33, 0
  br i1 %34, label %35, label %40

35:                                               ; preds = %32
  %36 = load i32, ptr @opened_clients, align 4, !tbaa !9
  %37 = icmp slt i32 %36, 5000
  br i1 %37, label %38, label %40

38:                                               ; preds = %35
  %39 = call ptr @next_connection()
  br label %40

40:                                               ; preds = %38, %35, %32
  %41 = load ptr, ptr %5, align 8, !tbaa !5
  %42 = call ptr @perform_random_operation(ptr noundef %41)
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  ret ptr %42
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { "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 }

!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 8}
!12 = !{!"http_socket", !13, i64 0, !10, i64 8, !13, i64 16, !10, i64 24, !7, i64 28}
!13 = !{!"double", !7, i64 0}
!14 = !{!12, !13, i64 0}
!15 = !{!12, !13, i64 16}
!16 = !{!12, !10, i64 24}


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

@opened_clients = external dso_local local_unnamed_addr global i32, align 4
@opened_connections = external dso_local local_unnamed_addr global i32, align 4
@opened_servers = external dso_local local_unnamed_addr global i32, align 4

; 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 #1

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

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

; Function Attrs: nounwind uwtable
define dso_local ptr @on_http_socket_open(ptr noundef %0, i32 noundef %1, ptr nocapture noundef readnone %2, i32 noundef %3) local_unnamed_addr #0 {
  %5 = tail call ptr @us_socket_ext(i32 noundef 1, ptr noundef %0) #2
  %6 = getelementptr inbounds i8, ptr %5, i64 8
  store i32 1, ptr %6, align 8, !tbaa !5
  store double 0x402D4E358298CC14, ptr %5, align 8, !tbaa !11
  %7 = getelementptr inbounds i8, ptr %5, i64 16
  store double 0x402D4E358298CC14, ptr %7, align 8, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %5, i64 24
  store i32 %1, ptr %8, align 8, !tbaa !13
  tail call void @assume_state(ptr noundef %0, i32 noundef 1)
  %9 = load i32, ptr @opened_connections, align 4, !tbaa !14
  %10 = add nsw i32 %9, 1
  store i32 %10, ptr @opened_connections, align 4, !tbaa !14
  %.not = icmp eq i32 %1, 0
  br i1 %.not, label %.thread, label %13

.thread:                                          ; preds = %4
  %11 = load i32, ptr @opened_servers, align 4, !tbaa !14
  %12 = add nsw i32 %11, 1
  store i32 %12, ptr @opened_servers, align 4, !tbaa !14
  br label %19

13:                                               ; preds = %4
  %14 = load i32, ptr @opened_clients, align 4, !tbaa !14
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr @opened_clients, align 4, !tbaa !14
  %16 = icmp slt i32 %14, 4999
  br i1 %16, label %17, label %19

17:                                               ; preds = %13
  %18 = tail call ptr @next_connection()
  br label %19

19:                                               ; preds = %.thread, %17, %13
  %20 = tail call ptr @perform_random_operation(ptr noundef %0)
  ret ptr %20
}

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 = { "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 }

!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 8}
!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 = !{!6, !7, i64 0}
!12 = !{!6, !7, i64 16}
!13 = !{!6, !10, i64 24}
!14 = !{!10, !10, i64 0}


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