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

/* Variables and functions */
int REG_EXTENDED;
int REG_NOSUB;
int /*<<< orphan*/ STDERR_FILENO;
char *malloc(int);
scalar_t__ regcomp(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ regexec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                           int /*<<< orphan*/ *, int /*<<< orphan*/);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strtok_r(char *, char *, char **);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int);
int parse(char *buf, char *address) {
  if (buf == NULL)
    return -1;
  if (address == NULL)
    address = malloc(sizeof(char) * 17);
  regex_t pattern;
  char *str = NULL;
  char *buffer = malloc(sizeof(char) * strlen(buf));
  str = malloc(sizeof(char) * strlen(buf));
  strncpy(buffer, buf, strlen(buf));
  if (regcomp(&pattern,
              "^DST=(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-"
              "9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\."
              "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$",
              REG_NOSUB | REG_EXTENDED)) {
    write(STDERR_FILENO, "Ocurrio un error al armar la expresion regular\n",
          48);
    return -2;
  }
  for (str = strtok_r(buffer, " ", &buffer); str != NULL;
       str = strtok_r(NULL, " ", &buffer)) {
    if (!regexec(&pattern, str, 0, NULL, 0)) {
      strncpy(address, str + 4, strlen(str) - 4);
      *(address + strlen(str) - 3) = 0;
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1197 <parse+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    132c <parse+0x1bc>
cmpq   $0x0,-0x18(%rbp)
jne    11b0 <parse+0x40>
mov    $0x11,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edx
mov    0x2dac(%rip),%rax
or     (%rax),%edx
lea    -0x1c(%rbp),%rdi
lea    0xdcf(%rip),%rsi
call   1060 <regcomp@plt>
cmp    $0x0,%rax
je     1266 <parse+0xf6>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xe55(%rip),%rsi
mov    $0x30,%edx
call   1040 <write@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    132c <parse+0x1bc>
mov    -0x30(%rbp),%rdi
lea    0xe64(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1325 <parse+0x1b5>
mov    -0x28(%rbp),%rsi
lea    -0x1c(%rbp),%rdi
xor    %r8d,%r8d
xor    %eax,%eax
mov    %eax,%ecx
mov    %r8d,%edx
call   1090 <regexec@plt>
cmp    $0x0,%eax
jne    1303 <parse+0x193>
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
sub    $0x4,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
movb   $0x0,-0x3(%rax,%rcx,1)
movl   $0x1,-0x4(%rbp)
jmp    132c <parse+0x1bc>
jmp    1308 <parse+0x198>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc2(%rip),%rsi
lea    -0x30(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
jmp    127e <parse+0x10e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %rdi,%rdi
je     121c <parse+0xac>
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rsi,%rsi
jne    119f <parse+0x2f>
mov    $0x11,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,0x10(%rsp)
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    0x2e06(%rip),%rax
mov    0x2def(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe14(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1060 <regcomp@plt>
test   %rax,%rax
je     1232 <parse+0xc2>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
mov    $0x30,%edx
call   1040 <write@plt>
mov    $0xfffffffe,%ebp
jmp    1221 <parse+0xb1>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe9c(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r15,%rdi
call   1070 <strtok_r@plt>
test   %rax,%rax
je     128f <parse+0x11f>
mov    %rax,%rbx
lea    0xc(%rsp),%r15
lea    0xe7b(%rip),%r12
lea    0x10(%rsp),%r13
nop
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1090 <regexec@plt>
test   %eax,%eax
je     1293 <parse+0x123>
xor    %ebp,%ebp
xor    %edi,%edi
mov    %r12,%rsi
mov    %r13,%rdx
call   1070 <strtok_r@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1260 <parse+0xf0>
jmp    1221 <parse+0xb1>
xor    %ebp,%ebp
jmp    1221 <parse+0xb1>
lea    0x4(%rbx),%rbp
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    -0x4(%rax),%edx
mov    %r14,%rdi
mov    %rbp,%rsi
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x3(%r14,%rax,1)
mov    $0x1,%ebp
jmp    1221 <parse+0xb1>

LLVM IR (-O0):
@.str = [165 x i8] c"^DST=(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$\00"
@REG_NOSUB = global i32 0
@REG_EXTENDED = global i32 0
@STDERR_FILENO = global i32 0
@.str.1 = [48 x i8] c"Ocurrio un error al armar la expresion regular\0A\00"
@.str.2 = [2 x i8] c" \00"
define i32 @parse(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %71
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i8* @malloc(i32 17)
store i8* %16, i8** %5
br label %17
17: ; preds = %15, %12
store i8* null, i8** %7
%18 = load i8*, i8** %4
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = mul i64 1, %20
%22 = trunc i64 %21 to i32
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %8
%24 = load i8*, i8** %4
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = mul i64 1, %26
%28 = trunc i64 %27 to i32
%29 = call i8* @malloc(i32 %28)
store i8* %29, i8** %7
%30 = load i8*, i8** %8
%31 = load i8*, i8** %4
%32 = load i8*, i8** %4
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @strncpy(i8* %30, i8* %31, i32 %33)
%35 = load i32, i32* @REG_NOSUB
%36 = load i32, i32* @REG_EXTENDED
%37 = or i32 %35, %36
%38 = call i64 @regcomp(i32* %6, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str, i64 0, i64 0), i32 %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %17
%41 = load i32, i32* @STDERR_FILENO
%42 = call i32 @write(i32 %41, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 48)
store i32 -2, i32* %3
br label %71
43: ; preds = %17
%44 = load i8*, i8** %8
%45 = call i8* @strtok_r(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %8)
store i8* %45, i8** %7
br label %46
46: ; preds = %68, %43
%47 = load i8*, i8** %7
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %70
49: ; preds = %46
%50 = load i8*, i8** %7
%51 = call i32 @regexec(i32* %6, i8* %50, i32 0, i32* null, i32 0)
%52 = icmp ne i32 %51, 0
br i1 %52, label %67, label %53
53: ; preds = %49
%54 = load i8*, i8** %5
%55 = load i8*, i8** %7
%56 = getelementptr inbounds i8, i8* %55, i64 4
%57 = load i8*, i8** %7
%58 = call i32 @strlen(i8* %57)
%59 = sub nsw i32 %58, 4
%60 = call i32 @strncpy(i8* %54, i8* %56, i32 %59)
%61 = load i8*, i8** %5
%62 = load i8*, i8** %7
%63 = call i32 @strlen(i8* %62)
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %61, i64 %64
%66 = getelementptr inbounds i8, i8* %65, i64 -3
store i8 0, i8* %66
store i32 1, i32* %3
br label %71
67: ; preds = %49
br label %68
68: ; preds = %67
%69 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %8)
store i8* %69, i8** %7
br label %46
70: ; preds = %46
store i32 0, i32* %3
br label %71
71: ; preds = %70, %53, %40, %11
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@.str = [165 x i8] c"^DST=(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$\00"
@REG_NOSUB = global i32 0
@REG_EXTENDED = global i32 0
@STDERR_FILENO = global i32 0
@.str.1 = [48 x i8] c"Ocurrio un error al armar la expresion regular\0A\00"
@.str.2 = [2 x i8] c" \00"
define i32 @parse(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = icmp eq i8* %0, null
br i1 %5, label %48, label %6
6: ; preds = %2
%7 = icmp eq i8* %1, null
br i1 %7, label %8, label %10
8: ; preds = %6
%9 = tail call dereferenceable_or_null(17) i8* @malloc(i32 17)
br label %10
10: ; preds = %8, %6
%11 = phi i8* [ %9, %8 ], [ %1, %6 ]
%12 = bitcast i32* %3 to i8*
%13 = bitcast i8** %4 to i8*
%14 = tail call i32 @strlen(i8* %0)
%15 = tail call i8* @malloc(i32 %14)
store i8* %15, i8** %4
%16 = tail call i32 @strlen(i8* %0)
%17 = tail call i32 @strlen(i8* %0)
%18 = tail call i32 @strncpy(i8* %15, i8* %0, i32 %17)
%19 = load i32, i32* @REG_NOSUB
%20 = load i32, i32* @REG_EXTENDED
%21 = or i32 %20, %19
%22 = call i64 @regcomp(i32* %3, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %10
%25 = load i32, i32* @STDERR_FILENO
%26 = call i32 @write(i32 %25, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 48)
br label %46
27: ; preds = %10
%28 = call i8* @strtok_r(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %4)
%29 = icmp eq i8* %28, null
br i1 %29, label %46, label %30
30: ; preds = %27, %43
%31 = phi i8* [ %44, %43 ], [ %28, %27 ]
%32 = call i32 @regexec(i32* %3, i8* %31, i32 0, i32* null, i32 0)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %43
34: ; preds = %30
%35 = getelementptr inbounds i8, i8* %31, i64 4
%36 = call i32 @strlen(i8* %31)
%37 = add nsw i32 %36, -4
%38 = call i32 @strncpy(i8* %11, i8* %35, i32 %37)
%39 = call i32 @strlen(i8* %31)
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %11, i64 %40
%42 = getelementptr inbounds i8, i8* %41, i64 -3
store i8 0, i8* %42
br label %46
43: ; preds = %30
%44 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %4)
%45 = icmp eq i8* %44, null
br i1 %45, label %46, label %30
46: ; preds = %43, %27, %34, %24
%47 = phi i32 [ -2, %24 ], [ 1, %34 ], [ 0, %27 ], [ 0, %43 ]
br label %48
48: ; preds = %2, %46
%49 = phi i32 [ %47, %46 ], [ -1, %2 ]
ret i32 %49
}