#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ __ebt_print_error(char *, char *);
scalar_t__ ip_mask(char *, unsigned char *);
char *strrchr(char *, char);
scalar_t__ undot_ip(char *, unsigned char *);
void ebt_parse_ip_address(char *address, uint32_t *addr, uint32_t *msk) {
  char *p;
  if ((p = strrchr(address, '/')) != NULL) {
    *p = '\0';
    if (ip_mask(p + 1, (unsigned char *)msk)) {
      __ebt_print_error("Problem with the IP mask '%s'", p + 1);
      ;
      return;
    }
  } else
    *msk = 0xFFFFFFFF;
  if (undot_ip(address, (unsigned char *)addr)) {
    __ebt_print_error("Problem with the IP address '%s'", address);
    ;
    return;
  }
  *addr = *addr & *msk;
}


x86 assembly (clang, -O0):
<ebt_parse_ip_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11b0 <ebt_parse_ip_address+0x70>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
call   1030 <ip_mask@plt>
cmp    $0x0,%rax
je     11ab <ebt_parse_ip_address+0x6b>
mov    -0x20(%rbp),%rsi
add    $0x1,%rsi
lea    0xe5f(%rip),%rdi
call   1060 <__ebt_print_error@plt>
jmp    11f8 <ebt_parse_ip_address+0xb8>
jmp    11ba <ebt_parse_ip_address+0x7a>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <undot_ip@plt>
cmp    $0x0,%rax
je     11e6 <ebt_parse_ip_address+0xa6>
mov    -0x8(%rbp),%rsi
lea    0xe42(%rip),%rdi
call   1060 <__ebt_print_error@plt>
jmp    11f8 <ebt_parse_ip_address+0xb8>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
and    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ebt_parse_ip_address>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
mov    $0x2f,%esi
call   1040 <strrchr@plt>
test   %rax,%rax
je     1186 <ebt_parse_ip_address+0x46>
mov    %rax,%rbx
movb   $0x0,(%rax)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <ip_mask@plt>
test   %rax,%rax
je     118d <ebt_parse_ip_address+0x4d>
lea    0xe7f(%rip),%rdi
mov    %rbx,%rsi
jmp    11a7 <ebt_parse_ip_address+0x67>
movl   $0xffffffff,(%r15)
mov    %r12,%rdi
mov    %r14,%rsi
call   1050 <undot_ip@plt>
test   %rax,%rax
je     11b7 <ebt_parse_ip_address+0x77>
lea    0xe7a(%rip),%rdi
mov    %r12,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <__ebt_print_error@plt>
mov    (%r15),%eax
and    %eax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Problem with the IP mask '%s'\00"
@.str.1 = [33 x i8] c"Problem with the IP address '%s'\00"
define void @ebt_parse_ip_address(i8* %0, i32* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%8 = load i8*, i8** %4
%9 = call i8* @strrchr(i8* %8, i8 signext 47)
store i8* %9, i8** %7
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %24
11: ; preds = %3
%12 = load i8*, i8** %7
store i8 0, i8* %12
%13 = load i8*, i8** %7
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i32*, i32** %6
%16 = bitcast i32* %15 to i8*
%17 = call i64 @ip_mask(i8* %14, i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %11
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = call i32 @__ebt_print_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %42
23: ; preds = %11
br label %26
24: ; preds = %3
%25 = load i32*, i32** %6
store i32 -1, i32* %25
br label %26
26: ; preds = %24, %23
%27 = load i8*, i8** %4
%28 = load i32*, i32** %5
%29 = bitcast i32* %28 to i8*
%30 = call i64 @undot_ip(i8* %27, i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i8*, i8** %4
%34 = call i32 @__ebt_print_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %33)
br label %42
35: ; preds = %26
%36 = load i32*, i32** %5
%37 = load i32, i32* %36
%38 = load i32*, i32** %6
%39 = load i32, i32* %38
%40 = and i32 %37, %39
%41 = load i32*, i32** %5
store i32 %40, i32* %41
br label %42
42: ; preds = %35, %32, %19
ret void
}

LLVM IR (-O2):
@.str = [30 x i8] c"Problem with the IP mask '%s'\00"
@.str.1 = [33 x i8] c"Problem with the IP address '%s'\00"
define void @ebt_parse_ip_address(i8* %0, i32* %1, i32* %2) {
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%5 = icmp eq i8* %4, null
br i1 %5, label %13, label %6
6: ; preds = %3
store i8 0, i8* %4
%7 = getelementptr inbounds i8, i8* %4, i64 1
%8 = bitcast i32* %2 to i8*
%9 = tail call i64 @ip_mask(i8* %7, i8* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = tail call i32 @__ebt_print_error(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %24
13: ; preds = %3
store i32 -1, i32* %2
br label %14
14: ; preds = %6, %13
%15 = bitcast i32* %1 to i8*
%16 = tail call i64 @undot_ip(i8* %0, i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = tail call i32 @__ebt_print_error(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %24
20: ; preds = %14
%21 = load i32, i32* %1
%22 = load i32, i32* %2
%23 = and i32 %22, %21
store i32 %23, i32* %1
br label %24
24: ; preds = %20, %18, %11
ret void
}