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

; 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_sendto(i32 noundef %0, ptr noundef %1, i64 noundef %2, ptr noundef %3, i32 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 i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca %struct.ip_endpoint, align 4
  %14 = 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 i32 %4, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #3
  %15 = load i32, ptr %7, align 4, !tbaa !5
  %16 = call ptr @sock_get(i32 noundef %15)
  store ptr %16, ptr %12, align 8, !tbaa !9
  %17 = load ptr, ptr %12, align 8, !tbaa !9
  %18 = icmp ne ptr %17, null
  br i1 %18, label %20, label %19

19:                                               ; preds = %5
  store i64 -1, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %46

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

25:                                               ; preds = %20
  store i64 -1, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %46

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

30:                                               ; preds = %26
  %31 = load ptr, ptr %10, align 8, !tbaa !9
  %32 = getelementptr inbounds %struct.sockaddr_in, ptr %31, i32 0, i32 2
  %33 = load i32, ptr %32, align 4, !tbaa !16
  %34 = getelementptr inbounds %struct.ip_endpoint, ptr %13, i32 0, i32 0
  store i32 %33, ptr %34, align 4, !tbaa !19
  %35 = load ptr, ptr %10, align 8, !tbaa !9
  %36 = getelementptr inbounds %struct.sockaddr_in, ptr %35, i32 0, i32 1
  %37 = load i16, ptr %36, align 2, !tbaa !21
  %38 = getelementptr inbounds %struct.ip_endpoint, ptr %13, i32 0, i32 1
  store i16 %37, ptr %38, align 4, !tbaa !22
  %39 = load ptr, ptr %12, align 8, !tbaa !9
  %40 = getelementptr inbounds %struct.sock, ptr %39, i32 0, i32 3
  %41 = load i32, ptr %40, align 4, !tbaa !23
  %42 = load ptr, ptr %8, align 8, !tbaa !9
  %43 = load i64, ptr %9, align 8, !tbaa !11
  %44 = call i64 @udp_sendto(i32 noundef %41, ptr noundef %42, i64 noundef %43, ptr noundef %13)
  store i64 %44, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %46

45:                                               ; preds = %26
  store i64 -1, ptr %6, align 8
  store i32 1, ptr %14, align 4
  br label %46

46:                                               ; preds = %45, %30, %25, %19
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #3
  %47 = load i64, ptr %6, align 8
  ret i64 %47
}

declare i64 @udp_sendto(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 = !{!17, !6, i64 4}
!17 = !{!"sockaddr_in", !18, i64 0, !18, i64 2, !6, i64 4}
!18 = !{!"short", !7, i64 0}
!19 = !{!20, !6, i64 0}
!20 = !{!"ip_endpoint", !6, i64 0, !18, i64 4}
!21 = !{!17, !18, i64 2}
!22 = !{!20, !18, i64 4}
!23 = !{!14, !6, i64 12}


; 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 i64 @sock_sendto(i32 noundef %0, ptr noundef %1, i64 noundef %2, ptr nocapture noundef readonly %3, i32 noundef %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 %23, label %8

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

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 %23

14:                                               ; preds = %11
  %15 = getelementptr inbounds i8, ptr %3, i64 4
  %16 = load i32, ptr %15, align 4, !tbaa !11
  store i32 %16, ptr %6, align 4, !tbaa !14
  %17 = getelementptr inbounds i8, ptr %3, i64 2
  %18 = load i16, ptr %17, align 2, !tbaa !16
  %19 = getelementptr inbounds i8, ptr %6, i64 4
  store i16 %18, ptr %19, align 4, !tbaa !17
  %20 = getelementptr inbounds i8, ptr %7, i64 12
  %21 = load i32, ptr %20, align 4, !tbaa !18
  %22 = call i64 @udp_sendto(i32 noundef %21, ptr noundef %1, i64 noundef %2, ptr noundef nonnull %6) #3
  br label %23

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

declare i64 @udp_sendto(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 = !{!12, !7, i64 4}
!12 = !{!"sockaddr_in", !13, i64 0, !13, i64 2, !7, i64 4}
!13 = !{!"short", !8, i64 0}
!14 = !{!15, !7, i64 0}
!15 = !{!"ip_endpoint", !7, i64 0, !13, i64 4}
!16 = !{!12, !13, i64 2}
!17 = !{!15, !13, i64 4}
!18 = !{!6, !7, i64 12}


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