; LLVM IR from golems/ach :: src (dns)

; 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.7 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [12 x i8], align 1

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @mdns_res_search(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) #3 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca [4096 x i8], align 16
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca %struct.sockaddr_in, align 4
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca %struct.sockaddr_in, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store i32 %1, ptr %8, align 4, !tbaa !9
  store i32 %2, ptr %9, align 4, !tbaa !9
  store ptr %3, ptr %10, align 8, !tbaa !5
  store i32 %4, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4096, ptr %12) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  %20 = load ptr, ptr %7, align 8, !tbaa !5
  %21 = load i32, ptr %8, align 4, !tbaa !9
  %22 = load i32, ptr %9, align 4, !tbaa !9
  %23 = getelementptr inbounds [4096 x i8], ptr %12, i64 0, i64 0
  %24 = call i32 @res_mkquery(i32 noundef 0, ptr noundef %20, i32 noundef %21, i32 noundef %22, ptr noundef null, i32 noundef 0, ptr noundef null, ptr noundef %23, i32 noundef 4096) #6
  store i32 %24, ptr %13, align 4, !tbaa !9
  %25 = load i32, ptr %13, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 0
  br i1 %26, label %27, label %28

27:                                               ; preds = %5
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %73

28:                                               ; preds = %5
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  %29 = call i32 @socket(i32 noundef 2, i32 noundef 2, i32 noundef 0) #6
  store i32 %29, ptr %15, align 4, !tbaa !9
  %30 = load i32, ptr %15, align 4, !tbaa !9
  %31 = icmp slt i32 %30, 0
  br i1 %31, label %32, label %33

32:                                               ; preds = %28
  call void @perror(ptr noundef @.str.7)
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %72

33:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 16, ptr %16) #6
  call void @llvm.memset.p0.i64(ptr align 4 %16, i8 0, i64 16, i1 false)
  %34 = getelementptr inbounds %struct.sockaddr_in, ptr %16, i32 0, i32 0
  store i16 2, ptr %34, align 4, !tbaa !11
  %35 = call zeroext i16 @__bswap_16(i16 noundef zeroext 0)
  %36 = getelementptr inbounds %struct.sockaddr_in, ptr %16, i32 0, i32 1
  store i16 %35, ptr %36, align 2, !tbaa !15
  %37 = getelementptr inbounds %struct.sockaddr_in, ptr %16, i32 0, i32 2
  %38 = getelementptr inbounds %struct.in_addr, ptr %37, i32 0, i32 0
  store i32 0, ptr %38, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #6
  store i32 1, ptr %17, align 4, !tbaa !9
  %39 = load i32, ptr %15, align 4, !tbaa !9
  %40 = call i32 @setsockopt(i32 noundef %39, i32 noundef 0, i32 noundef 34, ptr noundef %17, i32 noundef 4) #6
  %41 = icmp ne i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %33
  call void @perror(ptr noundef @.str.8)
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %71

43:                                               ; preds = %33
  %44 = load i32, ptr %15, align 4, !tbaa !9
  %45 = call i32 @setsockopt(i32 noundef %44, i32 noundef 1, i32 noundef 2, ptr noundef %17, i32 noundef 4) #6
  %46 = icmp ne i32 %45, 0
  br i1 %46, label %47, label %48

47:                                               ; preds = %43
  call void @perror(ptr noundef @.str.9)
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %71

48:                                               ; preds = %43
  %49 = load i32, ptr %15, align 4, !tbaa !9
  %50 = call i32 @bind(i32 noundef %49, ptr noundef %16, i32 noundef 16) #6
  %51 = icmp slt i32 %50, 0
  br i1 %51, label %52, label %53

52:                                               ; preds = %48
  call void @perror(ptr noundef @.str.10)
  store i32 -1, ptr %6, align 4
  store i32 1, ptr %14, align 4
  br label %71

53:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #6
  call void @llvm.lifetime.start.p0(i64 16, ptr %19) #6
  call void @llvm.memset.p0.i64(ptr align 4 %19, i8 0, i64 16, i1 false)
  %54 = call zeroext i16 @__bswap_16(i16 noundef zeroext 5353)
  %55 = getelementptr inbounds %struct.sockaddr_in, ptr %19, i32 0, i32 1
  store i16 %54, ptr %55, align 2, !tbaa !15
  %56 = getelementptr inbounds %struct.sockaddr_in, ptr %19, i32 0, i32 0
  store i16 2, ptr %56, align 4, !tbaa !11
  %57 = call i32 @inet_addr(ptr noundef @.str.11) #6
  %58 = getelementptr inbounds %struct.sockaddr_in, ptr %19, i32 0, i32 2
  %59 = getelementptr inbounds %struct.in_addr, ptr %58, i32 0, i32 0
  store i32 %57, ptr %59, align 4, !tbaa !16
  %60 = load i32, ptr %15, align 4, !tbaa !9
  %61 = getelementptr inbounds [4096 x i8], ptr %12, i64 0, i64 0
  %62 = load i32, ptr %13, align 4, !tbaa !9
  %63 = sext i32 %62 to i64
  %64 = load ptr, ptr %10, align 8, !tbaa !5
  %65 = load i32, ptr %11, align 4, !tbaa !9
  %66 = sext i32 %65 to i64
  %67 = call i32 @dns_query(i32 noundef %60, ptr noundef %19, i64 noundef 16, ptr noundef %61, i64 noundef %63, ptr noundef %64, i64 noundef %66)
  store i32 %67, ptr %18, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 16, ptr %19) #6
  %68 = load i32, ptr %15, align 4, !tbaa !9
  %69 = call i32 @close(i32 noundef %68)
  %70 = load i32, ptr %18, align 4, !tbaa !9
  store i32 %70, ptr %6, align 4
  store i32 1, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #6
  br label %71

71:                                               ; preds = %53, %52, %47, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr %16) #6
  br label %72

72:                                               ; preds = %71, %32
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  br label %73

73:                                               ; preds = %72, %27
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4096, ptr %12) #6
  %74 = load i32, ptr %6, align 4
  ret i32 %74
}

; Function Attrs: nounwind
declare i32 @res_mkquery(i32 noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef) #4

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

declare void @perror(ptr noundef) #5

; Function Attrs: nounwind
declare i32 @setsockopt(i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) #4

; Function Attrs: nounwind
declare i32 @bind(i32 noundef, ptr noundef, i32 noundef) #4

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @dns_query(i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) #3

declare i32 @close(i32 noundef) #5

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #3 = { 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 #4 = { 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 = { "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 = { 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, !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", !10, i64 0}
!15 = !{!12, !13, i64 2}
!16 = !{!12, !10, i64 4}


; 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.7 = external hidden unnamed_addr constant [24 x i8], align 1
@.str.8 = external hidden unnamed_addr constant [30 x i8], align 1
@.str.9 = external hidden unnamed_addr constant [32 x i8], align 1
@.str.10 = external hidden unnamed_addr constant [26 x i8], align 1
@.str.11 = external hidden unnamed_addr constant [12 x i8], align 1

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

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

; 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
define dso_local i32 @mdns_res_search(ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef %3, i32 noundef %4) local_unnamed_addr #2 {
  %6 = alloca [4096 x i8], align 16
  %7 = alloca %struct.sockaddr_in, align 4
  %8 = alloca i32, align 4
  %9 = alloca %struct.sockaddr_in, align 4
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %6) #6
  %10 = call i32 @res_mkquery(i32 noundef 0, ptr noundef %0, i32 noundef %1, i32 noundef %2, ptr noundef null, i32 noundef 0, ptr noundef null, ptr noundef nonnull %6, i32 noundef 4096) #6
  %11 = icmp slt i32 %10, 0
  br i1 %11, label %41, label %12

12:                                               ; preds = %5
  %13 = call i32 @socket(i32 noundef 2, i32 noundef 2, i32 noundef 0) #6
  %14 = icmp slt i32 %13, 0
  br i1 %14, label %15, label %16

15:                                               ; preds = %12
  call void @perror(ptr noundef nonnull @.str.7) #7
  br label %41

16:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %7) #6
  %17 = getelementptr inbounds i8, ptr %7, i64 8
  store i64 0, ptr %17, align 4
  store i16 2, ptr %7, align 4, !tbaa !5
  %18 = call zeroext i16 @__bswap_16(i16 noundef zeroext 0)
  %19 = getelementptr inbounds i8, ptr %7, i64 2
  store i16 %18, ptr %19, align 2, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %7, i64 4
  store i32 0, ptr %20, align 4, !tbaa !13
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #6
  store i32 1, ptr %8, align 4, !tbaa !14
  %21 = call i32 @setsockopt(i32 noundef %13, i32 noundef 0, i32 noundef 34, ptr noundef nonnull %8, i32 noundef 4) #6
  %.not = icmp eq i32 %21, 0
  br i1 %.not, label %23, label %22

22:                                               ; preds = %16
  call void @perror(ptr noundef nonnull @.str.8) #7
  br label %40

23:                                               ; preds = %16
  %24 = call i32 @setsockopt(i32 noundef %13, i32 noundef 1, i32 noundef 2, ptr noundef nonnull %8, i32 noundef 4) #6
  %.not16 = icmp eq i32 %24, 0
  br i1 %.not16, label %26, label %25

25:                                               ; preds = %23
  call void @perror(ptr noundef nonnull @.str.9) #7
  br label %40

26:                                               ; preds = %23
  %27 = call i32 @bind(i32 noundef %13, ptr noundef nonnull %7, i32 noundef 16) #6
  %28 = icmp slt i32 %27, 0
  br i1 %28, label %29, label %30

29:                                               ; preds = %26
  call void @perror(ptr noundef nonnull @.str.10) #7
  br label %40

30:                                               ; preds = %26
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %9) #6
  %31 = getelementptr inbounds i8, ptr %9, i64 8
  store i64 0, ptr %31, align 4
  %32 = call zeroext i16 @__bswap_16(i16 noundef zeroext 5353)
  %33 = getelementptr inbounds i8, ptr %9, i64 2
  store i16 %32, ptr %33, align 2, !tbaa !12
  store i16 2, ptr %9, align 4, !tbaa !5
  %34 = call i32 @inet_addr(ptr noundef nonnull @.str.11) #6
  %35 = getelementptr inbounds i8, ptr %9, i64 4
  store i32 %34, ptr %35, align 4, !tbaa !13
  %36 = zext nneg i32 %10 to i64
  %37 = sext i32 %4 to i64
  %38 = call i32 @dns_query(i32 noundef %13, ptr noundef nonnull %9, i64 noundef 16, ptr noundef nonnull %6, i64 noundef %36, ptr noundef %3, i64 noundef %37)
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %9) #6
  %39 = call i32 @close(i32 noundef %13) #6
  br label %40

40:                                               ; preds = %30, %29, %25, %22
  %.0 = phi i32 [ -1, %22 ], [ -1, %25 ], [ -1, %29 ], [ %38, %30 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #6
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %7) #6
  br label %41

41:                                               ; preds = %15, %40, %5
  %.2 = phi i32 [ -1, %5 ], [ -1, %15 ], [ %.0, %40 ]
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %6) #6
  ret i32 %.2
}

; Function Attrs: nounwind
declare i32 @res_mkquery(i32 noundef, ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef, ptr noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

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

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

; Function Attrs: nounwind
declare i32 @setsockopt(i32 noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

; Function Attrs: nounwind
declare i32 @bind(i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #3

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

; Function Attrs: nounwind uwtable
declare dso_local i32 @dns_query(i32 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef, ptr noundef, i64 noundef) local_unnamed_addr #2

declare i32 @close(i32 noundef) local_unnamed_addr #5

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

!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, !7, i64 2}
!13 = !{!6, !11, i64 4}
!14 = !{!11, !11, i64 0}


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