; 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.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 }
%struct.gaih_addrtuple = type { ptr, ptr, i32, [4 x i32], i32 }

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

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

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

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

; Function Attrs: nounwind uwtable
define dso_local i32 @convert_kadnode_nss_response_to_addrtuple(ptr noundef %0, ptr noundef %1, ptr noundef %2, ptr noundef %3, ptr noundef %4, ptr noundef %5) #1 {
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca ptr, align 8
  %10 = alloca ptr, align 8
  %11 = alloca ptr, align 8
  %12 = alloca ptr, align 8
  %13 = alloca ptr, align 8
  %14 = alloca ptr, align 8
  %15 = alloca i32, align 4
  %16 = alloca ptr, align 8
  %17 = alloca i32, align 4
  %18 = alloca ptr, align 8
  %19 = alloca ptr, align 8
  %20 = alloca i64, align 8
  store ptr %0, ptr %8, align 8, !tbaa !5
  store ptr %1, ptr %9, align 8, !tbaa !5
  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
  store ptr %5, ptr %13, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #4
  %21 = load ptr, ptr %11, align 8, !tbaa !5
  %22 = load ptr, ptr %9, align 8, !tbaa !5
  %23 = call ptr @buffer_strdup(ptr noundef %21, ptr noundef %22)
  store ptr %23, ptr %14, align 8, !tbaa !5
  %24 = load ptr, ptr %14, align 8, !tbaa !5
  %25 = icmp eq ptr %24, null
  br i1 %25, label %26, label %29

26:                                               ; preds = %6
  %27 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 34, ptr %27, align 4, !tbaa !9
  %28 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 3, ptr %28, align 4, !tbaa !9
  store i32 -2, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %108

29:                                               ; preds = %6
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #4
  store ptr null, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #4
  store i32 0, ptr %17, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %101, %29
  %31 = load i32, ptr %17, align 4, !tbaa !9
  %32 = load ptr, ptr %8, align 8, !tbaa !5
  %33 = getelementptr inbounds %struct.kadnode_nss_response_t, ptr %32, i32 0, i32 0
  %34 = load i32, ptr %33, align 4, !tbaa !11
  %35 = icmp slt i32 %31, %34
  br i1 %35, label %37, label %36

36:                                               ; preds = %30
  store i32 2, ptr %15, align 4
  br label %104

37:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #4
  %38 = load ptr, ptr %8, align 8, !tbaa !5
  %39 = getelementptr inbounds %struct.kadnode_nss_response_t, ptr %38, i32 0, i32 1
  %40 = load i32, ptr %17, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [16 x %struct.query_address_result_t], ptr %39, i64 0, i64 %41
  store ptr %42, ptr %18, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %19) #4
  %43 = load ptr, ptr %16, align 8, !tbaa !5
  %44 = icmp eq ptr %43, null
  br i1 %44, label %45, label %53

45:                                               ; preds = %37
  %46 = load ptr, ptr %10, align 8, !tbaa !5
  %47 = load ptr, ptr %46, align 8, !tbaa !5
  %48 = icmp ne ptr %47, null
  br i1 %48, label %49, label %53

49:                                               ; preds = %45
  %50 = load ptr, ptr %10, align 8, !tbaa !5
  %51 = load ptr, ptr %50, align 8, !tbaa !5
  store ptr %51, ptr %19, align 8, !tbaa !5
  %52 = load ptr, ptr %19, align 8, !tbaa !5
  call void @llvm.memset.p0.i64(ptr align 8 %52, i8 0, i64 40, i1 false)
  br label %62

53:                                               ; preds = %45, %37
  %54 = load ptr, ptr %11, align 8, !tbaa !5
  %55 = call ptr @buffer_alloc(ptr noundef %54, i64 noundef 40)
  store ptr %55, ptr %19, align 8, !tbaa !5
  %56 = load ptr, ptr %19, align 8, !tbaa !5
  %57 = icmp eq ptr %56, null
  br i1 %57, label %58, label %61

58:                                               ; preds = %53
  %59 = load ptr, ptr %12, align 8, !tbaa !5
  store i32 34, ptr %59, align 4, !tbaa !9
  %60 = load ptr, ptr %13, align 8, !tbaa !5
  store i32 3, ptr %60, align 4, !tbaa !9
  store i32 -2, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %98

61:                                               ; preds = %53
  br label %62

62:                                               ; preds = %61, %49
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #4
  %63 = load ptr, ptr %18, align 8, !tbaa !5
  %64 = getelementptr inbounds %struct.query_address_result_t, ptr %63, i32 0, i32 0
  %65 = load i32, ptr %64, align 4, !tbaa !13
  %66 = icmp eq i32 %65, 2
  %67 = zext i1 %66 to i64
  %68 = select i1 %66, i64 4, i64 16
  store i64 %68, ptr %20, align 8, !tbaa !15
  %69 = load ptr, ptr %14, align 8, !tbaa !5
  %70 = load ptr, ptr %19, align 8, !tbaa !5
  %71 = getelementptr inbounds %struct.gaih_addrtuple, ptr %70, i32 0, i32 1
  store ptr %69, ptr %71, align 8, !tbaa !17
  %72 = load ptr, ptr %18, align 8, !tbaa !5
  %73 = getelementptr inbounds %struct.query_address_result_t, ptr %72, i32 0, i32 0
  %74 = load i32, ptr %73, align 4, !tbaa !13
  %75 = load ptr, ptr %19, align 8, !tbaa !5
  %76 = getelementptr inbounds %struct.gaih_addrtuple, ptr %75, i32 0, i32 2
  store i32 %74, ptr %76, align 8, !tbaa !19
  %77 = load ptr, ptr %19, align 8, !tbaa !5
  %78 = getelementptr inbounds %struct.gaih_addrtuple, ptr %77, i32 0, i32 3
  %79 = load ptr, ptr %18, align 8, !tbaa !5
  %80 = getelementptr inbounds %struct.query_address_result_t, ptr %79, i32 0, i32 1
  %81 = load i64, ptr %20, align 8, !tbaa !15
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %78, ptr align 4 %80, i64 %81, i1 false)
  %82 = load ptr, ptr %18, align 8, !tbaa !5
  %83 = getelementptr inbounds %struct.query_address_result_t, ptr %82, i32 0, i32 2
  %84 = load i32, ptr %83, align 4, !tbaa !20
  %85 = load ptr, ptr %19, align 8, !tbaa !5
  %86 = getelementptr inbounds %struct.gaih_addrtuple, ptr %85, i32 0, i32 4
  store i32 %84, ptr %86, align 4, !tbaa !21
  %87 = load ptr, ptr %16, align 8, !tbaa !5
  %88 = icmp eq ptr %87, null
  br i1 %88, label %89, label %92

89:                                               ; preds = %62
  %90 = load ptr, ptr %19, align 8, !tbaa !5
  %91 = load ptr, ptr %10, align 8, !tbaa !5
  store ptr %90, ptr %91, align 8, !tbaa !5
  br label %96

92:                                               ; preds = %62
  %93 = load ptr, ptr %19, align 8, !tbaa !5
  %94 = load ptr, ptr %16, align 8, !tbaa !5
  %95 = getelementptr inbounds %struct.gaih_addrtuple, ptr %94, i32 0, i32 0
  store ptr %93, ptr %95, align 8, !tbaa !22
  br label %96

96:                                               ; preds = %92, %89
  %97 = load ptr, ptr %19, align 8, !tbaa !5
  store ptr %97, ptr %16, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #4
  store i32 0, ptr %15, align 4
  br label %98

98:                                               ; preds = %96, %58
  call void @llvm.lifetime.end.p0(i64 8, ptr %19) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #4
  %99 = load i32, ptr %15, align 4
  switch i32 %99, label %104 [
    i32 0, label %100
  ]

100:                                              ; preds = %98
  br label %101

101:                                              ; preds = %100
  %102 = load i32, ptr %17, align 4, !tbaa !9
  %103 = add nsw i32 %102, 1
  store i32 %103, ptr %17, align 4, !tbaa !9
  br label %30, !llvm.loop !23

104:                                              ; preds = %98, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #4
  %105 = load i32, ptr %15, align 4
  switch i32 %105, label %107 [
    i32 2, label %106
  ]

106:                                              ; preds = %104
  store i32 1, ptr %7, align 4
  store i32 1, ptr %15, align 4
  br label %107

107:                                              ; preds = %106, %104
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #4
  br label %108

108:                                              ; preds = %107, %26
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #4
  %109 = load i32, ptr %7, align 4
  ret i32 %109
}

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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: readwrite) }
attributes #3 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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, !10, i64 0}
!12 = !{!"", !10, i64 0, !7, i64 4}
!13 = !{!14, !10, i64 0}
!14 = !{!"", !10, i64 0, !7, i64 4, !10, i64 20}
!15 = !{!16, !16, i64 0}
!16 = !{!"long", !7, i64 0}
!17 = !{!18, !6, i64 8}
!18 = !{!"gaih_addrtuple", !6, i64 0, !6, i64 8, !10, i64 16, !7, i64 20, !10, i64 36}
!19 = !{!18, !10, i64 16}
!20 = !{!14, !10, i64 20}
!21 = !{!18, !10, i64 36}
!22 = !{!18, !6, i64 0}
!23 = distinct !{!23, !24}
!24 = !{!"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
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

; Function Attrs: nounwind uwtable
define dso_local noundef i32 @convert_kadnode_nss_response_to_addrtuple(ptr nocapture noundef readonly %0, ptr noundef %1, ptr nocapture noundef %2, ptr noundef %3, ptr nocapture noundef writeonly %4, ptr nocapture noundef writeonly %5) local_unnamed_addr #0 {
  %7 = tail call ptr @buffer_strdup(ptr noundef %3, ptr noundef %1)
  %8 = icmp eq ptr %7, null
  br i1 %8, label %.loopexit.sink.split, label %.preheader

.preheader:                                       ; preds = %6
  %9 = load i32, ptr %0, align 4, !tbaa !5
  %.not4650 = icmp sgt i32 %9, 0
  br i1 %.not4650, label %.lr.ph, label %.loopexit

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

11:                                               ; preds = %.lr.ph, %20
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %.04151 = phi ptr [ null, %.lr.ph ], [ %.037, %20 ]
  %12 = getelementptr inbounds [16 x %struct.query_address_result_t], ptr %10, i64 0, i64 %indvars.iv
  %13 = icmp eq ptr %.04151, null
  br i1 %13, label %14, label %17

14:                                               ; preds = %11
  %15 = load ptr, ptr %2, align 8, !tbaa !10
  %.not = icmp eq ptr %15, null
  br i1 %.not, label %17, label %16

16:                                               ; preds = %14
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(40) %15, i8 0, i64 40, i1 false)
  br label %20

17:                                               ; preds = %14, %11
  %18 = tail call ptr @buffer_alloc(ptr noundef %3, i64 noundef 40)
  %19 = icmp eq ptr %18, null
  br i1 %19, label %.loopexit.sink.split, label %20

20:                                               ; preds = %17, %16
  %.037 = phi ptr [ %15, %16 ], [ %18, %17 ]
  %21 = load i32, ptr %12, align 4, !tbaa !12
  %22 = icmp eq i32 %21, 2
  %23 = select i1 %22, i64 4, i64 16
  %24 = getelementptr inbounds i8, ptr %.037, i64 8
  store ptr %7, ptr %24, align 8, !tbaa !14
  %25 = getelementptr inbounds i8, ptr %.037, i64 16
  store i32 %21, ptr %25, align 8, !tbaa !16
  %26 = getelementptr inbounds i8, ptr %.037, i64 20
  %27 = getelementptr inbounds i8, ptr %12, i64 4
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(4) %26, ptr noundef nonnull align 4 dereferenceable(4) %27, i64 %23, i1 false)
  %28 = getelementptr inbounds i8, ptr %12, i64 20
  %29 = load i32, ptr %28, align 4, !tbaa !17
  %30 = getelementptr inbounds i8, ptr %.037, i64 36
  store i32 %29, ptr %30, align 4, !tbaa !18
  %..04151 = select i1 %13, ptr %2, ptr %.04151
  store ptr %.037, ptr %..04151, align 8, !tbaa !10
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %31 = load i32, ptr %0, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %.not46 = icmp slt i64 %indvars.iv.next, %32
  br i1 %.not46, label %11, label %.loopexit, !llvm.loop !19

.loopexit.sink.split:                             ; preds = %17, %6
  store i32 34, ptr %4, align 4, !tbaa !21
  store i32 3, ptr %5, align 4, !tbaa !21
  br label %.loopexit

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

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

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) }
attributes #2 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }

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


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