; LLVM IR from pandax381/microps :: ip (ip_addr_pton)

; 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: nounwind uwtable
define dso_local i32 @ip_addr_pton(ptr noundef %0, ptr noundef %1) #0 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca ptr, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = 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 8, ptr %6) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %11, ptr %6, align 8, !tbaa !5
  store i32 0, ptr %8, align 4, !tbaa !9
  br label %12

12:                                               ; preds = %55, %2
  %13 = load i32, ptr %8, align 4, !tbaa !9
  %14 = icmp slt i32 %13, 4
  br i1 %14, label %15, label %58

15:                                               ; preds = %12
  %16 = load ptr, ptr %6, align 8, !tbaa !5
  %17 = call i64 @strtol(ptr noundef %16, ptr noundef %7, i32 noundef 10) #3
  store i64 %17, ptr %9, align 8, !tbaa !11
  %18 = load i64, ptr %9, align 8, !tbaa !11
  %19 = icmp slt i64 %18, 0
  br i1 %19, label %23, label %20

20:                                               ; preds = %15
  %21 = load i64, ptr %9, align 8, !tbaa !11
  %22 = icmp sgt i64 %21, 255
  br i1 %22, label %23, label %24

23:                                               ; preds = %20, %15
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %59

24:                                               ; preds = %20
  %25 = load ptr, ptr %7, align 8, !tbaa !5
  %26 = load ptr, ptr %6, align 8, !tbaa !5
  %27 = icmp eq ptr %25, %26
  br i1 %27, label %28, label %29

28:                                               ; preds = %24
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %59

29:                                               ; preds = %24
  %30 = load i32, ptr %8, align 4, !tbaa !9
  %31 = icmp eq i32 %30, 3
  br i1 %31, label %32, label %37

32:                                               ; preds = %29
  %33 = load ptr, ptr %7, align 8, !tbaa !5
  %34 = load i8, ptr %33, align 1, !tbaa !13
  %35 = sext i8 %34 to i32
  %36 = icmp ne i32 %35, 0
  br i1 %36, label %45, label %37

37:                                               ; preds = %32, %29
  %38 = load i32, ptr %8, align 4, !tbaa !9
  %39 = icmp ne i32 %38, 3
  br i1 %39, label %40, label %46

40:                                               ; preds = %37
  %41 = load ptr, ptr %7, align 8, !tbaa !5
  %42 = load i8, ptr %41, align 1, !tbaa !13
  %43 = sext i8 %42 to i32
  %44 = icmp ne i32 %43, 46
  br i1 %44, label %45, label %46

45:                                               ; preds = %40, %32
  store i32 -1, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %59

46:                                               ; preds = %40, %37
  %47 = load i64, ptr %9, align 8, !tbaa !11
  %48 = trunc i64 %47 to i8
  %49 = load ptr, ptr %5, align 8, !tbaa !5
  %50 = load i32, ptr %8, align 4, !tbaa !9
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i8, ptr %49, i64 %51
  store i8 %48, ptr %52, align 1, !tbaa !13
  %53 = load ptr, ptr %7, align 8, !tbaa !5
  %54 = getelementptr inbounds i8, ptr %53, i64 1
  store ptr %54, ptr %6, align 8, !tbaa !5
  br label %55

55:                                               ; preds = %46
  %56 = load i32, ptr %8, align 4, !tbaa !9
  %57 = add nsw i32 %56, 1
  store i32 %57, ptr %8, align 4, !tbaa !9
  br label %12, !llvm.loop !14

58:                                               ; preds = %12
  store i32 0, ptr %3, align 4
  store i32 1, ptr %10, align 4
  br label %59

59:                                               ; preds = %58, %45, %28, %23
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #3
  %60 = load i32, ptr %3, align 4
  ret i32 %60
}

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

; Function Attrs: nounwind
declare i64 @strtol(ptr noundef, ptr noundef, i32 noundef) #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 = { nounwind "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/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"long", !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"

; Function Attrs: mustprogress nofree nounwind willreturn uwtable
define dso_local range(i32 -1, 1) i32 @ip_addr_pton(ptr noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = alloca ptr, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  %4 = call i64 @strtol(ptr noundef %0, ptr noundef nonnull %3, i32 noundef 10) #3
  %or.cond = icmp ugt i64 %4, 255
  br i1 %or.cond, label %42, label %5

5:                                                ; preds = %2
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp eq ptr %6, %0
  br i1 %7, label %42, label %8

8:                                                ; preds = %5
  %9 = load i8, ptr %6, align 1, !tbaa !9
  %.not18 = icmp eq i8 %9, 46
  br i1 %.not18, label %10, label %42

10:                                               ; preds = %8
  %11 = trunc nuw i64 %4 to i8
  store i8 %11, ptr %1, align 1, !tbaa !9
  %12 = getelementptr inbounds i8, ptr %6, i64 1
  %13 = call i64 @strtol(ptr noundef nonnull %12, ptr noundef nonnull %3, i32 noundef 10) #3
  %or.cond.1 = icmp ugt i64 %13, 255
  br i1 %or.cond.1, label %42, label %14

14:                                               ; preds = %10
  %15 = load ptr, ptr %3, align 8, !tbaa !5
  %16 = icmp eq ptr %15, %12
  br i1 %16, label %42, label %17

17:                                               ; preds = %14
  %18 = load i8, ptr %15, align 1, !tbaa !9
  %.not18.1 = icmp eq i8 %18, 46
  br i1 %.not18.1, label %19, label %42

19:                                               ; preds = %17
  %20 = trunc nuw i64 %13 to i8
  %21 = getelementptr inbounds i8, ptr %1, i64 1
  store i8 %20, ptr %21, align 1, !tbaa !9
  %22 = getelementptr inbounds i8, ptr %15, i64 1
  %23 = call i64 @strtol(ptr noundef nonnull %22, ptr noundef nonnull %3, i32 noundef 10) #3
  %or.cond.2 = icmp ugt i64 %23, 255
  br i1 %or.cond.2, label %42, label %24

24:                                               ; preds = %19
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = icmp eq ptr %25, %22
  br i1 %26, label %42, label %27

27:                                               ; preds = %24
  %28 = load i8, ptr %25, align 1, !tbaa !9
  %.not18.2 = icmp eq i8 %28, 46
  br i1 %.not18.2, label %29, label %42

29:                                               ; preds = %27
  %30 = trunc nuw i64 %23 to i8
  %31 = getelementptr inbounds i8, ptr %1, i64 2
  store i8 %30, ptr %31, align 1, !tbaa !9
  %32 = getelementptr inbounds i8, ptr %25, i64 1
  %33 = call i64 @strtol(ptr noundef nonnull %32, ptr noundef nonnull %3, i32 noundef 10) #3
  %or.cond.3 = icmp ugt i64 %33, 255
  br i1 %or.cond.3, label %42, label %34

34:                                               ; preds = %29
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = icmp eq ptr %35, %32
  br i1 %36, label %42, label %37

37:                                               ; preds = %34
  %38 = load i8, ptr %35, align 1, !tbaa !9
  %.not.3 = icmp eq i8 %38, 0
  br i1 %.not.3, label %39, label %42

39:                                               ; preds = %37
  %40 = trunc nuw i64 %33 to i8
  %41 = getelementptr inbounds i8, ptr %1, i64 3
  store i8 %40, ptr %41, align 1, !tbaa !9
  br label %42

42:                                               ; preds = %39, %37, %34, %29, %27, %24, %19, %17, %14, %10, %8, %5, %2
  %.0 = phi i32 [ -1, %2 ], [ -1, %5 ], [ -1, %8 ], [ -1, %10 ], [ -1, %14 ], [ -1, %17 ], [ -1, %19 ], [ -1, %24 ], [ -1, %27 ], [ -1, %29 ], [ -1, %34 ], [ -1, %37 ], [ 0, %39 ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret i32 %.0
}

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

; Function Attrs: mustprogress nofree nounwind willreturn
declare i64 @strtol(ptr noundef readonly, ptr nocapture noundef, i32 noundef) local_unnamed_addr #2

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

attributes #0 = { mustprogress nofree nounwind willreturn 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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { mustprogress nofree nounwind willreturn "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/C++ TBAA"}
!9 = !{!7, !7, i64 0}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,PostOrderFunctionAttrsPass,SCCPPass,SROAPass,SimplifyCFGPass