; LLVM IR from AprilAndFriends/sakit :: util/multicast-example (mc2)

; 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.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main(i32 noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca %struct.sockaddr_in, align 4
  %7 = alloca %struct.sockaddr_in, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  store i32 0, ptr %3, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 16, ptr %6) #8
  call void @llvm.lifetime.start.p0(i64 16, ptr %7) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #8
  store ptr @.str, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #8
  store ptr @.str.1, ptr %11, align 8, !tbaa !9
  %12 = call i32 @socket(i32 noundef 2, i32 noundef 2, i32 noundef 0) #8
  store i32 %12, ptr %8, align 4, !tbaa !5
  %13 = icmp slt i32 %12, 0
  br i1 %13, label %14, label %15

14:                                               ; preds = %2
  call void @perror(ptr noundef @.str.2)
  call void @exit(i32 noundef 1) #9
  unreachable

15:                                               ; preds = %2
  %16 = call i32 @socket(i32 noundef 2, i32 noundef 2, i32 noundef 0) #8
  store i32 %16, ptr %9, align 4, !tbaa !5
  %17 = icmp slt i32 %16, 0
  br i1 %17, label %18, label %19

18:                                               ; preds = %15
  call void @perror(ptr noundef @.str.2)
  call void @exit(i32 noundef 1) #9
  unreachable

19:                                               ; preds = %15
  call void @llvm.memset.p0.i64(ptr align 4 %6, i8 0, i64 16, i1 false)
  %20 = getelementptr inbounds %struct.sockaddr_in, ptr %6, i32 0, i32 0
  store i16 2, ptr %20, align 4, !tbaa !11
  %21 = call i32 @inet_addr(ptr noundef @.str.3) #8
  %22 = getelementptr inbounds %struct.sockaddr_in, ptr %6, i32 0, i32 2
  %23 = getelementptr inbounds %struct.in_addr, ptr %22, i32 0, i32 0
  store i32 %21, ptr %23, align 4, !tbaa !15
  %24 = call zeroext i16 @__bswap_16(i16 noundef zeroext 12345)
  %25 = getelementptr inbounds %struct.sockaddr_in, ptr %6, i32 0, i32 1
  store i16 %24, ptr %25, align 2, !tbaa !16
  call void @llvm.memset.p0.i64(ptr align 4 %7, i8 0, i64 16, i1 false)
  %26 = getelementptr inbounds %struct.sockaddr_in, ptr %7, i32 0, i32 0
  store i16 2, ptr %26, align 4, !tbaa !11
  %27 = call i32 @inet_addr(ptr noundef @.str.3) #8
  %28 = getelementptr inbounds %struct.sockaddr_in, ptr %7, i32 0, i32 2
  %29 = getelementptr inbounds %struct.in_addr, ptr %28, i32 0, i32 0
  store i32 %27, ptr %29, align 4, !tbaa !15
  %30 = call zeroext i16 @__bswap_16(i16 noundef zeroext 12346)
  %31 = getelementptr inbounds %struct.sockaddr_in, ptr %7, i32 0, i32 1
  store i16 %30, ptr %31, align 2, !tbaa !16
  br label %32

32:                                               ; preds = %50, %19
  br label %33

33:                                               ; preds = %32
  %34 = load i32, ptr %8, align 4, !tbaa !5
  %35 = load ptr, ptr %10, align 8, !tbaa !9
  %36 = load ptr, ptr %10, align 8, !tbaa !9
  %37 = call i64 @strlen(ptr noundef %36) #10
  %38 = call i64 @sendto(i32 noundef %34, ptr noundef %35, i64 noundef %37, i32 noundef 0, ptr noundef %6, i32 noundef 16)
  %39 = icmp slt i64 %38, 0
  br i1 %39, label %40, label %41

40:                                               ; preds = %33
  call void @perror(ptr noundef @.str.4)
  call void @exit(i32 noundef 1) #9
  unreachable

41:                                               ; preds = %33
  %42 = call i32 @sleep(i32 noundef 3)
  %43 = load i32, ptr %9, align 4, !tbaa !5
  %44 = load ptr, ptr %11, align 8, !tbaa !9
  %45 = load ptr, ptr %11, align 8, !tbaa !9
  %46 = call i64 @strlen(ptr noundef %45) #10
  %47 = call i64 @sendto(i32 noundef %43, ptr noundef %44, i64 noundef %46, i32 noundef 0, ptr noundef %7, i32 noundef 16)
  %48 = icmp slt i64 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %41
  call void @perror(ptr noundef @.str.5)
  call void @exit(i32 noundef 1) #9
  unreachable

50:                                               ; preds = %41
  %51 = call i32 @sleep(i32 noundef 3)
  br label %32
}

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

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) #2

declare void @perror(ptr noundef) #3

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

; Function Attrs: nounwind
declare i32 @inet_addr(ptr noundef) #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) #6

declare i64 @sendto(i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i32 noundef) #3

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #7

declare i32 @sleep(i32 noundef) #3

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 = { 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 #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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { inlinehint 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 #7 = { nounwind willreturn memory(read) "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 #8 = { nounwind }
attributes #9 = { noreturn nounwind }
attributes #10 = { nounwind willreturn memory(read) }

!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, !13, i64 0}
!12 = !{!"sockaddr_in", !13, i64 0, !13, i64 2, !14, i64 4, !7, i64 8}
!13 = !{!"short", !7, i64 0}
!14 = !{!"in_addr", !6, i64 0}
!15 = !{!12, !6, i64 4}
!16 = !{!12, !13, 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.sockaddr_in = type { i16, i16, %struct.in_addr, [8 x i8] }
%struct.in_addr = type { i32 }

@.str = external hidden unnamed_addr constant [14 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [13 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [11 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [8 x i8], align 1

; Function Attrs: noreturn nounwind uwtable
define dso_local noundef i32 @main(i32 noundef %0, ptr nocapture noundef readnone %1) local_unnamed_addr #0 {
  %3 = alloca %struct.sockaddr_in, align 4
  %4 = alloca %struct.sockaddr_in, align 4
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %3) #8
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %4) #8
  %5 = tail call i32 @socket(i32 noundef 2, i32 noundef 2, i32 noundef 0) #8
  %6 = icmp slt i32 %5, 0
  br i1 %6, label %7, label %8

7:                                                ; preds = %2
  tail call void @perror(ptr noundef nonnull @.str.2) #9
  tail call void @exit(i32 noundef 1) #10
  unreachable

8:                                                ; preds = %2
  %9 = tail call i32 @socket(i32 noundef 2, i32 noundef 2, i32 noundef 0) #8
  %10 = icmp slt i32 %9, 0
  br i1 %10, label %11, label %12

11:                                               ; preds = %8
  tail call void @perror(ptr noundef nonnull @.str.2) #9
  tail call void @exit(i32 noundef 1) #10
  unreachable

12:                                               ; preds = %8
  %13 = getelementptr inbounds i8, ptr %3, i64 8
  store i64 0, ptr %13, align 4
  store i16 2, ptr %3, align 4, !tbaa !5
  %14 = tail call i32 @inet_addr(ptr noundef nonnull @.str.3) #8
  %15 = getelementptr inbounds i8, ptr %3, i64 4
  store i32 %14, ptr %15, align 4, !tbaa !12
  %16 = tail call zeroext i16 @__bswap_16(i16 noundef zeroext 12345)
  %17 = getelementptr inbounds i8, ptr %3, i64 2
  store i16 %16, ptr %17, align 2, !tbaa !13
  %18 = getelementptr inbounds i8, ptr %4, i64 8
  store i64 0, ptr %18, align 4
  store i16 2, ptr %4, align 4, !tbaa !5
  %19 = tail call i32 @inet_addr(ptr noundef nonnull @.str.3) #8
  %20 = getelementptr inbounds i8, ptr %4, i64 4
  store i32 %19, ptr %20, align 4, !tbaa !12
  %21 = tail call zeroext i16 @__bswap_16(i16 noundef zeroext 12346)
  %22 = getelementptr inbounds i8, ptr %4, i64 2
  store i16 %21, ptr %22, align 2, !tbaa !13
  %23 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @.str) #11
  %24 = call i64 @sendto(i32 noundef %5, ptr noundef nonnull @.str, i64 noundef %23, i32 noundef 0, ptr noundef nonnull %3, i32 noundef 16) #8
  %25 = icmp slt i64 %24, 0
  br i1 %25, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %31, %12
  call void @perror(ptr noundef nonnull @.str.4) #9
  call void @exit(i32 noundef 1) #10
  unreachable

.lr.ph:                                           ; preds = %12, %31
  %26 = call i32 @sleep(i32 noundef 3) #8
  %27 = call i64 @strlen(ptr noundef nonnull dereferenceable(1) @.str.1) #11
  %28 = call i64 @sendto(i32 noundef %9, ptr noundef nonnull @.str.1, i64 noundef %27, i32 noundef 0, ptr noundef nonnull %4, i32 noundef 16) #8
  %29 = icmp slt i64 %28, 0
  br i1 %29, label %30, label %31

30:                                               ; preds = %.lr.ph
  call void @perror(ptr noundef nonnull @.str.5) #9
  call void @exit(i32 noundef 1) #10
  unreachable

31:                                               ; preds = %.lr.ph
  %32 = call i32 @sleep(i32 noundef 3) #8
  %33 = call i64 @sendto(i32 noundef %5, ptr noundef nonnull @.str, i64 noundef %23, i32 noundef 0, ptr noundef nonnull %3, i32 noundef 16) #8
  %34 = icmp slt i64 %33, 0
  br i1 %34, label %._crit_edge, label %.lr.ph
}

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

; Function Attrs: nounwind
declare i32 @socket(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #2

; Function Attrs: nofree nounwind
declare void @perror(ptr nocapture noundef readonly) local_unnamed_addr #3

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

; Function Attrs: nounwind
declare i32 @inet_addr(ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint nounwind uwtable
declare hidden zeroext i16 @__bswap_16(i16 noundef zeroext) local_unnamed_addr #5

declare i64 @sendto(i32 noundef, ptr noundef, i64 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #6

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #7

declare i32 @sleep(i32 noundef) local_unnamed_addr #6

attributes #0 = { noreturn 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #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 = { inlinehint 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 #6 = { "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 #7 = { mustprogress nofree nounwind willreturn memory(argmem: read) "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 #8 = { nounwind }
attributes #9 = { cold }
attributes #10 = { noreturn nounwind }
attributes #11 = { nounwind willreturn memory(read) }

!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 0}
!6 = !{!"sockaddr_in", !7, i64 0, !7, i64 2, !10, i64 4, !8, i64 8}
!7 = !{!"short", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"in_addr", !11, i64 0}
!11 = !{!"int", !8, i64 0}
!12 = !{!6, !11, i64 4}
!13 = !{!6, !7, i64 2}


; Effective O3 passes: DSEPass,EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass