; LLVM IR from thalium/icebox :: third_party/virtualbox/src/VBox/Devices/EFI/Firmware/MdeModulePkg/Universal (NetStringToIp)

; 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

; Function Attrs: nounwind uwtable
declare dso_local i32 @NetStringToU32(ptr noundef) #1

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

11:                                               ; preds = %63, %2
  %12 = load i64, ptr %8, align 8, !tbaa !11
  %13 = icmp ult i64 %12, 4
  br i1 %13, label %14, label %66

14:                                               ; preds = %11
  %15 = load ptr, ptr %4, align 8, !tbaa !5
  %16 = load i8, ptr %15, align 1, !tbaa !13
  %17 = zext i8 %16 to i32
  %18 = icmp sle i32 48, %17
  br i1 %18, label %19, label %24

19:                                               ; preds = %14
  %20 = load ptr, ptr %4, align 8, !tbaa !5
  %21 = load i8, ptr %20, align 1, !tbaa !13
  %22 = zext i8 %21 to i32
  %23 = icmp sle i32 %22, 57
  br i1 %23, label %25, label %24

24:                                               ; preds = %19, %14
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %69

25:                                               ; preds = %19
  %26 = load ptr, ptr %4, align 8, !tbaa !5
  %27 = call i32 @NetStringToU32(ptr noundef %26)
  store i32 %27, ptr %6, align 4, !tbaa !9
  %28 = load i32, ptr %6, align 4, !tbaa !9
  %29 = icmp ugt i32 %28, 255
  br i1 %29, label %30, label %31

30:                                               ; preds = %25
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %69

31:                                               ; preds = %25
  %32 = load i32, ptr %7, align 4, !tbaa !9
  %33 = shl i32 %32, 8
  %34 = load i32, ptr %6, align 4, !tbaa !9
  %35 = or i32 %33, %34
  store i32 %35, ptr %7, align 4, !tbaa !9
  br label %36

36:                                               ; preds = %48, %31
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = load i8, ptr %37, align 1, !tbaa !13
  %39 = zext i8 %38 to i32
  %40 = icmp sle i32 48, %39
  br i1 %40, label %41, label %46

41:                                               ; preds = %36
  %42 = load ptr, ptr %4, align 8, !tbaa !5
  %43 = load i8, ptr %42, align 1, !tbaa !13
  %44 = zext i8 %43 to i32
  %45 = icmp sle i32 %44, 57
  br label %46

46:                                               ; preds = %41, %36
  %47 = phi i1 [ false, %36 ], [ %45, %41 ]
  br i1 %47, label %48, label %51

48:                                               ; preds = %46
  %49 = load ptr, ptr %4, align 8, !tbaa !5
  %50 = getelementptr inbounds i8, ptr %49, i32 1
  store ptr %50, ptr %4, align 8, !tbaa !5
  br label %36, !llvm.loop !14

51:                                               ; preds = %46
  %52 = load i64, ptr %8, align 8, !tbaa !11
  %53 = icmp ult i64 %52, 3
  br i1 %53, label %54, label %60

54:                                               ; preds = %51
  %55 = load ptr, ptr %4, align 8, !tbaa !5
  %56 = load i8, ptr %55, align 1, !tbaa !13
  %57 = zext i8 %56 to i32
  %58 = icmp ne i32 %57, 46
  br i1 %58, label %59, label %60

59:                                               ; preds = %54
  store i64 -9223372036854775806, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %69

60:                                               ; preds = %54, %51
  %61 = load ptr, ptr %4, align 8, !tbaa !5
  %62 = getelementptr inbounds i8, ptr %61, i32 1
  store ptr %62, ptr %4, align 8, !tbaa !5
  br label %63

63:                                               ; preds = %60
  %64 = load i64, ptr %8, align 8, !tbaa !11
  %65 = add i64 %64, 1
  store i64 %65, ptr %8, align 8, !tbaa !11
  br label %11, !llvm.loop !16

66:                                               ; preds = %11
  %67 = load i32, ptr %7, align 4, !tbaa !9
  %68 = load ptr, ptr %5, align 8, !tbaa !5
  store i32 %67, ptr %68, align 4, !tbaa !9
  store i64 0, ptr %3, align 8
  store i32 1, ptr %9, align 4
  br label %69

69:                                               ; preds = %66, %59, %30, %24
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #2
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #2
  %70 = load i64, ptr %3, align 8
  ret i64 %70
}

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 = { 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 long", !7, i64 0}
!13 = !{!7, !7, i64 0}
!14 = distinct !{!14, !15}
!15 = !{!"llvm.loop.mustprogress"}
!16 = distinct !{!16, !15}


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

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

; Function Attrs: nounwind uwtable
define dso_local range(i64 -9223372036854775806, 1) i64 @NetStringToIp(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  store i32 0, ptr %1, align 4, !tbaa !5
  %3 = load i8, ptr %0, align 1, !tbaa !9
  %4 = add i8 %3, -48
  %or.cond = icmp ult i8 %4, 10
  br i1 %or.cond, label %5, label %.loopexit

5:                                                ; preds = %2
  %6 = tail call i32 @NetStringToU32(ptr noundef nonnull %0)
  %7 = icmp ugt i32 %6, 255
  br i1 %7, label %.loopexit, label %.preheader37

.preheader37:                                     ; preds = %5, %.preheader37
  %.1 = phi ptr [ %10, %.preheader37 ], [ %0, %5 ]
  %8 = load i8, ptr %.1, align 1, !tbaa !9
  %9 = add i8 %8, -48
  %or.cond24 = icmp ult i8 %9, 10
  %10 = getelementptr inbounds i8, ptr %.1, i64 1
  br i1 %or.cond24, label %.preheader37, label %.critedge, !llvm.loop !10

.critedge:                                        ; preds = %.preheader37
  %.not23 = icmp eq i8 %8, 46
  br i1 %.not23, label %11, label %.loopexit

11:                                               ; preds = %.critedge
  %12 = load i8, ptr %10, align 1, !tbaa !9
  %13 = add i8 %12, -48
  %or.cond.1 = icmp ult i8 %13, 10
  br i1 %or.cond.1, label %14, label %.loopexit

14:                                               ; preds = %11
  %15 = tail call i32 @NetStringToU32(ptr noundef nonnull %10)
  %16 = icmp ugt i32 %15, 255
  br i1 %16, label %.loopexit, label %.preheader36

.preheader36:                                     ; preds = %14, %.preheader36
  %.1.1 = phi ptr [ %19, %.preheader36 ], [ %10, %14 ]
  %17 = load i8, ptr %.1.1, align 1, !tbaa !9
  %18 = add i8 %17, -48
  %or.cond24.1 = icmp ult i8 %18, 10
  %19 = getelementptr inbounds i8, ptr %.1.1, i64 1
  br i1 %or.cond24.1, label %.preheader36, label %.critedge.1, !llvm.loop !10

.critedge.1:                                      ; preds = %.preheader36
  %.not23.1 = icmp eq i8 %17, 46
  br i1 %.not23.1, label %20, label %.loopexit

20:                                               ; preds = %.critedge.1
  %21 = load i8, ptr %19, align 1, !tbaa !9
  %22 = add i8 %21, -48
  %or.cond.2 = icmp ult i8 %22, 10
  br i1 %or.cond.2, label %23, label %.loopexit

23:                                               ; preds = %20
  %24 = tail call i32 @NetStringToU32(ptr noundef nonnull %19)
  %25 = icmp ugt i32 %24, 255
  br i1 %25, label %.loopexit, label %.preheader

.preheader:                                       ; preds = %23, %.preheader
  %.1.2 = phi ptr [ %28, %.preheader ], [ %19, %23 ]
  %26 = load i8, ptr %.1.2, align 1, !tbaa !9
  %27 = add i8 %26, -48
  %or.cond24.2 = icmp ult i8 %27, 10
  %28 = getelementptr inbounds i8, ptr %.1.2, i64 1
  br i1 %or.cond24.2, label %.preheader, label %.critedge.2, !llvm.loop !10

.critedge.2:                                      ; preds = %.preheader
  %29 = shl nuw nsw i32 %6, 16
  %30 = shl nuw nsw i32 %15, 8
  %31 = or disjoint i32 %29, %30
  %32 = or disjoint i32 %24, %31
  %.not23.2 = icmp eq i8 %26, 46
  br i1 %.not23.2, label %33, label %.loopexit

33:                                               ; preds = %.critedge.2
  %34 = load i8, ptr %28, align 1, !tbaa !9
  %35 = add i8 %34, -48
  %or.cond.3 = icmp ult i8 %35, 10
  br i1 %or.cond.3, label %36, label %.loopexit

36:                                               ; preds = %33
  %37 = tail call i32 @NetStringToU32(ptr noundef nonnull %28)
  %38 = icmp ugt i32 %37, 255
  br i1 %38, label %.loopexit, label %.critedge.3

.critedge.3:                                      ; preds = %36
  %39 = shl nuw i32 %32, 8
  %40 = or disjoint i32 %37, %39
  store i32 %40, ptr %1, align 4, !tbaa !5
  br label %.loopexit

.loopexit:                                        ; preds = %.critedge, %5, %2, %11, %14, %.critedge.1, %20, %23, %.critedge.2, %33, %36, %.critedge.3
  %.018 = phi i64 [ 0, %.critedge.3 ], [ -9223372036854775806, %36 ], [ -9223372036854775806, %33 ], [ -9223372036854775806, %.critedge.2 ], [ -9223372036854775806, %23 ], [ -9223372036854775806, %20 ], [ -9223372036854775806, %.critedge.1 ], [ -9223372036854775806, %14 ], [ -9223372036854775806, %11 ], [ -9223372036854775806, %2 ], [ -9223372036854775806, %5 ], [ -9223372036854775806, %.critedge ]
  ret i64 %.018
}

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

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass