; LLVM IR from mwarning/KadNode :: src/ext-libnss.ll (nss_kadnode_gethostbyname_impl)

; 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.kadnode_nss_request_t = type { i32, i8, [256 x i8] }
%struct.kadnode_nss_response_t = type { i32, [16 x %struct.query_address_result_t] }
%struct.query_address_result_t = type { i32, %union.anon, i32 }
%union.anon = type { %struct.ipv4_address_t, [12 x i8] }
%struct.ipv4_address_t = type { i32 }

; Function Attrs: nounwind uwtable
define dso_local i32 @_nss_kadnode_gethostbyname_impl(ptr noundef %0, i32 noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, i1 noundef zeroext %5) #0 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca i8, align 1
  %14 = alloca %struct.kadnode_nss_request_t, align 4
  %15 = alloca i8, align 1
  %16 = alloca i32, align 4
  store ptr %0, ptr %8, align 8, !tbaa !5
  store i32 %1, ptr %9, align 4, !tbaa !9
  store ptr %2, ptr %10, align 8, !tbaa !5
  store ptr %3, ptr %11, align 8, !tbaa !5
  store ptr %4, ptr %12, align 8, !tbaa !5
  %17 = zext i1 %5 to i8
  store i8 %17, ptr %13, align 1, !tbaa !11
  %18 = load i32, ptr %9, align 4, !tbaa !9
  %19 = icmp eq i32 %18, 0
  br i1 %19, label %26, label %20

20:                                               ; preds = %6
  %21 = load i32, ptr %9, align 4, !tbaa !9
  %22 = icmp eq i32 %21, 2
  br i1 %22, label %26, label %23

23:                                               ; preds = %20
  %24 = load i32, ptr %9, align 4, !tbaa !9
  %25 = icmp eq i32 %24, 10
  br i1 %25, label %26, label %64

26:                                               ; preds = %23, %20, %6
  call void @llvm.lifetime.start.p0(i64 264, ptr %14) #4
  call void @llvm.memset.p0.i64(ptr align 4 %14, i8 0, i64 264, i1 false)
  %27 = getelementptr inbounds %struct.kadnode_nss_request_t, ptr %14, i32 0, i32 0
  %28 = load i32, ptr %9, align 4, !tbaa !9
  store i32 %28, ptr %27, align 4, !tbaa !13
  %29 = getelementptr inbounds %struct.kadnode_nss_request_t, ptr %14, i32 0, i32 1
  %30 = load i8, ptr %13, align 1, !tbaa !11, !range !15, !noundef !16
  %31 = trunc i8 %30 to i1
  %32 = zext i1 %31 to i8
  store i8 %32, ptr %29, align 4, !tbaa !17
  %33 = getelementptr inbounds %struct.kadnode_nss_request_t, ptr %14, i32 0, i32 2
  %34 = getelementptr inbounds %struct.kadnode_nss_request_t, ptr %14, i32 0, i32 2
  %35 = getelementptr inbounds [256 x i8], ptr %34, i64 0, i64 0
  %36 = load ptr, ptr %8, align 8, !tbaa !5
  %37 = call ptr @strncpy(ptr noundef %35, ptr noundef %36, i64 noundef 256) #4
  call void @llvm.lifetime.start.p0(i64 1, ptr %15) #4
  %38 = load ptr, ptr %10, align 8, !tbaa !5
  %39 = call zeroext i1 @_nss_kadnode_lookup(ptr noundef %38, ptr noundef %14)
  %40 = zext i1 %39 to i8
  store i8 %40, ptr %15, align 1, !tbaa !11
  %41 = load i8, ptr %15, align 1, !tbaa !11, !range !15, !noundef !16
  %42 = trunc i8 %41 to i1
  br i1 %42, label %43, label %60

43:                                               ; preds = %26
  %44 = load ptr, ptr %10, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.kadnode_nss_response_t, ptr %44, i32 0, i32 0
  %46 = load i32, ptr %45, align 4, !tbaa !18
  %47 = icmp eq i32 %46, 0
  br i1 %47, label %48, label %51

48:                                               ; preds = %43
  %49 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 110, ptr %49, align 4, !tbaa !9
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 2, ptr %50, align 4, !tbaa !9
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %63

51:                                               ; preds = %43
  %52 = load ptr, ptr %10, align 8, !tbaa !5
  %53 = getelementptr inbounds %struct.kadnode_nss_response_t, ptr %52, i32 0, i32 0
  %54 = load i32, ptr %53, align 4, !tbaa !18
  %55 = icmp sgt i32 %54, 0
  br i1 %55, label %56, label %57

56:                                               ; preds = %51
  store i32 1, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %63

57:                                               ; preds = %51
  %58 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 110, ptr %58, align 4, !tbaa !9
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 1, ptr %59, align 4, !tbaa !9
  store i32 0, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %63

60:                                               ; preds = %26
  %61 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 110, ptr %61, align 4, !tbaa !9
  %62 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 3, ptr %62, align 4, !tbaa !9
  store i32 -1, ptr %7, align 4
  store i32 1, ptr %16, align 4
  br label %63

63:                                               ; preds = %60, %57, %56, %48
  call void @llvm.lifetime.end.p0(i64 1, ptr %15) #4
  call void @llvm.lifetime.end.p0(i64 264, ptr %14) #4
  br label %67

64:                                               ; preds = %23
  %65 = load ptr, ptr %11, align 8, !tbaa !5
  store i32 110, ptr %65, align 4, !tbaa !9
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 3, ptr %66, align 4, !tbaa !9
  store i32 -1, ptr %7, align 4
  br label %67

67:                                               ; preds = %64, %63
  %68 = load i32, ptr %7, align 4
  ret i32 %68
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

; Function Attrs: nounwind
declare ptr @strncpy(ptr noundef, ptr noundef, i64 noundef) #3

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @_nss_kadnode_lookup(ptr noundef, ptr noundef) #0

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

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 nounwind willreturn memory(argmem: write) }
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 = { 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, !12, i64 0}
!12 = !{!"_Bool", !7, i64 0}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !12, i64 4, !7, i64 5}
!15 = !{i8 0, i8 2}
!16 = !{}
!17 = !{!14, !12, i64 4}
!18 = !{!19, !10, i64 0}
!19 = !{!"", !10, i64 0, !7, 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.kadnode_nss_request_t = type { i32, i8, [256 x i8] }

; Function Attrs: nounwind uwtable
define dso_local range(i32 -1, 2) i32 @_nss_kadnode_gethostbyname_impl(ptr nocapture noundef readonly %0, i32 noundef %1, ptr noundef %2, ptr nocapture noundef writeonly %3, ptr nocapture noundef writeonly %4, i1 noundef zeroext %5) local_unnamed_addr #0 {
  %7 = alloca %struct.kadnode_nss_request_t, align 4
  switch i32 %1, label %21 [
    i32 10, label %8
    i32 2, label %8
    i32 0, label %8
  ]

8:                                                ; preds = %6, %6, %6
  %9 = zext i1 %5 to i8
  call void @llvm.lifetime.start.p0(i64 264, ptr nonnull %7) #3
  %10 = getelementptr inbounds i8, ptr %7, i64 260
  store i32 0, ptr %10, align 4
  store i32 %1, ptr %7, align 4, !tbaa !5
  %11 = getelementptr inbounds i8, ptr %7, i64 4
  store i8 %9, ptr %11, align 4, !tbaa !11
  %12 = getelementptr inbounds i8, ptr %7, i64 5
  %13 = call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %12, ptr noundef nonnull dereferenceable(1) %0, i64 noundef 256) #3
  %14 = call zeroext i1 @_nss_kadnode_lookup(ptr noundef %2, ptr noundef nonnull %7)
  br i1 %14, label %15, label %.sink.split

15:                                               ; preds = %8
  %16 = load i32, ptr %2, align 4, !tbaa !12
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %.sink.split, label %18

18:                                               ; preds = %15
  %19 = icmp sgt i32 %16, 0
  br i1 %19, label %20, label %.sink.split

.sink.split:                                      ; preds = %8, %18, %15
  %.sink = phi i32 [ 2, %15 ], [ 1, %18 ], [ 3, %8 ]
  %.0.ph = phi i32 [ -1, %15 ], [ 0, %18 ], [ -1, %8 ]
  store i32 110, ptr %3, align 4, !tbaa !14
  store i32 %.sink, ptr %4, align 4, !tbaa !14
  br label %20

20:                                               ; preds = %.sink.split, %18
  %.0 = phi i32 [ 1, %18 ], [ %.0.ph, %.sink.split ]
  call void @llvm.lifetime.end.p0(i64 264, ptr nonnull %7) #3
  br label %22

21:                                               ; preds = %6
  store i32 110, ptr %3, align 4, !tbaa !14
  store i32 3, ptr %4, align 4, !tbaa !14
  br label %22

22:                                               ; preds = %21, %20
  %.1 = phi i32 [ %.0, %20 ], [ -1, %21 ]
  ret i32 %.1
}

; 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 nofree nounwind willreturn memory(argmem: readwrite)
declare ptr @strncpy(ptr noalias noundef returned writeonly, ptr noalias nocapture noundef readonly, i64 noundef) local_unnamed_addr #2

; Function Attrs: nounwind uwtable
declare hidden zeroext i1 @_nss_kadnode_lookup(ptr noundef, ptr noundef) local_unnamed_addr #0

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

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


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