; LLVM IR from chensoft/libsocket :: src/ip/ip_version.ll (ZN4chen11ip_version66toCIDREPKh)

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

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

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

declare noundef i32 @_ZN4chen3num4bitsEj(i32 noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i8 @_ZN4chen11ip_version66toCIDREPKh(ptr noundef %0) #2 align 2 {
  %2 = alloca ptr, align 8
  %3 = alloca i8, align 1
  %4 = alloca i32, align 4
  store ptr %0, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 1, ptr %3) #3
  store i8 0, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #3
  store i32 0, ptr %4, align 4, !tbaa !10
  br label %5

5:                                                ; preds = %23, %1
  %6 = load i32, ptr %4, align 4, !tbaa !10
  %7 = icmp slt i32 %6, 16
  br i1 %7, label %9, label %8

8:                                                ; preds = %5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %26

9:                                                ; preds = %5
  %10 = load ptr, ptr %2, align 8, !tbaa !5
  %11 = load i32, ptr %4, align 4, !tbaa !10
  %12 = sext i32 %11 to i64
  %13 = getelementptr inbounds i8, ptr %10, i64 %12
  %14 = load i8, ptr %13, align 1, !tbaa !9
  %15 = zext i8 %14 to i32
  %16 = call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %15)
  %17 = trunc i32 %16 to i8
  %18 = zext i8 %17 to i32
  %19 = load i8, ptr %3, align 1, !tbaa !9
  %20 = zext i8 %19 to i32
  %21 = add nsw i32 %20, %18
  %22 = trunc i32 %21 to i8
  store i8 %22, ptr %3, align 1, !tbaa !9
  br label %23

23:                                               ; preds = %9
  %24 = load i32, ptr %4, align 4, !tbaa !10
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr %4, align 4, !tbaa !10
  br label %5, !llvm.loop !12

26:                                               ; preds = %8
  %27 = load i8, ptr %3, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %3) #3
  ret i8 %27
}

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

!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++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = !{!11, !11, i64 0}
!11 = !{!"int", !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"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"

declare noundef i32 @_ZN4chen3num4bitsEj(i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i8 @_ZN4chen11ip_version66toCIDREPKh(ptr nocapture noundef readonly %0) local_unnamed_addr #1 align 2 {
  %2 = load i8, ptr %0, align 1, !tbaa !5
  %3 = zext i8 %2 to i32
  %4 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %3)
  %5 = trunc i32 %4 to i8
  %6 = getelementptr inbounds i8, ptr %0, i64 1
  %7 = load i8, ptr %6, align 1, !tbaa !5
  %8 = zext i8 %7 to i32
  %9 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %8)
  %10 = trunc i32 %9 to i8
  %11 = add i8 %5, %10
  %12 = getelementptr inbounds i8, ptr %0, i64 2
  %13 = load i8, ptr %12, align 1, !tbaa !5
  %14 = zext i8 %13 to i32
  %15 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %14)
  %16 = trunc i32 %15 to i8
  %17 = add i8 %11, %16
  %18 = getelementptr inbounds i8, ptr %0, i64 3
  %19 = load i8, ptr %18, align 1, !tbaa !5
  %20 = zext i8 %19 to i32
  %21 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %20)
  %22 = trunc i32 %21 to i8
  %23 = add i8 %17, %22
  %24 = getelementptr inbounds i8, ptr %0, i64 4
  %25 = load i8, ptr %24, align 1, !tbaa !5
  %26 = zext i8 %25 to i32
  %27 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %26)
  %28 = trunc i32 %27 to i8
  %29 = add i8 %23, %28
  %30 = getelementptr inbounds i8, ptr %0, i64 5
  %31 = load i8, ptr %30, align 1, !tbaa !5
  %32 = zext i8 %31 to i32
  %33 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %32)
  %34 = trunc i32 %33 to i8
  %35 = add i8 %29, %34
  %36 = getelementptr inbounds i8, ptr %0, i64 6
  %37 = load i8, ptr %36, align 1, !tbaa !5
  %38 = zext i8 %37 to i32
  %39 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %38)
  %40 = trunc i32 %39 to i8
  %41 = add i8 %35, %40
  %42 = getelementptr inbounds i8, ptr %0, i64 7
  %43 = load i8, ptr %42, align 1, !tbaa !5
  %44 = zext i8 %43 to i32
  %45 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %44)
  %46 = trunc i32 %45 to i8
  %47 = add i8 %41, %46
  %48 = getelementptr inbounds i8, ptr %0, i64 8
  %49 = load i8, ptr %48, align 1, !tbaa !5
  %50 = zext i8 %49 to i32
  %51 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %50)
  %52 = trunc i32 %51 to i8
  %53 = add i8 %47, %52
  %54 = getelementptr inbounds i8, ptr %0, i64 9
  %55 = load i8, ptr %54, align 1, !tbaa !5
  %56 = zext i8 %55 to i32
  %57 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %56)
  %58 = trunc i32 %57 to i8
  %59 = add i8 %53, %58
  %60 = getelementptr inbounds i8, ptr %0, i64 10
  %61 = load i8, ptr %60, align 1, !tbaa !5
  %62 = zext i8 %61 to i32
  %63 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %62)
  %64 = trunc i32 %63 to i8
  %65 = add i8 %59, %64
  %66 = getelementptr inbounds i8, ptr %0, i64 11
  %67 = load i8, ptr %66, align 1, !tbaa !5
  %68 = zext i8 %67 to i32
  %69 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %68)
  %70 = trunc i32 %69 to i8
  %71 = add i8 %65, %70
  %72 = getelementptr inbounds i8, ptr %0, i64 12
  %73 = load i8, ptr %72, align 1, !tbaa !5
  %74 = zext i8 %73 to i32
  %75 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %74)
  %76 = trunc i32 %75 to i8
  %77 = add i8 %71, %76
  %78 = getelementptr inbounds i8, ptr %0, i64 13
  %79 = load i8, ptr %78, align 1, !tbaa !5
  %80 = zext i8 %79 to i32
  %81 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %80)
  %82 = trunc i32 %81 to i8
  %83 = add i8 %77, %82
  %84 = getelementptr inbounds i8, ptr %0, i64 14
  %85 = load i8, ptr %84, align 1, !tbaa !5
  %86 = zext i8 %85 to i32
  %87 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %86)
  %88 = trunc i32 %87 to i8
  %89 = add i8 %83, %88
  %90 = getelementptr inbounds i8, ptr %0, i64 15
  %91 = load i8, ptr %90, align 1, !tbaa !5
  %92 = zext i8 %91 to i32
  %93 = tail call noundef i32 @_ZN4chen3num4bitsEj(i32 noundef %92)
  %94 = trunc i32 %93 to i8
  %95 = add i8 %89, %94
  ret i8 %95
}

attributes #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 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" }

!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++ TBAA"}


; Effective O3 passes: GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,LCSSAPass,LoopRotatePass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass