#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;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int atoi(char *);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, int *);
int ntohl(int);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char *, int);
int getabc(uint32_t *addr_base, int *addr_count, char *netaddr) {
  char *p, buf[256];
  int i, plen, alen;
  uint32_t base, mask;
  strncpy(buf, netaddr, sizeof(buf));
  buf[sizeof(buf) - 1] = 0;
  if ((p = strchr(buf, '/')) == NULL)
    return -1;
  *p = 0;
  plen = atoi(p + 1);
  alen = 32 - plen;
  if (plen > 24)
    return -1;
  if (inet_pton(AF_INET, buf, &base) < 0)
    return -1;
  for (i = 0, mask = 0; i < alen; i++)
    mask = (mask << 1) | 1;
  *addr_base = ntohl(base) & ~mask;
  *addr_count = 1 << alen;
  return 0;
}


x86 assembly (clang, -O0):
<getabc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x31(%rbp)
lea    -0x130(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11ab <getabc+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <getabc+0x157>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,-0x138(%rbp)
mov    $0x20,%eax
sub    -0x138(%rbp),%eax
mov    %eax,-0x13c(%rbp)
cmpl   $0x18,-0x138(%rbp)
jle    11ef <getabc+0x9f>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <getabc+0x157>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
lea    -0x130(%rbp),%rsi
lea    -0x140(%rbp),%rdx
call   1050 <inet_pton@plt>
cmp    $0x0,%rax
jge    1221 <getabc+0xd1>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a7 <getabc+0x157>
movl   $0x0,-0x134(%rbp)
movl   $0x0,-0x144(%rbp)
mov    -0x134(%rbp),%eax
cmp    -0x13c(%rbp),%eax
jge    126d <getabc+0x11d>
mov    -0x144(%rbp),%eax
shl    $0x1,%eax
or     $0x1,%eax
mov    %eax,-0x144(%rbp)
mov    -0x134(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x134(%rbp)
jmp    1235 <getabc+0xe5>
mov    -0x140(%rbp),%edi
call   1070 <ntohl@plt>
mov    %eax,%ecx
mov    -0x144(%rbp),%eax
xor    $0xffffffff,%eax
and    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x13c(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getabc>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %rdx,%rsi
mov    $0x100,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x10f(%rsp)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strchr@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     125e <getabc+0x10e>
movb   $0x0,(%rax)
add    $0x1,%rax
mov    %rax,%rdi
call   1060 <atoi@plt>
cmp    $0x18,%eax
jg     125e <getabc+0x10e>
mov    %eax,%ebx
mov    0x2e2c(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1050 <inet_pton@plt>
test   %rax,%rax
js     125e <getabc+0x10e>
mov    $0x20,%ebp
sub    %ebx,%ebp
cmp    $0x2,%ebp
mov    $0x1,%edx
cmovge %ebp,%edx
lea    -0x1(%rdx),%ecx
mov    %edx,%eax
and    $0x7,%eax
cmp    $0x7,%ecx
jae    11fd <getabc+0xad>
xor    %ecx,%ecx
test   %eax,%eax
jne    1230 <getabc+0xe0>
jmp    123f <getabc+0xef>
and    $0x7ffffff8,%edx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ecx,%ebx
shl    $0x8,%ebx
lea    0xff(%rbx),%ecx
add    $0xfffffff8,%edx
jne    1210 <getabc+0xc0>
or     $0xfe,%ebx
test   %eax,%eax
je     123f <getabc+0xef>
nopw   0x0(%rax,%rax,1)
mov    %ecx,%ebx
lea    (%rbx,%rbx,1),%ecx
add    $0x1,%ecx
add    $0xffffffff,%eax
jne    1230 <getabc+0xe0>
add    %ebx,%ebx
xor    $0xfffffffe,%ebx
mov    0xc(%rsp),%edi
call   1070 <ntohl@plt>
mov    $0x1,%edx
mov    %ebp,%ecx
shl    %cl,%edx
and    %ebx,%eax
mov    %eax,(%r15)
mov    %edx,(%r14)
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@AF_INET = global i32 0
define i32 @getabc(i32* %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%16 = load i8*, i8** %7
%17 = call i32 @strncpy(i8* %15, i8* %16, i32 256)
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 255
store i8 0, i8* %18
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%20 = call i8* @strchr(i8* %19, i8 signext 47)
store i8* %20, i8** %8
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %23
22: ; preds = %3
store i32 -1, i32* %4
br label %61
23: ; preds = %3
%24 = load i8*, i8** %8
store i8 0, i8* %24
%25 = load i8*, i8** %8
%26 = getelementptr inbounds i8, i8* %25, i64 1
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %11
%28 = load i32, i32* %11
%29 = sub nsw i32 32, %28
store i32 %29, i32* %12
%30 = load i32, i32* %11
%31 = icmp sgt i32 %30, 24
br i1 %31, label %32, label %33
32: ; preds = %23
store i32 -1, i32* %4
br label %61
33: ; preds = %23
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%36 = call i64 @inet_pton(i32 %34, i8* %35, i32* %13)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %33
store i32 -1, i32* %4
br label %61
39: ; preds = %33
store i32 0, i32* %10
store i32 0, i32* %14
br label %40
40: ; preds = %48, %39
%41 = load i32, i32* %10
%42 = load i32, i32* %12
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %51
44: ; preds = %40
%45 = load i32, i32* %14
%46 = shl i32 %45, 1
%47 = or i32 %46, 1
store i32 %47, i32* %14
br label %48
48: ; preds = %44
%49 = load i32, i32* %10
%50 = add nsw i32 %49, 1
store i32 %50, i32* %10
br label %40
51: ; preds = %40
%52 = load i32, i32* %13
%53 = call i32 @ntohl(i32 %52)
%54 = load i32, i32* %14
%55 = xor i32 %54, -1
%56 = and i32 %53, %55
%57 = load i32*, i32** %5
store i32 %56, i32* %57
%58 = load i32, i32* %12
%59 = shl i32 1, %58
%60 = load i32*, i32** %6
store i32 %59, i32* %60
store i32 0, i32* %4
br label %61
61: ; preds = %51, %38, %32, %22
%62 = load i32, i32* %4
ret i32 %62
}

LLVM IR (-O2):
@AF_INET = global i32 0
define i32 @getabc(i32* nocapture writeonly %0, i32* nocapture writeonly %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
%8 = call i32 @strncpy(i8* %6, i8* %2, i32 256)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 255
store i8 0, i8* %9
%10 = call i8* @strchr(i8* %6, i8 signext 47)
%11 = icmp eq i8* %10, null
br i1 %11, label %55, label %12
12: ; preds = %3
store i8 0, i8* %10
%13 = getelementptr inbounds i8, i8* %10, i64 1
%14 = call i32 @atoi(i8* %13)
%15 = sub i32 32, %14
%16 = icmp sgt i32 %14, 24
br i1 %16, label %55, label %17
17: ; preds = %12
%18 = load i32, i32* @AF_INET
%19 = call i64 @inet_pton(i32 %18, i8* %6, i32* %5)
%20 = icmp slt i64 %19, 0
br i1 %20, label %55, label %21
21: ; preds = %17
%22 = call i32 @llvm.smax.i32(i32 %15, i32 1)
%23 = add nsw i32 %22, -1
%24 = and i32 %22, 7
%25 = icmp ult i32 %23, 7
br i1 %25, label %37, label %26
26: ; preds = %21
%27 = and i32 %22, 2147483640
br label %28
28: ; preds = %28, %26
%29 = phi i32 [ 0, %26 ], [ %32, %28 ]
%30 = phi i32 [ 0, %26 ], [ %33, %28 ]
%31 = shl i32 %29, 8
%32 = or i32 %31, 255
%33 = add i32 %30, 8
%34 = icmp eq i32 %33, %27
br i1 %34, label %35, label %28
35: ; preds = %28
%36 = or i32 %31, 254
br label %37
37: ; preds = %35, %21
%38 = phi i32 [ undef, %21 ], [ %36, %35 ]
%39 = phi i32 [ 0, %21 ], [ %32, %35 ]
%40 = icmp eq i32 %24, 0
br i1 %40, label %48, label %41
41: ; preds = %37, %41
%42 = phi i32 [ %45, %41 ], [ %39, %37 ]
%43 = phi i32 [ %46, %41 ], [ 0, %37 ]
%44 = shl i32 %42, 1
%45 = or i32 %44, 1
%46 = add i32 %43, 1
%47 = icmp eq i32 %46, %24
br i1 %47, label %48, label %41
48: ; preds = %41, %37
%49 = phi i32 [ %38, %37 ], [ %44, %41 ]
%50 = xor i32 %49, -2
%51 = load i32, i32* %5
%52 = call i32 @ntohl(i32 %51)
%53 = and i32 %52, %50
store i32 %53, i32* %0
%54 = shl nuw i32 1, %15
store i32 %54, i32* %1
br label %55
55: ; preds = %17, %12, %3, %48
%56 = phi i32 [ 0, %48 ], [ -1, %3 ], [ -1, %12 ], [ -1, %17 ]
ret i32 %56
}