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

/* Variables and functions */
unsigned int atoi(char *);
int /*<<< orphan*/ free_regexp_matches(char **);
scalar_t__ regexp_match_grab(char const *, char const *, int, char **);
short int ipv4_ip2integer(const char *ip, unsigned long *ip_int) {
  char *matches[1 + 4];
  const char *pattern = "("
                        "[1-2]?[0-9]?[0-9]"
                        ")\\.("
                        "[1-2]?[0-9]?[0-9]"
                        ")\\.("
                        "[1-2]?[0-9]?[0-9]"
                        ")\\.("
                        "[1-2]?[0-9]?[0-9]"
                        ")";
  int i = 0;
  *ip_int = 0;
  if (regexp_match_grab(ip, pattern, 1, matches) != 0)
    return -1;
  for (i = 0; i <= 3; i++) {
    unsigned int byte = atoi(matches[i]);
    if (byte < 0 || byte > 255)
      return -2;
    *ip_int |= byte << (24 - (i * 8));
  }
  free_regexp_matches(matches);
  return 0;
}


x86 assembly (clang, -O0):
<ipv4_ip2integer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    0xeb9(%rip),%rax
mov    %rax,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x48(%rbp),%rsi
lea    -0x40(%rbp),%rcx
mov    $0x1,%edx
call   1030 <regexp_match_grab@plt>
cmp    $0x0,%rax
je     1188 <ipv4_ip2integer+0x58>
movw   $0xffff,-0x2(%rbp)
jmp    1209 <ipv4_ip2integer+0xd9>
movl   $0x0,-0x4c(%rbp)
cmpl   $0x3,-0x4c(%rbp)
jg     11fa <ipv4_ip2integer+0xca>
movslq -0x4c(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
call   1040 <atoi@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jb     11c1 <ipv4_ip2integer+0x91>
cmpl   $0xff,-0x50(%rbp)
jbe    11cc <ipv4_ip2integer+0x9c>
movw   $0xfffe,-0x2(%rbp)
jmp    1209 <ipv4_ip2integer+0xd9>
mov    -0x50(%rbp),%eax
mov    -0x4c(%rbp),%edx
shl    $0x3,%edx
mov    $0x18,%ecx
sub    %edx,%ecx
shl    %cl,%eax
mov    %eax,%eax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
or     (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    118f <ipv4_ip2integer+0x5f>
lea    -0x40(%rbp),%rdi
call   1050 <free_regexp_matches@plt>
movw   $0x0,-0x2(%rbp)
movswl -0x2(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ipv4_ip2integer>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%r14
movq   $0x0,(%rsi)
lea    0xeb7(%rip),%rsi
mov    %rsp,%rcx
mov    $0x1,%edx
call   1030 <regexp_match_grab@plt>
mov    $0xffff,%bp
test   %rax,%rax
jne    11d5 <ipv4_ip2integer+0xa5>
mov    (%rsp),%rdi
call   1040 <atoi@plt>
mov    $0xfffe,%bp
cmp    $0xff,%eax
ja     11d5 <ipv4_ip2integer+0xa5>
mov    %eax,%ebx
shl    $0x18,%ebx
or     (%r14),%rbx
mov    %rbx,(%r14)
mov    0x8(%rsp),%rdi
call   1040 <atoi@plt>
cmp    $0xff,%eax
ja     11d5 <ipv4_ip2integer+0xa5>
shl    $0x10,%eax
or     %rax,%rbx
mov    %rbx,(%r14)
mov    0x10(%rsp),%rdi
call   1040 <atoi@plt>
cmp    $0xff,%eax
ja     11d5 <ipv4_ip2integer+0xa5>
shl    $0x8,%eax
or     %rax,%rbx
mov    %rbx,(%r14)
mov    0x18(%rsp),%rdi
call   1040 <atoi@plt>
cmp    $0xff,%eax
ja     11d5 <ipv4_ip2integer+0xa5>
mov    %eax,%eax
or     %rax,%rbx
mov    %rbx,(%r14)
mov    %rsp,%rdi
call   1050 <free_regexp_matches@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [83 x i8] c"([1-2]?[0-9]?[0-9])\\.([1-2]?[0-9]?[0-9])\\.([1-2]?[0-9]?[0-9])\\.([1-2]?[0-9]?[0-9])\00"
define signext i16 @ipv4_ip2integer(i8* %0, i64* %1) {
%3 = alloca i16
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca [5 x i8*]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %4
store i64* %1, i64** %5
store i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i8** %7
store i32 0, i32* %8
%10 = load i64*, i64** %5
store i64 0, i64* %10
%11 = load i8*, i8** %4
%12 = load i8*, i8** %7
%13 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 0
%14 = call i64 @regexp_match_grab(i8* %11, i8* %12, i32 1, i8** %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %2
store i16 -1, i16* %3
br label %49
17: ; preds = %2
store i32 0, i32* %8
br label %18
18: ; preds = %43, %17
%19 = load i32, i32* %8
%20 = icmp sle i32 %19, 3
br i1 %20, label %21, label %46
21: ; preds = %18
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 %23
%25 = load i8*, i8** %24
%26 = call i32 @atoi(i8* %25)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp ult i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %21
%30 = load i32, i32* %9
%31 = icmp ugt i32 %30, 255
br i1 %31, label %32, label %33
32: ; preds = %29, %21
store i16 -2, i16* %3
br label %49
33: ; preds = %29
%34 = load i32, i32* %9
%35 = load i32, i32* %8
%36 = mul nsw i32 %35, 8
%37 = sub nsw i32 24, %36
%38 = shl i32 %34, %37
%39 = zext i32 %38 to i64
%40 = load i64*, i64** %5
%41 = load i64, i64* %40
%42 = or i64 %41, %39
store i64 %42, i64* %40
br label %43
43: ; preds = %33
%44 = load i32, i32* %8
%45 = add nsw i32 %44, 1
store i32 %45, i32* %8
br label %18
46: ; preds = %18
%47 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 0
%48 = call i32 @free_regexp_matches(i8** %47)
store i16 0, i16* %3
br label %49
49: ; preds = %46, %32, %16
%50 = load i16, i16* %3
ret i16 %50
}

LLVM IR (-O2):
@.str = [83 x i8] c"([1-2]?[0-9]?[0-9])\\.([1-2]?[0-9]?[0-9])\\.([1-2]?[0-9]?[0-9])\\.([1-2]?[0-9]?[0-9])\00"
define signext i16 @ipv4_ip2integer(i8* %0, i64* nocapture %1) {
%3 = alloca [5 x i8*]
%4 = bitcast [5 x i8*]* %3 to i8*
store i64 0, i64* %1
%5 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
%6 = call i64 @regexp_match_grab(i8* %0, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i32 1, i8** %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %41
8: ; preds = %2
%9 = load i8*, i8** %5
%10 = call i32 @atoi(i8* %9)
%11 = icmp ugt i32 %10, 255
br i1 %11, label %41, label %12
12: ; preds = %8
%13 = shl nuw i32 %10, 24
%14 = zext i32 %13 to i64
%15 = load i64, i64* %1
%16 = or i64 %15, %14
store i64 %16, i64* %1
%17 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @atoi(i8* %18)
%20 = icmp ugt i32 %19, 255
br i1 %20, label %41, label %21
21: ; preds = %12
%22 = shl nuw nsw i32 %19, 16
%23 = zext i32 %22 to i64
%24 = or i64 %16, %23
store i64 %24, i64* %1
%25 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
%28 = icmp ugt i32 %27, 255
br i1 %28, label %41, label %29
29: ; preds = %21
%30 = shl nuw nsw i32 %27, 8
%31 = zext i32 %30 to i64
%32 = or i64 %24, %31
store i64 %32, i64* %1
%33 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 3
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
%36 = icmp ugt i32 %35, 255
br i1 %36, label %41, label %37
37: ; preds = %29
%38 = zext i32 %35 to i64
%39 = or i64 %32, %38
store i64 %39, i64* %1
%40 = call i32 @free_regexp_matches(i8** %5)
br label %41
41: ; preds = %8, %12, %21, %29, %2, %37
%42 = phi i16 [ 0, %37 ], [ -1, %2 ], [ -2, %29 ], [ -2, %21 ], [ -2, %12 ], [ -2, %8 ]
ret i16 %42
}