; LLVM IR from pandax381/microps :: sock (sock_recvfrom)

; 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.ip_endpoint = type { i32, i16 }
%struct.sock = type { i32, i32, i32, i32 }
%struct.sockaddr_in = type { i16, i16, i32 }

; 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 hidden ptr @sock_get(i32 noundef) #1

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

20:                                               ; preds = %5
  store i64 -1, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %54

21:                                               ; preds = %5
  %22 = load ptr, ptr %12, align 8, !tbaa !9
  %23 = getelementptr inbounds %struct.sock, ptr %22, i32 0, i32 2
  %24 = load i32, ptr %23, align 4, !tbaa !13
  %25 = icmp ne i32 %24, 2
  br i1 %25, label %26, label %27

26:                                               ; preds = %21
  store i64 -1, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %54

27:                                               ; preds = %21
  %28 = load ptr, ptr %12, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.sock, ptr %28, i32 0, i32 1
  %30 = load i32, ptr %29, align 4, !tbaa !15
  switch i32 %30, label %53 [
    i32 2, label %31
  ]

31:                                               ; preds = %27
  %32 = load ptr, ptr %12, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.sock, ptr %32, i32 0, i32 3
  %34 = load i32, ptr %33, align 4, !tbaa !16
  %35 = load ptr, ptr %8, align 8, !tbaa !9
  %36 = load i64, ptr %9, align 8, !tbaa !11
  %37 = call i64 @udp_recvfrom(i32 noundef %34, ptr noundef %35, i64 noundef %36, ptr noundef %13)
  %38 = trunc i64 %37 to i32
  store i32 %38, ptr %14, align 4, !tbaa !5
  %39 = load i32, ptr %14, align 4, !tbaa !5
  %40 = icmp ne i32 %39, -1
  br i1 %40, label %41, label %50

41:                                               ; preds = %31
  %42 = getelementptr inbounds %struct.ip_endpoint, ptr %13, i32 0, i32 0
  %43 = load i32, ptr %42, align 4, !tbaa !17
  %44 = load ptr, ptr %10, align 8, !tbaa !9
  %45 = getelementptr inbounds %struct.sockaddr_in, ptr %44, i32 0, i32 2
  store i32 %43, ptr %45, align 4, !tbaa !20
  %46 = getelementptr inbounds %struct.ip_endpoint, ptr %13, i32 0, i32 1
  %47 = load i16, ptr %46, align 4, !tbaa !22
  %48 = load ptr, ptr %10, align 8, !tbaa !9
  %49 = getelementptr inbounds %struct.sockaddr_in, ptr %48, i32 0, i32 1
  store i16 %47, ptr %49, align 2, !tbaa !23
  br label %50

50:                                               ; preds = %41, %31
  %51 = load i32, ptr %14, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  store i64 %52, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %54

53:                                               ; preds = %27
  store i64 -1, ptr %6, align 8
  store i32 1, ptr %15, align 4
  br label %54

54:                                               ; preds = %53, %50, %26, %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %55 = load i64, ptr %6, align 8
  ret i64 %55
}

declare i64 @udp_recvfrom(i32 noundef, ptr noundef, i64 noundef, ptr noundef) #2

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 = !{!"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 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"sock", !6, i64 0, !6, i64 4, !6, i64 8, !6, i64 12}
!15 = !{!14, !6, i64 4}
!16 = !{!14, !6, i64 12}
!17 = !{!18, !6, i64 0}
!18 = !{!"ip_endpoint", !6, i64 0, !19, i64 4}
!19 = !{!"short", !7, i64 0}
!20 = !{!21, !6, i64 4}
!21 = !{!"sockaddr_in", !19, i64 0, !19, i64 2, !6, i64 4}
!22 = !{!18, !19, i64 4}
!23 = !{!21, !19, i64 2}


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

%struct.ip_endpoint = type { i32, i16 }

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

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

; Function Attrs: nounwind uwtable
declare hidden ptr @sock_get(i32 noundef) local_unnamed_addr #1

; Function Attrs: nounwind uwtable
define dso_local range(i64 -2147483648, 2147483648) i64 @sock_recvfrom(i32 noundef %0, ptr noundef %1, i64 noundef %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef readnone %4) local_unnamed_addr #1 {
  %6 = alloca %struct.ip_endpoint, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #3
  %7 = tail call ptr @sock_get(i32 noundef %0)
  %.not = icmp eq ptr %7, null
  br i1 %.not, label %27, label %8

8:                                                ; preds = %5
  %9 = getelementptr inbounds i8, ptr %7, i64 8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %.not12 = icmp eq i32 %10, 2
  br i1 %.not12, label %11, label %27

11:                                               ; preds = %8
  %12 = getelementptr inbounds i8, ptr %7, i64 4
  %13 = load i32, ptr %12, align 4, !tbaa !10
  %cond = icmp eq i32 %13, 2
  br i1 %cond, label %14, label %27

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %7, i64 12
  %16 = load i32, ptr %15, align 4, !tbaa !11
  %17 = call i64 @udp_recvfrom(i32 noundef %16, ptr noundef %1, i64 noundef %2, ptr noundef nonnull %6) #3
  %18 = and i64 %17, 4294967295
  %.not13 = icmp eq i64 %18, 4294967295
  br i1 %.not13, label %25, label %19

19:                                               ; preds = %14
  %20 = load i32, ptr %6, align 4, !tbaa !12
  %21 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %20, ptr %21, align 4, !tbaa !15
  %22 = getelementptr inbounds i8, ptr %6, i64 4
  %23 = load i16, ptr %22, align 4, !tbaa !17
  %24 = getelementptr inbounds i8, ptr %3, i64 2
  store i16 %23, ptr %24, align 2, !tbaa !18
  br label %25

25:                                               ; preds = %19, %14
  %sext = shl i64 %17, 32
  %26 = ashr exact i64 %sext, 32
  br label %27

27:                                               ; preds = %11, %8, %5, %25
  %.0 = phi i64 [ %26, %25 ], [ -1, %5 ], [ -1, %8 ], [ -1, %11 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #3
  ret i64 %.0
}

declare i64 @udp_recvfrom(i32 noundef, ptr noundef, i64 noundef, ptr noundef) local_unnamed_addr #2

attributes #0 = { mustprogress 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, !7, i64 8}
!6 = !{!"sock", !7, i64 0, !7, i64 4, !7, i64 8, !7, i64 12}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!6, !7, i64 4}
!11 = !{!6, !7, i64 12}
!12 = !{!13, !7, i64 0}
!13 = !{!"ip_endpoint", !7, i64 0, !14, i64 4}
!14 = !{!"short", !8, i64 0}
!15 = !{!16, !7, i64 4}
!16 = !{!"sockaddr_in", !14, i64 0, !14, i64 2, !7, i64 4}
!17 = !{!13, !14, i64 4}
!18 = !{!16, !14, i64 2}


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