#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int u_int;
typedef int u_char;

/* Variables and functions */
int INADDRSZ;
int /*<<< orphan*/ memcpy(int *, int *, int);
char *strchr(char const *, int);
int inet_pton4(const char *src, u_char *dst) {
  static const char digits[] = "0123456789";
  int saw_digit, octets, ch;
  u_char tmp[INADDRSZ], *tp;
  saw_digit = 0;
  octets = 0;
  *(tp = tmp) = 0;
  while ((ch = *src++) != '\0') {
    const char *pch;
    if ((pch = strchr(digits, ch)) != NULL) {
      u_int new = *tp * 10 + (pch - digits);
      if (new > 255)
        return (0);
      if (!saw_digit) {
        if (++octets > 4)
          return (0);
        saw_digit = 1;
      }
      *tp = new;
    } else if (ch == '.' && saw_digit) {
      if (octets == 4)
        return (0);
      *++tp = 0;
      saw_digit = 0;
    } else
      return (0);
  }
  if (octets < 4)
    return (0);
  memcpy(dst, tmp, INADDRSZ);
  return (1);
}


x86 assembly (clang, -O0):
<inet_pton4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %eax,%ecx
mov    %rsp,%rax
mov    %rax,-0x30(%rbp)
lea    0xf(,%rcx,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,-0x58(%rbp)
mov    %rax,%rsp
mov    %rcx,-0x38(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    %rax,-0x40(%rbp)
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     12a3 <inet_pton4+0x183>
mov    -0x24(%rbp),%esi
lea    0xe61(%rip),%rdi
call   1030 <strchr@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     1233 <inet_pton4+0x113>
mov    -0x40(%rbp),%rax
imul   $0xa,(%rax),%eax
cltq
mov    -0x48(%rbp),%rcx
lea    0xe3a(%rip),%rdx
sub    %rdx,%rcx
add    %rcx,%rax
mov    %eax,-0x4c(%rbp)
cmpl   $0xff,-0x4c(%rbp)
jle    11ef <inet_pton4+0xcf>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    12e4 <inet_pton4+0x1c4>
cmpl   $0x0,-0x1c(%rbp)
jne    1225 <inet_pton4+0x105>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
cmp    $0x4,%eax
jle    121e <inet_pton4+0xfe>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    12e4 <inet_pton4+0x1c4>
movl   $0x1,-0x1c(%rbp)
mov    -0x4c(%rbp),%ecx
mov    -0x40(%rbp),%rax
mov    %ecx,(%rax)
jmp    129e <inet_pton4+0x17e>
cmpl   $0x2e,-0x24(%rbp)
jne    1286 <inet_pton4+0x166>
cmpl   $0x0,-0x1c(%rbp)
je     1286 <inet_pton4+0x166>
cmpl   $0x4,-0x20(%rbp)
jne    1264 <inet_pton4+0x144>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    12e4 <inet_pton4+0x1c4>
mov    -0x40(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x40(%rbp)
movl   $0x0,0x4(%rax)
movl   $0x0,-0x1c(%rbp)
jmp    1299 <inet_pton4+0x179>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    12e4 <inet_pton4+0x1c4>
jmp    129e <inet_pton4+0x17e>
jmp    1177 <inet_pton4+0x57>
cmpl   $0x4,-0x20(%rbp)
jge    12c0 <inet_pton4+0x1a0>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
jmp    12e4 <inet_pton4+0x1c4>
mov    -0x58(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    0x2d11(%rip),%rax
mov    (%rax),%edx
call   1040 <memcpy@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inet_pton4>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    0x2ea8(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
mov    %rcx,%rdx
sub    %rax,%rdx
mov    %rdx,%rsp
neg    %rax
movl   $0x0,(%rcx,%rax,1)
mov    (%rdi),%r13b
test   %r13b,%r13b
je     1244 <inet_pton4+0x124>
mov    %rdi,%rbx
mov    %rsi,-0x48(%rbp)
add    $0x1,%rbx
xor    %r14d,%r14d
lea    0xe83(%rip),%rcx
mov    %rdx,-0x40(%rbp)
mov    %rdx,%r15
mov    %rdx,-0x38(%rbp)
xor    %r12d,%r12d
movl   $0x0,-0x2c(%rbp)
jmp    11c4 <inet_pton4+0xa4>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%edx
mov    %edx,-0x2c(%rbp)
mov    -0x38(%rbp),%rax
mov    %r14d,(%rax)
mov    $0x1,%r12d
movzbl (%rbx),%r13d
add    $0x1,%rbx
test   %r13b,%r13b
je     1248 <inet_pton4+0x128>
movsbl %r13b,%esi
mov    $0xb,%edx
mov    %rcx,%r15
mov    %rcx,%rdi
call   1030 <memchr@plt>
test   %rax,%rax
je     1210 <inet_pton4+0xf0>
lea    (%r14,%r14,4),%ecx
sub    %r15d,%eax
lea    (%rax,%rcx,2),%r14d
xor    %eax,%eax
cmp    $0xff,%r14d
jg     126b <inet_pton4+0x14b>
mov    %r15,%rcx
test   %r12d,%r12d
jne    11a6 <inet_pton4+0x86>
mov    -0x2c(%rbp),%edx
cmp    $0x3,%edx
jle    11a0 <inet_pton4+0x80>
jmp    126b <inet_pton4+0x14b>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
test   %r12d,%r12d
je     126b <inet_pton4+0x14b>
cmp    $0x2e,%r13b
jne    126b <inet_pton4+0x14b>
cmpl   $0x4,-0x2c(%rbp)
je     126b <inet_pton4+0x14b>
mov    %r15,%rcx
mov    -0x38(%rbp),%rax
movl   $0x0,0x4(%rax)
add    $0x4,%rax
mov    %rax,-0x38(%rbp)
xor    %r14d,%r14d
xor    %r12d,%r12d
jmp    11b3 <inet_pton4+0x93>
xor    %eax,%eax
jmp    126b <inet_pton4+0x14b>
xor    %eax,%eax
cmpl   $0x4,-0x2c(%rbp)
jl     126b <inet_pton4+0x14b>
mov    0x2d89(%rip),%rax
mov    (%rax),%edx
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <memcpy@plt>
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@inet_pton4.digits = internal constant [11 x i8] c"0123456789\00"
@INADDRSZ = global i32 0
define i32 @inet_pton4(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i32*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%15 = load i32, i32* @INADDRSZ
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %9
%18 = alloca i32, i64 %16
store i64 %16, i64* %10
store i32 0, i32* %6
store i32 0, i32* %7
store i32* %18, i32** %11
store i32 0, i32* %18
br label %19
19: ; preds = %69, %2
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i8, i8* %20
%23 = sext i8 %22 to i32
store i32 %23, i32* %8
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %70
25: ; preds = %19
%26 = load i32, i32* %8
%27 = call i8* @strchr(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @inet_pton4.digits, i64 0, i64 0), i32 %26)
store i8* %27, i8** %12
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %54
29: ; preds = %25
%30 = load i32*, i32** %11
%31 = load i32, i32* %30
%32 = mul nsw i32 %31, 10
%33 = sext i32 %32 to i64
%34 = load i8*, i8** %12
%35 = ptrtoint i8* %34 to i64
%36 = sub i64 %35, ptrtoint ([11 x i8]* @inet_pton4.digits to i64)
%37 = add nsw i64 %33, %36
%38 = trunc i64 %37 to i32
store i32 %38, i32* %13
%39 = load i32, i32* %13
%40 = icmp sgt i32 %39, 255
br i1 %40, label %41, label %42
41: ; preds = %29
store i32 0, i32* %3
store i32 1, i32* %14
br label %78
42: ; preds = %29
%43 = load i32, i32* %6
%44 = icmp ne i32 %43, 0
br i1 %44, label %51, label %45
45: ; preds = %42
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
%48 = icmp sgt i32 %47, 4
br i1 %48, label %49, label %50
49: ; preds = %45
store i32 0, i32* %3
store i32 1, i32* %14
br label %78
50: ; preds = %45
store i32 1, i32* %6
br label %51
51: ; preds = %50, %42
%52 = load i32, i32* %13
%53 = load i32*, i32** %11
store i32 %52, i32* %53
br label %69
54: ; preds = %25
%55 = load i32, i32* %8
%56 = icmp eq i32 %55, 46
br i1 %56, label %57, label %67
57: ; preds = %54
%58 = load i32, i32* %6
%59 = icmp ne i32 %58, 0
br i1 %59, label %60, label %67
60: ; preds = %57
%61 = load i32, i32* %7
%62 = icmp eq i32 %61, 4
br i1 %62, label %63, label %64
63: ; preds = %60
store i32 0, i32* %3
store i32 1, i32* %14
br label %78
64: ; preds = %60
%65 = load i32*, i32** %11
%66 = getelementptr inbounds i32, i32* %65, i32 1
store i32* %66, i32** %11
store i32 0, i32* %66
store i32 0, i32* %6
br label %68
67: ; preds = %57, %54
store i32 0, i32* %3
store i32 1, i32* %14
br label %78
68: ; preds = %64
br label %69
69: ; preds = %68, %51
br label %19
70: ; preds = %19
%71 = load i32, i32* %7
%72 = icmp slt i32 %71, 4
br i1 %72, label %73, label %74
73: ; preds = %70
store i32 0, i32* %3
store i32 1, i32* %14
br label %78
74: ; preds = %70
%75 = load i32*, i32** %5
%76 = load i32, i32* @INADDRSZ
%77 = call i32 @memcpy(i32* %75, i32* %18, i32 %76)
store i32 1, i32* %3
store i32 1, i32* %14
br label %78
78: ; preds = %74, %73, %67, %63, %49, %41
%79 = load i8*, i8** %9
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
@inet_pton4.digits = internal constant [11 x i8] c"0123456789\00"
@INADDRSZ = global i32 0
define i32 @inet_pton4(i8* nocapture %0, i32* %1) {
%3 = load i32, i32* @INADDRSZ
%4 = zext i32 %3 to i64
%5 = alloca i32, i64 %4
store i32 0, i32* %5
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %53, label %8
8: ; preds = %2, %41
%9 = phi i32 [ %42, %41 ], [ 0, %2 ]
%10 = phi i8 [ %46, %41 ], [ %6, %2 ]
%11 = phi i8* [ %15, %41 ], [ %0, %2 ]
%12 = phi i32* [ %45, %41 ], [ %5, %2 ]
%13 = phi i32 [ %44, %41 ], [ 0, %2 ]
%14 = phi i32 [ %43, %41 ], [ 0, %2 ]
%15 = getelementptr inbounds i8, i8* %11, i64 1
%16 = sext i8 %10 to i32
%17 = tail call i8* @memchr(i8* dereferenceable(11) getelementptr inbounds ([11 x i8], [11 x i8]* @inet_pton4.digits, i64 0, i64 0), i32 %16, i64 11)
%18 = icmp eq i8* %17, null
br i1 %18, label %33, label %19
19: ; preds = %8
%20 = mul nsw i32 %9, 10
%21 = ptrtoint i8* %17 to i64
%22 = trunc i64 %21 to i32
%23 = sub i32 %22, ptrtoint ([11 x i8]* @inet_pton4.digits to i32)
%24 = add i32 %20, %23
%25 = icmp sgt i32 %24, 255
br i1 %25, label %53, label %26
26: ; preds = %19
%27 = icmp eq i32 %13, 0
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = add nsw i32 %14, 1
%30 = icmp sgt i32 %14, 3
br i1 %30, label %53, label %31
31: ; preds = %26, %28
%32 = phi i32 [ %14, %26 ], [ %29, %28 ]
store i32 %24, i32* %12
br label %41
33: ; preds = %8
%34 = icmp ne i8 %10, 46
%35 = icmp eq i32 %13, 0
%36 = or i1 %35, %34
%37 = icmp eq i32 %14, 4
%38 = select i1 %36, i1 true, i1 %37
br i1 %38, label %53, label %39
39: ; preds = %33
%40 = getelementptr inbounds i32, i32* %12, i64 1
store i32 0, i32* %40
br label %41
41: ; preds = %39, %31
%42 = phi i32 [ %24, %31 ], [ 0, %39 ]
%43 = phi i32 [ %32, %31 ], [ %14, %39 ]
%44 = phi i32 [ 1, %31 ], [ 0, %39 ]
%45 = phi i32* [ %12, %31 ], [ %40, %39 ]
%46 = load i8, i8* %15
%47 = icmp eq i8 %46, 0
br i1 %47, label %48, label %8
48: ; preds = %41
%49 = icmp slt i32 %43, 4
br i1 %49, label %53, label %50
50: ; preds = %48
%51 = load i32, i32* @INADDRSZ
%52 = call i32 @memcpy(i32* %1, i32* %5, i32 %51)
br label %53
53: ; preds = %28, %19, %33, %2, %48, %50
%54 = phi i32 [ 1, %50 ], [ 0, %48 ], [ 0, %2 ], [ 0, %33 ], [ 0, %19 ], [ 0, %28 ]
ret i32 %54
}