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

; 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.std::array" = type { [16 x i8] }
%"class.chen::ip_version" = type { i8 }

; 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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt5arrayIhLm16EEixEm(ptr noundef nonnull align 1 dereferenceable(16), i64 noundef) #2 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, i64 } @_ZNK4chen11ip_version68wildcardEv(ptr noundef nonnull align 4 dereferenceable(24) %0) #2 align 2 {
  %2 = alloca %"struct.std::array", align 1
  %3 = alloca ptr, align 8
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %7 = load ptr, ptr %3, align 8
  call void @llvm.memset.p0.i64(ptr align 1 %2, i8 0, i64 16, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %8 = getelementptr inbounds %"class.chen::ip_version", ptr %7, i32 0, i32 0
  %9 = load i8, ptr %8, align 4, !tbaa !9
  %10 = zext i8 %9 to i32
  %11 = sdiv i32 %10, 8
  store i32 %11, ptr %4, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %12 = getelementptr inbounds %"class.chen::ip_version", ptr %7, i32 0, i32 0
  %13 = load i8, ptr %12, align 4, !tbaa !9
  %14 = zext i8 %13 to i32
  %15 = srem i32 %14, 8
  store i32 %15, ptr %5, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  %16 = call noundef ptr @_ZNSt5arrayIhLm16EE5beginEv(ptr noundef nonnull align 1 dereferenceable(16) %2) #5
  %17 = load i32, ptr %4, align 4, !tbaa !11
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds i8, ptr %16, i64 %18
  store ptr %19, ptr %6, align 8, !tbaa !5
  %20 = load i32, ptr %5, align 4, !tbaa !11
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %22, label %33

22:                                               ; preds = %1
  %23 = load ptr, ptr %6, align 8, !tbaa !5
  %24 = getelementptr inbounds i8, ptr %23, i32 1
  store ptr %24, ptr %6, align 8, !tbaa !5
  %25 = load i32, ptr %5, align 4, !tbaa !11
  %26 = sub nsw i32 8, %25
  %27 = shl i32 255, %26
  %28 = xor i32 %27, -1
  %29 = trunc i32 %28 to i8
  %30 = load i32, ptr %4, align 4, !tbaa !11
  %31 = sext i32 %30 to i64
  %32 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt5arrayIhLm16EEixEm(ptr noundef nonnull align 1 dereferenceable(16) %2, i64 noundef %31) #4
  store i8 %29, ptr %32, align 1, !tbaa !13
  br label %33

33:                                               ; preds = %22, %1
  br label %34

34:                                               ; preds = %40, %33
  %35 = load ptr, ptr %6, align 8, !tbaa !5
  %36 = call noundef ptr @_ZNSt5arrayIhLm16EE3endEv(ptr noundef nonnull align 1 dereferenceable(16) %2) #5
  %37 = icmp ne ptr %35, %36
  br i1 %37, label %38, label %43

38:                                               ; preds = %34
  %39 = load ptr, ptr %6, align 8, !tbaa !5
  store i8 -1, ptr %39, align 1, !tbaa !13
  br label %40

40:                                               ; preds = %38
  %41 = load ptr, ptr %6, align 8, !tbaa !5
  %42 = getelementptr inbounds i8, ptr %41, i32 1
  store ptr %42, ptr %6, align 8, !tbaa !5
  br label %34, !llvm.loop !14

43:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  %44 = getelementptr inbounds %"struct.std::array", ptr %2, i32 0, i32 0
  %45 = load { i64, i64 }, ptr %44, align 1
  ret { i64, i64 } %45
}

; Function Attrs: mustprogress nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayIhLm16EE5beginEv(ptr noundef nonnull align 1 dereferenceable(16)) #3 align 2

; Function Attrs: mustprogress nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayIhLm16EE3endEv(ptr noundef nonnull align 1 dereferenceable(16)) #3 align 2

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { mustprogress 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 #3 = { mustprogress nounwind willreturn memory(none) 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 #4 = { nounwind }
attributes #5 = { nounwind willreturn memory(none) }

!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 = !{!10, !7, i64 0}
!10 = !{!"_ZTSN4chen10ip_versionE", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"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.std::array" = type { [16 x i8] }

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt5arrayIhLm16EEixEm(ptr noundef nonnull align 1 dereferenceable(16), i64 noundef) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, i64 } @_ZNK4chen11ip_version68wildcardEv(ptr nocapture noundef nonnull readonly align 4 dereferenceable(24) %0) local_unnamed_addr #1 align 2 {
  %2 = alloca %"struct.std::array", align 8
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) %2, i8 0, i64 16, i1 false)
  %3 = load i8, ptr %0, align 4, !tbaa !5
  %4 = zext i8 %3 to i32
  %5 = lshr i32 %4, 3
  %6 = and i32 %4, 7
  %7 = call noundef ptr @_ZNSt5arrayIhLm16EE5beginEv(ptr noundef nonnull align 1 dereferenceable(16) %2) #3
  %8 = zext nneg i32 %5 to i64
  %9 = getelementptr inbounds i8, ptr %7, i64 %8
  %.not = icmp eq i32 %6, 0
  br i1 %.not, label %17, label %10

10:                                               ; preds = %1
  %11 = getelementptr inbounds i8, ptr %9, i64 1
  %12 = sub nuw nsw i32 8, %6
  %13 = shl nuw nsw i32 255, %12
  %14 = trunc i32 %13 to i8
  %15 = xor i8 %14, -1
  %16 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt5arrayIhLm16EEixEm(ptr noundef nonnull align 1 dereferenceable(16) %2, i64 noundef %8) #4
  store i8 %15, ptr %16, align 1, !tbaa !9
  br label %17

17:                                               ; preds = %10, %1
  %.0 = phi ptr [ %11, %10 ], [ %9, %1 ]
  %18 = call noundef ptr @_ZNSt5arrayIhLm16EE3endEv(ptr noundef nonnull align 1 dereferenceable(16) %2) #3
  %.not910 = icmp eq ptr %.0, %18
  br i1 %.not910, label %._crit_edge, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %17
  %19 = ptrtoint ptr %18 to i64
  %.012 = ptrtoint ptr %.0 to i64
  %20 = sub i64 %19, %.012
  call void @llvm.memset.p0.i64(ptr align 1 %.0, i8 -1, i64 %20, i1 false), !tbaa !9
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.preheader, %17
  %.fca.0.load = load i64, ptr %2, align 8
  %.fca.0.insert = insertvalue { i64, i64 } poison, i64 %.fca.0.load, 0
  %.fca.1.gep = getelementptr inbounds i8, ptr %2, i64 8
  %.fca.1.load = load i64, ptr %.fca.1.gep, align 8
  %.fca.1.insert = insertvalue { i64, i64 } %.fca.0.insert, i64 %.fca.1.load, 1
  ret { i64, i64 } %.fca.1.insert
}

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayIhLm16EE5beginEv(ptr noundef nonnull align 1 dereferenceable(16)) local_unnamed_addr #2 align 2

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(none) uwtable
declare dso_local noundef ptr @_ZNSt5arrayIhLm16EE3endEv(ptr noundef nonnull align 1 dereferenceable(16)) local_unnamed_addr #2 align 2

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


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,LICMPass,LoopIdiomRecognizePass,LoopRotatePass,LoopSimplifyPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass