; LLVM IR from mwarning/KadNode :: src (ext-libnss-utils)

; 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.hostent = type { ptr, ptr, i32, i32, ptr }
%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 @convert_userdata_for_name_to_hostent(ptr noundef %0, ptr noundef %1, i32 noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5, ptr noundef %6) #0 {
  %8 = alloca i32, align 4
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca ptr, align 8
  %16 = alloca i64, align 8
  %17 = alloca i32, align 4
  %18 = alloca i32, align 4
  %19 = alloca ptr, align 8
  store ptr %0, ptr %9, align 8, !tbaa !5
  store ptr %1, ptr %10, align 8, !tbaa !5
  store i32 %2, ptr %11, align 4, !tbaa !9
  store ptr %3, ptr %12, align 8, !tbaa !5
  store ptr %4, ptr %13, align 8, !tbaa !5
  store ptr %5, ptr %14, align 8, !tbaa !5
  store ptr %6, ptr %15, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #3
  %20 = load i32, ptr %11, align 4, !tbaa !9
  %21 = icmp eq i32 %20, 2
  %22 = zext i1 %21 to i64
  %23 = select i1 %21, i64 4, i64 16
  store i64 %23, ptr %16, align 8, !tbaa !11
  %24 = load ptr, ptr %13, align 8, !tbaa !5
  %25 = call ptr @buffer_alloc(ptr noundef %24, i64 noundef 8)
  %26 = load ptr, ptr %12, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.hostent, ptr %26, i32 0, i32 1
  store ptr %25, ptr %27, align 8, !tbaa !13
  %28 = load ptr, ptr %12, align 8, !tbaa !5
  %29 = getelementptr inbounds %struct.hostent, ptr %28, i32 0, i32 1
  %30 = load ptr, ptr %29, align 8, !tbaa !13
  %31 = icmp eq ptr %30, null
  br i1 %31, label %32, label %35

32:                                               ; preds = %7
  %33 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 34, ptr %33, align 4, !tbaa !9
  %34 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 3, ptr %34, align 4, !tbaa !9
  store i32 -2, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %115

35:                                               ; preds = %7
  %36 = load ptr, ptr %13, align 8, !tbaa !5
  %37 = load ptr, ptr %10, align 8, !tbaa !5
  %38 = call ptr @buffer_strdup(ptr noundef %36, ptr noundef %37)
  %39 = load ptr, ptr %12, align 8, !tbaa !5
  %40 = getelementptr inbounds %struct.hostent, ptr %39, i32 0, i32 0
  store ptr %38, ptr %40, align 8, !tbaa !15
  %41 = load ptr, ptr %12, align 8, !tbaa !5
  %42 = getelementptr inbounds %struct.hostent, ptr %41, i32 0, i32 0
  %43 = load ptr, ptr %42, align 8, !tbaa !15
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %48

45:                                               ; preds = %35
  %46 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 34, ptr %46, align 4, !tbaa !9
  %47 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 3, ptr %47, align 4, !tbaa !9
  store i32 -2, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %115

48:                                               ; preds = %35
  %49 = load i32, ptr %11, align 4, !tbaa !9
  %50 = load ptr, ptr %12, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.hostent, ptr %50, i32 0, i32 2
  store i32 %49, ptr %51, align 8, !tbaa !16
  %52 = load i64, ptr %16, align 8, !tbaa !11
  %53 = trunc i64 %52 to i32
  %54 = load ptr, ptr %12, align 8, !tbaa !5
  %55 = getelementptr inbounds %struct.hostent, ptr %54, i32 0, i32 3
  store i32 %53, ptr %55, align 4, !tbaa !17
  %56 = load ptr, ptr %13, align 8, !tbaa !5
  %57 = load ptr, ptr %9, align 8, !tbaa !5
  %58 = getelementptr inbounds %struct.kadnode_nss_response_t, ptr %57, i32 0, i32 0
  %59 = load i32, ptr %58, align 4, !tbaa !18
  %60 = add nsw i32 %59, 1
  %61 = sext i32 %60 to i64
  %62 = mul i64 %61, 8
  %63 = call ptr @buffer_alloc(ptr noundef %56, i64 noundef %62)
  %64 = load ptr, ptr %12, align 8, !tbaa !5
  %65 = getelementptr inbounds %struct.hostent, ptr %64, i32 0, i32 4
  store ptr %63, ptr %65, align 8, !tbaa !20
  %66 = load ptr, ptr %12, align 8, !tbaa !5
  %67 = getelementptr inbounds %struct.hostent, ptr %66, i32 0, i32 4
  %68 = load ptr, ptr %67, align 8, !tbaa !20
  %69 = icmp eq ptr %68, null
  br i1 %69, label %70, label %73

70:                                               ; preds = %48
  %71 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 34, ptr %71, align 4, !tbaa !9
  %72 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 3, ptr %72, align 4, !tbaa !9
  store i32 -2, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %115

73:                                               ; preds = %48
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #3
  store i32 0, ptr %18, align 4, !tbaa !9
  br label %74

74:                                               ; preds = %109, %73
  %75 = load i32, ptr %18, align 4, !tbaa !9
  %76 = load ptr, ptr %9, align 8, !tbaa !5
  %77 = getelementptr inbounds %struct.kadnode_nss_response_t, ptr %76, i32 0, i32 0
  %78 = load i32, ptr %77, align 4, !tbaa !18
  %79 = icmp slt i32 %75, %78
  br i1 %79, label %81, label %80

80:                                               ; preds = %74
  store i32 2, ptr %17, align 4
  br label %112

81:                                               ; preds = %74
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #3
  %82 = load ptr, ptr %13, align 8, !tbaa !5
  %83 = load i64, ptr %16, align 8, !tbaa !11
  %84 = call ptr @buffer_alloc(ptr noundef %82, i64 noundef %83)
  store ptr %84, ptr %19, align 8, !tbaa !5
  %85 = load ptr, ptr %19, align 8, !tbaa !5
  %86 = icmp eq ptr %85, null
  br i1 %86, label %87, label %90

87:                                               ; preds = %81
  %88 = load ptr, ptr %14, align 8, !tbaa !5
  store i32 34, ptr %88, align 4, !tbaa !9
  %89 = load ptr, ptr %15, align 8, !tbaa !5
  store i32 3, ptr %89, align 4, !tbaa !9
  store i32 -2, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %106

90:                                               ; preds = %81
  %91 = load ptr, ptr %19, align 8, !tbaa !5
  %92 = load ptr, ptr %9, align 8, !tbaa !5
  %93 = getelementptr inbounds %struct.kadnode_nss_response_t, ptr %92, i32 0, i32 1
  %94 = load i32, ptr %18, align 4, !tbaa !9
  %95 = sext i32 %94 to i64
  %96 = getelementptr inbounds [16 x %struct.query_address_result_t], ptr %93, i64 0, i64 %95
  %97 = getelementptr inbounds %struct.query_address_result_t, ptr %96, i32 0, i32 1
  %98 = load i64, ptr %16, align 8, !tbaa !11
  call void @llvm.memcpy.p0.p0.i64(ptr align 1 %91, ptr align 4 %97, i64 %98, i1 false)
  %99 = load ptr, ptr %19, align 8, !tbaa !5
  %100 = load ptr, ptr %12, align 8, !tbaa !5
  %101 = getelementptr inbounds %struct.hostent, ptr %100, i32 0, i32 4
  %102 = load ptr, ptr %101, align 8, !tbaa !20
  %103 = load i32, ptr %18, align 4, !tbaa !9
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds ptr, ptr %102, i64 %104
  store ptr %99, ptr %105, align 8, !tbaa !5
  store i32 0, ptr %17, align 4
  br label %106

106:                                              ; preds = %90, %87
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #3
  %107 = load i32, ptr %17, align 4
  switch i32 %107, label %112 [
    i32 0, label %108
  ]

108:                                              ; preds = %106
  br label %109

109:                                              ; preds = %108
  %110 = load i32, ptr %18, align 4, !tbaa !9
  %111 = add nsw i32 %110, 1
  store i32 %111, ptr %18, align 4, !tbaa !9
  br label %74, !llvm.loop !21

112:                                              ; preds = %106, %80
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #3
  %113 = load i32, ptr %17, align 4
  switch i32 %113, label %115 [
    i32 2, label %114
  ]

114:                                              ; preds = %112
  store i32 1, ptr %8, align 4
  store i32 1, ptr %17, align 4
  br label %115

115:                                              ; preds = %114, %112, %70, %45, %32
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #3
  %116 = load i32, ptr %8, align 4
  ret i32 %116
}

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

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

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

; 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) #2

; 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: readwrite) }
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 = !{!"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 = !{!"long", !7, i64 0}
!13 = !{!14, !6, i64 8}
!14 = !{!"hostent", !6, i64 0, !6, i64 8, !10, i64 16, !10, i64 20, !6, i64 24}
!15 = !{!14, !6, i64 0}
!16 = !{!14, !10, i64 16}
!17 = !{!14, !10, i64 20}
!18 = !{!19, !10, i64 0}
!19 = !{!"", !10, i64 0, !7, i64 4}
!20 = !{!14, !6, i64 24}
!21 = distinct !{!21, !22}
!22 = !{!"llvm.loop.mustprogress"}


; 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.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 noundef i32 @convert_userdata_for_name_to_hostent(ptr nocapture noundef readonly %0, ptr noundef %1, i32 noundef %2, ptr nocapture noundef %3, ptr noundef %4, ptr nocapture noundef writeonly %5, ptr nocapture noundef writeonly %6) local_unnamed_addr #0 {
  %8 = icmp eq i32 %2, 2
  %9 = select i1 %8, i64 4, i64 16
  %10 = tail call ptr @buffer_alloc(ptr noundef %4, i64 noundef 8)
  %11 = getelementptr inbounds i8, ptr %3, i64 8
  store ptr %10, ptr %11, align 8, !tbaa !5
  %12 = icmp eq ptr %10, null
  br i1 %12, label %.loopexit.sink.split, label %13

13:                                               ; preds = %7
  %14 = tail call ptr @buffer_strdup(ptr noundef %4, ptr noundef %1)
  store ptr %14, ptr %3, align 8, !tbaa !11
  %15 = icmp eq ptr %14, null
  br i1 %15, label %.loopexit.sink.split, label %16

16:                                               ; preds = %13
  %17 = getelementptr inbounds i8, ptr %3, i64 16
  store i32 %2, ptr %17, align 8, !tbaa !12
  %18 = trunc nuw nsw i64 %9 to i32
  %19 = getelementptr inbounds i8, ptr %3, i64 20
  store i32 %18, ptr %19, align 4, !tbaa !13
  %20 = load i32, ptr %0, align 4, !tbaa !14
  %21 = add nsw i32 %20, 1
  %22 = sext i32 %21 to i64
  %23 = shl nsw i64 %22, 3
  %24 = tail call ptr @buffer_alloc(ptr noundef %4, i64 noundef %23)
  %25 = getelementptr inbounds i8, ptr %3, i64 24
  store ptr %24, ptr %25, align 8, !tbaa !16
  %26 = icmp eq ptr %24, null
  br i1 %26, label %.loopexit.sink.split, label %.preheader

.preheader:                                       ; preds = %16
  %27 = load i32, ptr %0, align 4, !tbaa !14
  %.not4445 = icmp sgt i32 %27, 0
  br i1 %.not4445, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %.preheader
  %28 = getelementptr inbounds i8, ptr %0, i64 4
  br label %29

29:                                               ; preds = %.lr.ph, %31
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %31 ]
  %30 = tail call ptr @buffer_alloc(ptr noundef %4, i64 noundef %9)
  %.not = icmp eq ptr %30, null
  br i1 %.not, label %.loopexit.sink.split, label %31

31:                                               ; preds = %29
  %32 = getelementptr inbounds [16 x %struct.query_address_result_t], ptr %28, i64 0, i64 %indvars.iv, i32 1
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(4) %30, ptr noundef nonnull align 4 dereferenceable(4) %32, i64 %9, i1 false)
  %33 = load ptr, ptr %25, align 8, !tbaa !16
  %34 = getelementptr inbounds ptr, ptr %33, i64 %indvars.iv
  store ptr %30, ptr %34, align 8, !tbaa !17
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %35 = load i32, ptr %0, align 4, !tbaa !14
  %36 = sext i32 %35 to i64
  %.not44 = icmp slt i64 %indvars.iv.next, %36
  br i1 %.not44, label %29, label %.loopexit, !llvm.loop !18

.loopexit.sink.split:                             ; preds = %29, %16, %13, %7
  store i32 34, ptr %5, align 4, !tbaa !20
  store i32 3, ptr %6, align 4, !tbaa !20
  br label %.loopexit

.loopexit:                                        ; preds = %31, %.loopexit.sink.split, %.preheader
  %.3 = phi i32 [ 1, %.preheader ], [ -2, %.loopexit.sink.split ], [ 1, %31 ]
  ret i32 %.3
}

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

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

; Function Attrs: mustprogress 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) #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 nounwind willreturn memory(argmem: readwrite) }

!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 = !{!"hostent", !7, i64 0, !7, i64 8, !10, i64 16, !10, i64 20, !7, i64 24}
!7 = !{!"any pointer", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C/C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!6, !7, i64 0}
!12 = !{!6, !10, i64 16}
!13 = !{!6, !10, i64 20}
!14 = !{!15, !10, i64 0}
!15 = !{!"", !10, i64 0, !8, i64 4}
!16 = !{!6, !7, i64 24}
!17 = !{!7, !7, i64 0}
!18 = distinct !{!18, !19}
!19 = !{!"llvm.loop.mustprogress"}
!20 = !{!10, !10, i64 0}


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