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

@.str.3 = external hidden unnamed_addr constant [1 x i8], align 1
@__const.ach_srv_search.srv_type = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [21 x i8], align 1

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

declare void @ach_set_errstr(ptr noundef) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

; Function Attrs: nounwind uwtable
define dso_local i32 @ach_srv_search(ptr noundef %0, ptr noundef %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) #0 {
  %6 = alloca i32, align 4
  %7 = alloca ptr, align 8
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca ptr, align 8
  %12 = alloca [12 x i8], align 1
  %13 = alloca ptr, align 8
  %14 = alloca i64, align 8
  %15 = alloca [4096 x i8], align 16
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  store ptr %0, ptr %7, align 8, !tbaa !5
  store ptr %1, ptr %8, align 8, !tbaa !5
  store ptr %2, ptr %9, align 8, !tbaa !5
  store i64 %3, ptr %10, align 8, !tbaa !9
  store ptr %4, ptr %11, align 8, !tbaa !5
  call void @ach_set_errstr(ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 12, ptr %12) #8
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %12, ptr align 1 @__const.ach_srv_search.srv_type, i64 12, i1 false)
  %18 = load ptr, ptr %7, align 8, !tbaa !5
  %19 = call i64 @strlen(ptr noundef %18) #9
  %20 = add i64 %19, 11
  %21 = load ptr, ptr %8, align 8, !tbaa !5
  %22 = call i64 @strlen(ptr noundef %21) #9
  %23 = add i64 %20, %22
  %24 = add i64 %23, 1
  %25 = call ptr @llvm.stacksave.p0()
  store ptr %25, ptr %13, align 8
  %26 = alloca i8, i64 %24, align 16
  store i64 %24, ptr %14, align 8
  %27 = getelementptr inbounds i8, ptr %26, i64 0
  store i8 0, ptr %27, align 16, !tbaa !11
  %28 = load ptr, ptr %7, align 8, !tbaa !5
  %29 = call ptr @strcat(ptr noundef %26, ptr noundef %28) #8
  %30 = getelementptr inbounds [12 x i8], ptr %12, i64 0, i64 0
  %31 = call ptr @strcat(ptr noundef %26, ptr noundef %30) #8
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = call ptr @strcat(ptr noundef %26, ptr noundef %32) #8
  call void @llvm.lifetime.start.p0(i64 4096, ptr %15) #8
  call void @llvm.memset.p0.i64(ptr align 16 %15, i8 0, i64 4096, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #8
  %34 = load ptr, ptr %8, align 8, !tbaa !5
  %35 = call i32 @strcasecmp(ptr noundef @.str.4, ptr noundef %34) #9
  %36 = icmp eq i32 0, %35
  br i1 %36, label %37, label %44

37:                                               ; preds = %5
  %38 = getelementptr inbounds [4096 x i8], ptr %15, i64 0, i64 0
  %39 = call i32 @mdns_res_search(ptr noundef %26, i32 noundef 1, i32 noundef 33, ptr noundef %38, i32 noundef 4096)
  store i32 %39, ptr %16, align 4, !tbaa !12
  %40 = load i32, ptr %16, align 4, !tbaa !12
  %41 = icmp slt i32 %40, 0
  br i1 %41, label %42, label %43

42:                                               ; preds = %37
  call void @ach_set_errstr(ptr noundef @.str.5)
  store i32 4, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %59

43:                                               ; preds = %37
  br label %51

44:                                               ; preds = %5
  %45 = getelementptr inbounds [4096 x i8], ptr %15, i64 0, i64 0
  %46 = call i32 @res_search(ptr noundef %26, i32 noundef 1, i32 noundef 33, ptr noundef %45, i32 noundef 4096) #8
  store i32 %46, ptr %16, align 4, !tbaa !12
  %47 = load i32, ptr %16, align 4, !tbaa !12
  %48 = icmp slt i32 %47, 0
  br i1 %48, label %49, label %50

49:                                               ; preds = %44
  call void @ach_set_errstr(ptr noundef @.str.6)
  store i32 4, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %59

50:                                               ; preds = %44
  br label %51

51:                                               ; preds = %50, %43
  %52 = getelementptr inbounds [4096 x i8], ptr %15, i64 0, i64 0
  %53 = load i32, ptr %16, align 4, !tbaa !12
  %54 = sext i32 %53 to i64
  %55 = load ptr, ptr %9, align 8, !tbaa !5
  %56 = load i64, ptr %10, align 8, !tbaa !9
  %57 = load ptr, ptr %11, align 8, !tbaa !5
  %58 = call i32 @parse_dns_srv(ptr noundef %52, i64 noundef %54, ptr noundef %55, i64 noundef %56, ptr noundef %57)
  store i32 %58, ptr %6, align 4
  store i32 1, ptr %17, align 4
  br label %59

59:                                               ; preds = %51, %49, %42
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #8
  call void @llvm.lifetime.end.p0(i64 4096, ptr %15) #8
  %60 = load ptr, ptr %13, align 8
  call void @llvm.stackrestore.p0(ptr %60)
  call void @llvm.lifetime.end.p0(i64 12, ptr %12) #8
  %61 = load i32, ptr %6, align 4
  ret i32 %61
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #4

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

; Function Attrs: nounwind
declare ptr @strcat(ptr noundef, ptr noundef) #6

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

; Function Attrs: nounwind willreturn memory(read)
declare i32 @strcasecmp(ptr noundef, ptr noundef) #5

; Function Attrs: nounwind uwtable
declare dso_local i32 @mdns_res_search(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) #0

; Function Attrs: nounwind
declare i32 @res_search(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) #6

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 = { nocallback nofree nosync nounwind willreturn }
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 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { 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 #7 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #8 = { nounwind }
attributes #9 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = !{!13, !13, i64 0}
!13 = !{!"int", !7, i64 0}


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

@.str.3 = external hidden unnamed_addr constant [1 x i8], align 1
@__const.ach_srv_search.srv_type = external hidden unnamed_addr constant [12 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [6 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [20 x i8], align 1
@.str.6 = external hidden unnamed_addr constant [21 x i8], align 1

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

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

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

declare void @ach_set_errstr(ptr noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
define dso_local i32 @ach_srv_search(ptr nocapture noundef readonly %0, ptr nocapture noundef readonly %1, ptr noundef %2, i64 noundef %3, ptr noundef %4) local_unnamed_addr #0 {
  %6 = alloca [4096 x i8], align 16
  tail call void @ach_set_errstr(ptr noundef nonnull @.str.3) #8
  %7 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %0) #9
  %8 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) %1) #9
  %9 = add i64 %7, 12
  %10 = add i64 %9, %8
  %11 = alloca i8, i64 %10, align 16
  store i8 0, ptr %11, align 16, !tbaa !5
  %12 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %11, ptr noundef nonnull dereferenceable(1) %0) #8
  %13 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %11, ptr noundef nonnull dereferenceable(1) @__const.ach_srv_search.srv_type) #8
  %14 = call ptr @strcat(ptr noundef nonnull dereferenceable(1) %11, ptr noundef nonnull dereferenceable(1) %1) #8
  call void @llvm.lifetime.start.p0(i64 4096, ptr nonnull %6) #8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(4096) %6, i8 0, i64 4096, i1 false)
  %15 = call i32 @strcasecmp(ptr noundef nonnull @.str.4, ptr noundef %1) #9
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %21

17:                                               ; preds = %5
  %18 = call i32 @mdns_res_search(ptr noundef nonnull %11, i32 noundef 1, i32 noundef 33, ptr noundef nonnull %6, i32 noundef 4096)
  %19 = icmp slt i32 %18, 0
  br i1 %19, label %20, label %25

20:                                               ; preds = %17
  call void @ach_set_errstr(ptr noundef nonnull @.str.5) #8
  br label %28

21:                                               ; preds = %5
  %22 = call i32 @res_search(ptr noundef nonnull %11, i32 noundef 1, i32 noundef 33, ptr noundef nonnull %6, i32 noundef 4096) #8
  %23 = icmp slt i32 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %21
  call void @ach_set_errstr(ptr noundef nonnull @.str.6) #8
  br label %28

25:                                               ; preds = %21, %17
  %.0 = phi i32 [ %18, %17 ], [ %22, %21 ]
  %26 = zext nneg i32 %.0 to i64
  %27 = call i32 @parse_dns_srv(ptr noundef nonnull %6, i64 noundef %26, ptr noundef %2, i64 noundef %3, ptr noundef %4)
  br label %28

28:                                               ; preds = %25, %24, %20
  %.012 = phi i32 [ 4, %20 ], [ %27, %25 ], [ 4, %24 ]
  call void @llvm.lifetime.end.p0(i64 4096, ptr nonnull %6) #8
  ret i32 %.012
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strcat(ptr noalias noundef returned, ptr noalias nocapture noundef readonly) local_unnamed_addr #4

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(read)
declare i32 @strcasecmp(ptr nocapture noundef, ptr nocapture noundef) local_unnamed_addr #6

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

; Function Attrs: nounwind
declare i32 @res_search(ptr noundef, i32 noundef, i32 noundef, ptr noundef, i32 noundef) local_unnamed_addr #7

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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { 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 #4 = { mustprogress nofree nounwind willreturn memory(argmem: readwrite) "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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { mustprogress nofree 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 #7 = { 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 #8 = { nounwind }
attributes #9 = { 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 = !{!"omnipotent char", !7, i64 0}
!7 = !{!"Simple C/C++ TBAA"}


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