#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 /*<<< orphan*/ u_int64_t;

/* Variables and functions */
int AF_INET;
int AF_INET6;
int inet_pton(int, char *, void *);
scalar_t__ isspace(char);
char *strchr(char *, char);
char *strpbrk(char *, char *);
size_t strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ strtouq(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ warnx(char *, char *);
u_int64_t ip_addrparser(char *buf, void *key, size_t *prefixlen, void *arg) {
  int af;
  char *cp, *ap;
  size_t len;
  u_int64_t cnt;
  cp = buf;
  while (isspace(*cp))
    cp++;
  if (*cp == '\0' || *cp == '%')
    return (0);
  ap = cp;
  if ((cp = strchr(ap, '/')) != NULL) {
    *cp++ = '\0';
    len = strtol(cp, NULL, 0);
  } else {
    cp = ap;
    len = 128;
  }
  cp = strpbrk(cp, " \t");
  if (cp == NULL)
    return (0);
  *cp++ = '\0';
  while (isspace(*cp))
    cp++;
  cnt = strtouq(cp, NULL, 0);
  if (strchr(ap, ':') != NULL)
    af = AF_INET6;
  else if (strchr(ap, '.') != NULL) {
    af = AF_INET;
    if (len == 128)
      len = 32;
  } else {
    warnx("not ip: %s", buf);
    return (0);
  }
  if (inet_pton(af, ap, key) != 1) {
    warnx("inet_pton: %s", buf);
    return (0);
  }
  *prefixlen = len;
  if (arg != NULL) {
    if (af == AF_INET6)
      *(int *)arg = 1;
    else
      *(int *)arg = 0;
  }
  return (cnt);
}


x86 assembly (clang, -O0):
<ip_addrparser>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
je     11b7 <ip_addrparser+0x47>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    1190 <ip_addrparser+0x20>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d7 <ip_addrparser+0x67>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x25,%eax
jne    11e3 <ip_addrparser+0x73>
movl   $0x0,-0x4(%rbp)
jmp    13c1 <ip_addrparser+0x251>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1231 <ip_addrparser+0xc1>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %rax,-0x48(%rbp)
jmp    1241 <ip_addrparser+0xd1>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
movq   $0x80,-0x48(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xdb4(%rip),%rsi
call   1090 <strpbrk@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    126c <ip_addrparser+0xfc>
movl   $0x0,-0x4(%rbp)
jmp    13c1 <ip_addrparser+0x251>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movb   $0x0,(%rax)
mov    -0x38(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isspace@plt>
cmp    $0x0,%rax
je     12a5 <ip_addrparser+0x135>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    127e <ip_addrparser+0x10e>
mov    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1030 <strtouq@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     12e0 <ip_addrparser+0x170>
mov    0x2d0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
jmp    1340 <ip_addrparser+0x1d0>
mov    -0x40(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     131f <ip_addrparser+0x1af>
mov    0x2ce9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
cmpq   $0x80,-0x48(%rbp)
jne    131a <ip_addrparser+0x1aa>
movq   $0x20,-0x48(%rbp)
jmp    133b <ip_addrparser+0x1cb>
mov    -0x10(%rbp),%rsi
lea    0xcd9(%rip),%rdi
call   1050 <warnx@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c1 <ip_addrparser+0x251>
jmp    1340 <ip_addrparser+0x1d0>
mov    -0x2c(%rbp),%edi
mov    -0x40(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1080 <inet_pton@plt>
cmp    $0x1,%eax
je     1375 <ip_addrparser+0x205>
mov    -0x10(%rbp),%rsi
lea    0xcaa(%rip),%rdi
call   1050 <warnx@plt>
movl   $0x0,-0x4(%rbp)
jmp    13c1 <ip_addrparser+0x251>
mov    -0x48(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     13bb <ip_addrparser+0x24b>
mov    -0x2c(%rbp),%eax
mov    0x2c4b(%rip),%rcx
cmp    (%rcx),%eax
jne    13ac <ip_addrparser+0x23c>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
jmp    13b6 <ip_addrparser+0x246>
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
jmp    13bb <ip_addrparser+0x24b>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_addrparser>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r14
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r13
lea    -0x1(%rdi),%rbx
xchg   %ax,%ax
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1060 <isspace@plt>
test   %rax,%rax
jne    1190 <ip_addrparser+0x20>
mov    (%rbx),%al
xor    %r15d,%r15d
test   %al,%al
je     12f5 <ip_addrparser+0x185>
cmp    $0x25,%al
je     12f5 <ip_addrparser+0x185>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
test   %rax,%rax
mov    %r14,0x8(%rsp)
mov    %rbp,0x10(%rsp)
je     11ef <ip_addrparser+0x7f>
mov    %rax,%rbp
add    $0x1,%rbp
movb   $0x0,(%rax)
mov    %rbp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %rax,(%rsp)
jmp    11fb <ip_addrparser+0x8b>
mov    $0x80,%eax
mov    %rax,(%rsp)
mov    %rbx,%rbp
lea    0xdfe(%rip),%rsi
mov    %rbp,%rdi
call   1090 <strpbrk@plt>
test   %rax,%rax
je     12f5 <ip_addrparser+0x185>
mov    %rax,%r14
movb   $0x0,(%rax)
nopl   0x0(%rax)
movsbl 0x1(%r14),%edi
add    $0x1,%r14
call   1060 <isspace@plt>
test   %rax,%rax
jne    1220 <ip_addrparser+0xb0>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <strtouq@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1262 <ip_addrparser+0xf2>
mov    0x2d85(%rip),%rax
mov    0x8(%rsp),%r14
jmp    1298 <ip_addrparser+0x128>
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
mov    0x8(%rsp),%r14
je     12da <ip_addrparser+0x16a>
mov    (%rsp),%rcx
cmp    $0x80,%rcx
mov    $0x20,%eax
cmove  %rax,%rcx
mov    %rcx,(%rsp)
mov    0x2d50(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1080 <inet_pton@plt>
cmp    $0x1,%eax
jne    12d1 <ip_addrparser+0x161>
mov    0x10(%rsp),%rax
mov    (%rsp),%rcx
mov    %rcx,(%rax)
test   %r14,%r14
je     12f5 <ip_addrparser+0x185>
mov    0x2d1c(%rip),%rax
cmp    (%rax),%ebp
jne    12ee <ip_addrparser+0x17e>
movl   $0x1,(%r14)
jmp    12f5 <ip_addrparser+0x185>
lea    0xd36(%rip),%rdi
jmp    12e1 <ip_addrparser+0x171>
lea    0xd22(%rip),%rdi
mov    %r13,%rsi
call   1050 <warnx@plt>
xor    %r15d,%r15d
jmp    12f5 <ip_addrparser+0x185>
movl   $0x0,(%r14)
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c" \09\00"
@AF_INET6 = global i32 0
@AF_INET = global i32 0
@.str.1 = [11 x i8] c"not ip: %s\00"
@.str.2 = [14 x i8] c"inet_pton: %s\00"
define i32 @ip_addrparser(i8* %0, i8* %1, i64* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i64* %2, i64** %8
store i8* %3, i8** %9
%15 = load i8*, i8** %6
store i8* %15, i8** %11
br label %16
16: ; preds = %21, %4
%17 = load i8*, i8** %11
%18 = load i8, i8* %17
%19 = call i64 @isspace(i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i8*, i8** %11
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %11
br label %16
24: ; preds = %16
%25 = load i8*, i8** %11
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %24
%30 = load i8*, i8** %11
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 37
br i1 %33, label %34, label %35
34: ; preds = %29, %24
store i32 0, i32* %5
br label %113
35: ; preds = %29
%36 = load i8*, i8** %11
store i8* %36, i8** %12
%37 = load i8*, i8** %12
%38 = call i8* @strchr(i8* %37, i8 signext 47)
store i8* %38, i8** %11
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = load i8*, i8** %11
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %11
store i8 0, i8* %41
%43 = load i8*, i8** %11
%44 = call i64 @strtol(i8* %43, i32* null, i32 0)
store i64 %44, i64* %13
br label %47
45: ; preds = %35
%46 = load i8*, i8** %12
store i8* %46, i8** %11
store i64 128, i64* %13
br label %47
47: ; preds = %45, %40
%48 = load i8*, i8** %11
%49 = call i8* @strpbrk(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %49, i8** %11
%50 = load i8*, i8** %11
%51 = icmp eq i8* %50, null
br i1 %51, label %52, label %53
52: ; preds = %47
store i32 0, i32* %5
br label %113
53: ; preds = %47
%54 = load i8*, i8** %11
%55 = getelementptr inbounds i8, i8* %54, i32 1
store i8* %55, i8** %11
store i8 0, i8* %54
br label %56
56: ; preds = %61, %53
%57 = load i8*, i8** %11
%58 = load i8, i8* %57
%59 = call i64 @isspace(i8 signext %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %56
%62 = load i8*, i8** %11
%63 = getelementptr inbounds i8, i8* %62, i32 1
store i8* %63, i8** %11
br label %56
64: ; preds = %56
%65 = load i8*, i8** %11
%66 = call i32 @strtouq(i8* %65, i32* null, i32 0)
store i32 %66, i32* %14
%67 = load i8*, i8** %12
%68 = call i8* @strchr(i8* %67, i8 signext 58)
%69 = icmp ne i8* %68, null
br i1 %69, label %70, label %72
70: ; preds = %64
%71 = load i32, i32* @AF_INET6
store i32 %71, i32* %10
br label %86
72: ; preds = %64
%73 = load i8*, i8** %12
%74 = call i8* @strchr(i8* %73, i8 signext 46)
%75 = icmp ne i8* %74, null
br i1 %75, label %76, label %82
76: ; preds = %72
%77 = load i32, i32* @AF_INET
store i32 %77, i32* %10
%78 = load i64, i64* %13
%79 = icmp eq i64 %78, 128
br i1 %79, label %80, label %81
80: ; preds = %76
store i64 32, i64* %13
br label %81
81: ; preds = %80, %76
br label %85
82: ; preds = %72
%83 = load i8*, i8** %6
%84 = call i32 @warnx(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %83)
store i32 0, i32* %5
br label %113
85: ; preds = %81
br label %86
86: ; preds = %85, %70
%87 = load i32, i32* %10
%88 = load i8*, i8** %12
%89 = load i8*, i8** %7
%90 = call i32 @inet_pton(i32 %87, i8* %88, i8* %89)
%91 = icmp ne i32 %90, 1
br i1 %91, label %92, label %95
92: ; preds = %86
%93 = load i8*, i8** %6
%94 = call i32 @warnx(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %93)
store i32 0, i32* %5
br label %113
95: ; preds = %86
%96 = load i64, i64* %13
%97 = load i64*, i64** %8
store i64 %96, i64* %97
%98 = load i8*, i8** %9
%99 = icmp ne i8* %98, null
br i1 %99, label %100, label %111
100: ; preds = %95
%101 = load i32, i32* %10
%102 = load i32, i32* @AF_INET6
%103 = icmp eq i32 %101, %102
br i1 %103, label %104, label %107
104: ; preds = %100
%105 = load i8*, i8** %9
%106 = bitcast i8* %105 to i32*
store i32 1, i32* %106
br label %110
107: ; preds = %100
%108 = load i8*, i8** %9
%109 = bitcast i8* %108 to i32*
store i32 0, i32* %109
br label %110
110: ; preds = %107, %104
br label %111
111: ; preds = %110, %95
%112 = load i32, i32* %14
store i32 %112, i32* %5
br label %113
113: ; preds = %111, %92, %82, %52, %34
%114 = load i32, i32* %5
ret i32 %114
}

LLVM IR (-O2):
@.str = [3 x i8] c" \09\00"
@AF_INET6 = global i32 0
@AF_INET = global i32 0
@.str.1 = [11 x i8] c"not ip: %s\00"
@.str.2 = [14 x i8] c"inet_pton: %s\00"
define i32 @ip_addrparser(i8* %0, i8* %1, i64* nocapture writeonly %2, i8* writeonly %3) {
br label %5
5: ; preds = %5, %4
%6 = phi i8* [ %0, %4 ], [ %10, %5 ]
%7 = load i8, i8* %6
%8 = tail call i64 @isspace(i8 signext %7)
%9 = icmp eq i64 %8, 0
%10 = getelementptr inbounds i8, i8* %6, i64 1
br i1 %9, label %11, label %5
11: ; preds = %5
%12 = load i8, i8* %6
switch i8 %12, label %13 [
i8 0, label %59
i8 37, label %59
]
13: ; preds = %11
%14 = tail call i8* @strchr(i8* %6, i8 signext 47)
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %14, i64 1
store i8 0, i8* %14
%18 = tail call i64 @strtol(i8* nocapture %17, i32* null, i32 0)
br label %19
19: ; preds = %13, %16
%20 = phi i8* [ %17, %16 ], [ %6, %13 ]
%21 = phi i64 [ %18, %16 ], [ 128, %13 ]
%22 = tail call i8* @strpbrk(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %59, label %24
24: ; preds = %19
store i8 0, i8* %22
br label %25
25: ; preds = %25, %24
%26 = phi i8* [ %22, %24 ], [ %27, %25 ]
%27 = getelementptr inbounds i8, i8* %26, i64 1
%28 = load i8, i8* %27
%29 = tail call i64 @isspace(i8 signext %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %25
31: ; preds = %25
%32 = tail call i32 @strtouq(i8* %27, i32* null, i32 0)
%33 = tail call i8* @strchr(i8* %6, i8 signext 58)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %43
35: ; preds = %31
%36 = tail call i8* @strchr(i8* %6, i8 signext 46)
%37 = icmp eq i8* %36, null
br i1 %37, label %41, label %38
38: ; preds = %35
%39 = icmp eq i64 %21, 128
%40 = select i1 %39, i64 32, i64 %21
br label %43
41: ; preds = %35
%42 = tail call i32 @warnx(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %59
43: ; preds = %31, %38
%44 = phi i32* [ @AF_INET, %38 ], [ @AF_INET6, %31 ]
%45 = phi i64 [ %40, %38 ], [ %21, %31 ]
%46 = load i32, i32* %44
%47 = tail call i32 @inet_pton(i32 %46, i8* %6, i8* %1)
%48 = icmp eq i32 %47, 1
br i1 %48, label %51, label %49
49: ; preds = %43
%50 = tail call i32 @warnx(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %59
51: ; preds = %43
store i64 %45, i64* %2
%52 = icmp eq i8* %3, null
br i1 %52, label %59, label %53
53: ; preds = %51
%54 = load i32, i32* @AF_INET6
%55 = icmp eq i32 %46, %54
%56 = bitcast i8* %3 to i32*
br i1 %55, label %57, label %58
57: ; preds = %53
store i32 1, i32* %56
br label %59
58: ; preds = %53
store i32 0, i32* %56
br label %59
59: ; preds = %51, %58, %57, %19, %11, %11, %49, %41
%60 = phi i32 [ 0, %49 ], [ 0, %41 ], [ 0, %11 ], [ 0, %11 ], [ 0, %19 ], [ %32, %57 ], [ %32, %58 ], [ %32, %51 ]
ret i32 %60
}