#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*/ exit(int);
scalar_t__ ip_mask(char *, unsigned char *);
int /*<<< orphan*/ printf(char *);
char *strrchr(char *, char);
scalar_t__ undot_ip(char *, unsigned char *);
void 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)) {
      printf("Problem with the IP mask");
      printf(".\n");
      exit(-1);
    };
  } else
    *msk = 0xFFFFFFFF;
  if (undot_ip(address, (unsigned char *)addr)) {
    printf("Problem with the IP address");
    printf(".\n");
    exit(-1);
  };
  *addr = *addr & *msk;
}


x86 assembly (clang, -O0):
<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   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11c9 <parse_ip_address+0x79>
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     11c4 <parse_ip_address+0x74>
lea    0xe57(%rip),%rdi
call   1040 <printf@plt>
lea    0xe64(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
jmp    11d3 <parse_ip_address+0x83>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <undot_ip@plt>
cmp    $0x0,%rax
je     120c <parse_ip_address+0xbc>
lea    0xe2b(%rip),%rdi
call   1040 <printf@plt>
lea    0xe1c(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
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):
<parse_ip_address>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     119d <parse_ip_address+0x3d>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <ip_mask@plt>
test   %rax,%rax
je     11a4 <parse_ip_address+0x44>
lea    0xe65(%rip),%rdi
jmp    11c7 <parse_ip_address+0x67>
movl   $0xffffffff,(%r15)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <undot_ip@plt>
test   %rax,%rax
jne    11c0 <parse_ip_address+0x60>
mov    (%r15),%eax
and    %eax,(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe52(%rip),%rdi
call   1050 <printf@plt>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Problem with the IP mask\00"
@.str.1 = [3 x i8] c".\0A\00"
@.str.2 = [28 x i8] c"Problem with the IP address\00"
define void @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 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%21 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
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 %36
32: ; preds = %26
%33 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %26
%37 = load i32*, i32** %5
%38 = load i32, i32* %37
%39 = load i32*, i32** %6
%40 = load i32, i32* %39
%41 = and i32 %38, %40
%42 = load i32*, i32** %5
store i32 %41, i32* %42
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"Problem with the IP mask\00"
@.str.2 = [28 x i8] c"Problem with the IP address\00"
@str.3 = [2 x i8] c".\00"
define void @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 %15, 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 %16, label %11
11: ; preds = %6
%12 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.3, i64 0, i64 0))
%14 = tail call i32 @exit(i32 -1)
unreachable
15: ; preds = %3
store i32 -1, i32* %2
br label %16
16: ; preds = %6, %15
%17 = bitcast i32* %1 to i8*
%18 = tail call i64 @undot_ip(i8* %0, i8* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %16
%21 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.3, i64 0, i64 0))
%23 = tail call i32 @exit(i32 -1)
unreachable
24: ; preds = %16
%25 = load i32, i32* %1
%26 = load i32, i32* %2
%27 = and i32 %26, %25
store i32 %27, i32* %1
ret void
}