#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*/ regcomp(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ regexec(int /*<<< orphan*/ *, char const *, size_t,
                           int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ regfree(int /*<<< orphan*/ *);
bool validate_addr(const char *addr) {
  regex_t myregex;
  bool valid = false;
  regcomp(&myregex,
          "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-"
          "9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$",
          REG_EXTENDED | REG_NOSUB);
  if (!regexec(&myregex, addr, (size_t)0, NULL, 0)) {
    valid = true;
  }
  regfree(&myregex);
  return valid;
}


x86 assembly (clang, -O0):
<validate_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%edx
mov    0x2e8d(%rip),%rax
or     (%rax),%edx
lea    -0xc(%rbp),%rdi
lea    0xea0(%rip),%rsi
call   1040 <regcomp@plt>
mov    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
xor    %r8d,%r8d
mov    %rcx,%rdx
call   1050 <regexec@plt>
cmp    $0x0,%eax
jne    118c <validate_addr+0x5c>
movl   $0x1,-0x10(%rbp)
lea    -0xc(%rbp),%rdi
call   1030 <regfree@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_addr>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e9a(%rip),%rax
mov    0x2e9b(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xeb0(%rip),%rsi
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <regcomp@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <regexec@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
mov    %r14,%rdi
call   1030 <regfree@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [106 x i8] c"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$\00"
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
define i32 @validate_addr(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
%5 = load i32, i32* @REG_EXTENDED
%6 = load i32, i32* @REG_NOSUB
%7 = or i32 %5, %6
%8 = call i32 @regcomp(i32* %3, i8* getelementptr inbounds ([106 x i8], [106 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i8*, i8** %2
%10 = call i32 @regexec(i32* %3, i8* %9, i64 0, i32* null, i32 0)
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %1
store i32 1, i32* %4
br label %13
13: ; preds = %12, %1
%14 = call i32 @regfree(i32* %3)
%15 = load i32, i32* %4
ret i32 %15
}

LLVM IR (-O2):
@.str = [106 x i8] c"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$\00"
@REG_EXTENDED = global i32 0
@REG_NOSUB = global i32 0
define i32 @validate_addr(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @REG_EXTENDED
%5 = load i32, i32* @REG_NOSUB
%6 = or i32 %5, %4
%7 = call i32 @regcomp(i32* %2, i8* getelementptr inbounds ([106 x i8], [106 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 @regexec(i32* %2, i8* %0, i64 0, i32* null, i32 0)
%9 = icmp eq i32 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @regfree(i32* %2)
ret i32 %10
}