#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;
scalar_t__ 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;
  char *str = NULL;
  char *buffer = (char *)malloc(sizeof(char) * strlen(buf));
  regex_t pattern;
  str = (char *)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)) {
      if (address == NULL)
        address = (char *)malloc(sizeof(char) * 17);
      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>
movq   $0x0,-0x20(%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    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x28(%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    0x2dde(%rip),%rax
mov    (%rax),%edx
mov    0x2dc5(%rip),%rax
or     (%rax),%edx
lea    -0x2c(%rbp),%rdi
lea    0xde8(%rip),%rsi
call   1060 <regcomp@plt>
cmp    $0x0,%rax
je     124d <parse+0xdd>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
mov    $0x30,%edx
call   1040 <write@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    132c <parse+0x1bc>
mov    -0x28(%rbp),%rdi
lea    0xe7d(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1325 <parse+0x1b5>
mov    -0x20(%rbp),%rsi
lea    -0x2c(%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>
cmpq   $0x0,-0x18(%rbp)
jne    12a9 <parse+0x139>
mov    $0x11,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%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    -0x20(%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    -0x28(%rbp),%rdx
call   1070 <strtok_r@plt>
mov    %rax,-0x20(%rbp)
jmp    1265 <parse+0xf5>
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     120e <parse+0x9e>
mov    %rsi,%r14
mov    %rdi,%rbx
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    %eax,%edi
call   1080 <malloc@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    0x2e14(%rip),%rax
mov    0x2dfd(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xe22(%rip),%rsi
lea    0xc(%rsp),%rdi
call   1060 <regcomp@plt>
test   %rax,%rax
je     1224 <parse+0xb4>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xea8(%rip),%rsi
mov    $0x30,%edx
call   1040 <write@plt>
mov    $0xfffffffe,%ebp
jmp    1213 <parse+0xa3>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xeaa(%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    0xe89(%rip),%r12
lea    0x10(%rsp),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
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    1213 <parse+0xa3>
xor    %ebp,%ebp
jmp    1213 <parse+0xa3>
test   %r14,%r14
jne    12a5 <parse+0x135>
mov    $0x11,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
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    1213 <parse+0xa3>

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 i8*
%7 = alloca i8*
%8 = alloca i32
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 %74
12: ; preds = %2
store i8* null, i8** %6
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = sext i32 %14 to i64
%16 = mul i64 1, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %7
%20 = load i8*, i8** %4
%21 = call i32 @strlen(i8* %20)
%22 = sext i32 %21 to i64
%23 = mul i64 1, %22
%24 = trunc i64 %23 to i32
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %6
%27 = load i8*, i8** %7
%28 = load i8*, i8** %4
%29 = load i8*, i8** %4
%30 = call i32 @strlen(i8* %29)
%31 = call i32 @strncpy(i8* %27, i8* %28, i32 %30)
%32 = load i32, i32* @REG_NOSUB
%33 = load i32, i32* @REG_EXTENDED
%34 = or i32 %32, %33
%35 = call i64 @regcomp(i32* %8, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = icmp ne i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %12
%38 = load i32, i32* @STDERR_FILENO
%39 = call i32 @write(i32 %38, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 48)
store i32 -2, i32* %3
br label %74
40: ; preds = %12
%41 = load i8*, i8** %7
%42 = call i8* @strtok_r(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %7)
store i8* %42, i8** %6
br label %43
43: ; preds = %71, %40
%44 = load i8*, i8** %6
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %73
46: ; preds = %43
%47 = load i8*, i8** %6
%48 = call i32 @regexec(i32* %8, i8* %47, i32 0, i32* null, i32 0)
%49 = icmp ne i32 %48, 0
br i1 %49, label %70, label %50
50: ; preds = %46
%51 = load i8*, i8** %5
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = call i64 @malloc(i32 17)
%55 = inttoptr i64 %54 to i8*
store i8* %55, i8** %5
br label %56
56: ; preds = %53, %50
%57 = load i8*, i8** %5
%58 = load i8*, i8** %6
%59 = getelementptr inbounds i8, i8* %58, i64 4
%60 = load i8*, i8** %6
%61 = call i32 @strlen(i8* %60)
%62 = sub nsw i32 %61, 4
%63 = call i32 @strncpy(i8* %57, i8* %59, i32 %62)
%64 = load i8*, i8** %5
%65 = load i8*, i8** %6
%66 = call i32 @strlen(i8* %65)
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8, i8* %64, i64 %67
%69 = getelementptr inbounds i8, i8* %68, i64 -3
store i8 0, i8* %69
store i32 1, i32* %3
br label %74
70: ; preds = %46
br label %71
71: ; preds = %70
%72 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %7)
store i8* %72, i8** %6
br label %43
73: ; preds = %43
store i32 0, i32* %3
br label %74
74: ; preds = %73, %56, %37, %11
%75 = load i32, i32* %3
ret i32 %75
}

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 i8*
%4 = alloca i32
%5 = icmp eq i8* %0, null
br i1 %5, label %51, label %6
6: ; preds = %2
%7 = bitcast i8** %3 to i8*
%8 = tail call i32 @strlen(i8* %0)
%9 = tail call i64 @malloc(i32 %8)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %3
%11 = bitcast i32* %4 to i8*
%12 = tail call i32 @strlen(i8* %0)
%13 = tail call i64 @malloc(i32 %12)
%14 = tail call i32 @strlen(i8* %0)
%15 = tail call i32 @strncpy(i8* %10, i8* %0, i32 %14)
%16 = load i32, i32* @REG_NOSUB
%17 = load i32, i32* @REG_EXTENDED
%18 = or i32 %17, %16
%19 = call i64 @regcomp(i32* %4, i8* getelementptr inbounds ([165 x i8], [165 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %6
%22 = load i32, i32* @STDERR_FILENO
%23 = call i32 @write(i32 %22, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.1, i64 0, i64 0), i32 48)
br label %49
24: ; preds = %6
%25 = call i8* @strtok_r(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %3)
%26 = icmp eq i8* %25, null
br i1 %26, label %49, label %27
27: ; preds = %24, %46
%28 = phi i8* [ %47, %46 ], [ %25, %24 ]
%29 = call i32 @regexec(i32* %4, i8* %28, i32 0, i32* null, i32 0)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %46
31: ; preds = %27
%32 = icmp eq i8* %1, null
br i1 %32, label %33, label %36
33: ; preds = %31
%34 = call i64 @malloc(i32 17)
%35 = inttoptr i64 %34 to i8*
br label %36
36: ; preds = %33, %31
%37 = phi i8* [ %35, %33 ], [ %1, %31 ]
%38 = getelementptr inbounds i8, i8* %28, i64 4
%39 = call i32 @strlen(i8* %28)
%40 = add nsw i32 %39, -4
%41 = call i32 @strncpy(i8* %37, i8* %38, i32 %40)
%42 = call i32 @strlen(i8* %28)
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %37, i64 %43
%45 = getelementptr inbounds i8, i8* %44, i64 -3
store i8 0, i8* %45
br label %49
46: ; preds = %27
%47 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8** %3)
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %27
49: ; preds = %46, %24, %36, %21
%50 = phi i32 [ -2, %21 ], [ 1, %36 ], [ 0, %24 ], [ 0, %46 ]
br label %51
51: ; preds = %2, %49
%52 = phi i32 [ %50, %49 ], [ -1, %2 ]
ret i32 %52
}