#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct in6_addr {
  int dummy;
};
struct sockaddr_in6 {
  struct in6_addr sin6_addr;
  int /*<<< orphan*/ sin6_family;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_INET6;
void *calloc(int, int);
int /*<<< orphan*/ htonl(unsigned long);
unsigned long mlfi_regex_ipv4_extract(char const *);
scalar_t__ mlfi_regex_ipv6_extract(char const *, struct in6_addr *);
int mlfi_regex_ipv46_extract(char const *pStr, struct sockaddr **ppSa) {
  int found = 0;
  if (pStr != NULL && *pStr && ppSa != NULL) {
    unsigned long ipv4 = mlfi_regex_ipv4_extract(pStr);
    if (ipv4 != 0) {
      struct sockaddr_in *pSa = calloc(1, sizeof(struct sockaddr_in));
      if (pSa != NULL) {
        pSa->sin_family = AF_INET;
        pSa->sin_addr.s_addr = htonl(ipv4);
        *ppSa = (struct sockaddr *)pSa;
        found = 1;
      }
    } else {
      struct in6_addr ipv6;
      if (mlfi_regex_ipv6_extract(pStr, &ipv6)) {
        struct sockaddr_in6 *pSa = calloc(1, sizeof(struct sockaddr_in6));
        if (pSa != NULL) {
          pSa->sin6_family = AF_INET6;
          pSa->sin6_addr = ipv6;
          *ppSa = (struct sockaddr *)pSa;
          found = 1;
        }
      }
    }
  }
  return found;
}


x86 assembly (clang, -O0):
<mlfi_regex_ipv46_extract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     125a <mlfi_regex_ipv46_extract+0x11a>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     125a <mlfi_regex_ipv46_extract+0x11a>
cmpq   $0x0,-0x10(%rbp)
je     125a <mlfi_regex_ipv46_extract+0x11a>
mov    -0x8(%rbp),%rdi
call   1060 <mlfi_regex_ipv4_extract@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11eb <mlfi_regex_ipv46_extract+0xab>
mov    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11e6 <mlfi_regex_ipv46_extract+0xa6>
mov    0x2e2e(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <htonl@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x14(%rbp)
jmp    1255 <mlfi_regex_ipv46_extract+0x115>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1050 <mlfi_regex_ipv6_extract@plt>
cmp    $0x0,%rax
je     1250 <mlfi_regex_ipv46_extract+0x110>
mov    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     124b <mlfi_regex_ipv46_extract+0x10b>
mov    0x2db9(%rip),%rax
mov    (%rax),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x38(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x14(%rbp)
jmp    1250 <mlfi_regex_ipv46_extract+0x110>
jmp    1255 <mlfi_regex_ipv46_extract+0x115>
jmp    125a <mlfi_regex_ipv46_extract+0x11a>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mlfi_regex_ipv46_extract>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %ebp,%ebp
test   %rdi,%rdi
je     11eb <mlfi_regex_ipv46_extract+0xab>
mov    %rsi,%r15
test   %rsi,%rsi
je     11eb <mlfi_regex_ipv46_extract+0xab>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11eb <mlfi_regex_ipv46_extract+0xab>
mov    %rbx,%rdi
call   1060 <mlfi_regex_ipv4_extract@plt>
test   %rax,%rax
je     11ac <mlfi_regex_ipv46_extract+0x6c>
mov    %rax,%r14
mov    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     11eb <mlfi_regex_ipv46_extract+0xab>
mov    %rax,%rbx
mov    0x2e50(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    %r14,%rdi
call   1030 <htonl@plt>
mov    %eax,(%rbx)
mov    %rbx,(%r15)
jmp    11e6 <mlfi_regex_ipv46_extract+0xa6>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1050 <mlfi_regex_ipv6_extract@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11eb <mlfi_regex_ipv46_extract+0xab>
mov    $0x1,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
test   %rax,%rax
je     11eb <mlfi_regex_ipv46_extract+0xab>
mov    0x2e07(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rax)
mov    (%rsp),%ecx
mov    %ecx,(%rax)
mov    %rax,(%r15)
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.in6_addr = type { i32 }
%struct.sockaddr_in6 = type { %struct.in6_addr, i32 }
@AF_INET = global i32 0
@AF_INET6 = global i32 0
define i32 @mlfi_regex_ipv46_extract(i8* %0, %struct.sockaddr** %1) {
%3 = alloca i8*
%4 = alloca %struct.sockaddr**
%5 = alloca i32
%6 = alloca i64
%7 = alloca %struct.sockaddr_in*
%8 = alloca %struct.in6_addr
%9 = alloca %struct.sockaddr_in6*
store i8* %0, i8** %3
store %struct.sockaddr** %1, %struct.sockaddr*** %4
store i32 0, i32* %5
%10 = load i8*, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %66
12: ; preds = %2
%13 = load i8*, i8** %3
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %66
17: ; preds = %12
%18 = load %struct.sockaddr**, %struct.sockaddr*** %4
%19 = icmp ne %struct.sockaddr** %18, null
br i1 %19, label %20, label %66
20: ; preds = %17
%21 = load i8*, i8** %3
%22 = call i64 @mlfi_regex_ipv4_extract(i8* %21)
store i64 %22, i64* %6
%23 = load i64, i64* %6
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %43
25: ; preds = %20
%26 = call i8* @calloc(i32 1, i32 8)
%27 = bitcast i8* %26 to %struct.sockaddr_in*
store %struct.sockaddr_in* %27, %struct.sockaddr_in** %7
%28 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%29 = icmp ne %struct.sockaddr_in* %28, null
br i1 %29, label %30, label %42
30: ; preds = %25
%31 = load i32, i32* @AF_INET
%32 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %32, i32 0, i32 1
store i32 %31, i32* %33
%34 = load i64, i64* %6
%35 = call i32 @htonl(i64 %34)
%36 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %36, i32 0, i32 0
%38 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %37, i32 0, i32 0
store i32 %35, i32* %38
%39 = load %struct.sockaddr_in*, %struct.sockaddr_in** %7
%40 = bitcast %struct.sockaddr_in* %39 to %struct.sockaddr*
%41 = load %struct.sockaddr**, %struct.sockaddr*** %4
store %struct.sockaddr* %40, %struct.sockaddr** %41
store i32 1, i32* %5
br label %42
42: ; preds = %30, %25
br label %65
43: ; preds = %20
%44 = load i8*, i8** %3
%45 = call i64 @mlfi_regex_ipv6_extract(i8* %44, %struct.in6_addr* %8)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %64
47: ; preds = %43
%48 = call i8* @calloc(i32 1, i32 8)
%49 = bitcast i8* %48 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %49, %struct.sockaddr_in6** %9
%50 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%51 = icmp ne %struct.sockaddr_in6* %50, null
br i1 %51, label %52, label %63
52: ; preds = %47
%53 = load i32, i32* @AF_INET6
%54 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%55 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %54, i32 0, i32 1
store i32 %53, i32* %55
%56 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%57 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %56, i32 0, i32 0
%58 = bitcast %struct.in6_addr* %57 to i8*
%59 = bitcast %struct.in6_addr* %8 to i8*
%60 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %9
%61 = bitcast %struct.sockaddr_in6* %60 to %struct.sockaddr*
%62 = load %struct.sockaddr**, %struct.sockaddr*** %4
store %struct.sockaddr* %61, %struct.sockaddr** %62
store i32 1, i32* %5
br label %63
63: ; preds = %52, %47
br label %64
64: ; preds = %63, %43
br label %65
65: ; preds = %64, %42
br label %66
66: ; preds = %65, %17, %12, %2
%67 = load i32, i32* %5
ret i32 %67
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
%struct.in6_addr = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in6 = type { %struct.in6_addr, i32 }
@AF_INET = global i32 0
@AF_INET6 = global i32 0
define i32 @mlfi_regex_ipv46_extract(i8* %0, %struct.sockaddr** writeonly %1) {
%3 = alloca %struct.in6_addr
%4 = icmp eq i8* %0, null
br i1 %4, label %40, label %5
5: ; preds = %2
%6 = load i8, i8* %0
%7 = icmp ne i8 %6, 0
%8 = icmp ne %struct.sockaddr** %1, null
%9 = and i1 %8, %7
br i1 %9, label %10, label %40
10: ; preds = %5
%11 = tail call i64 @mlfi_regex_ipv4_extract(i8* %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %23, label %13
13: ; preds = %10
%14 = tail call dereferenceable_or_null(8) i8* @calloc(i32 1, i32 8)
%15 = bitcast i8* %14 to %struct.sockaddr_in*
%16 = icmp eq i8* %14, null
br i1 %16, label %40, label %17
17: ; preds = %13
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i64 0, i32 1
store i32 %18, i32* %19
%20 = tail call i32 @htonl(i64 %11)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i64 0, i32 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr** %1 to i8**
store i8* %14, i8** %22
br label %40
23: ; preds = %10
%24 = bitcast %struct.in6_addr* %3 to i8*
%25 = call i64 @mlfi_regex_ipv6_extract(i8* %0, %struct.in6_addr* %3)
%26 = icmp eq i64 %25, 0
br i1 %26, label %38, label %27
27: ; preds = %23
%28 = call dereferenceable_or_null(8) i8* @calloc(i32 1, i32 8)
%29 = icmp eq i8* %28, null
br i1 %29, label %38, label %30
30: ; preds = %27
%31 = bitcast i8* %28 to %struct.sockaddr_in6*
%32 = load i32, i32* @AF_INET6
%33 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %31, i64 0, i32 1
store i32 %32, i32* %33
%34 = getelementptr inbounds %struct.in6_addr, %struct.in6_addr* %3, i64 0, i32 0
%35 = bitcast i8* %28 to i32*
%36 = load i32, i32* %34
store i32 %36, i32* %35
%37 = bitcast %struct.sockaddr** %1 to i8**
store i8* %28, i8** %37
br label %38
38: ; preds = %27, %30, %23
%39 = phi i32 [ 0, %23 ], [ 1, %30 ], [ 0, %27 ]
br label %40
40: ; preds = %38, %17, %13, %5, %2
%41 = phi i32 [ 0, %5 ], [ 0, %2 ], [ %39, %38 ], [ 1, %17 ], [ 0, %13 ]
ret i32 %41
}