#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*/ AF_INET;
int atoi(char *);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int *);
int ntohl(int);
scalar_t__ strchr(char *, char);
uint32_t parse_mask(char *str) {
  uint32_t mask;
  int shift;
  if (strchr(str, '.')) {
    inet_pton(AF_INET, str, &mask);
    return ntohl(mask);
  } else {
    shift = atoi(str);
    return (0xFFFFFFFF << (32 - shift));
  }
}


x86 assembly (clang, -O0):
<parse_mask>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     118a <parse_mask+0x4a>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1040 <inet_pton@plt>
mov    -0x14(%rbp),%edi
call   1060 <ntohl@plt>
mov    %eax,-0x4(%rbp)
jmp    11a8 <parse_mask+0x68>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    $0x20,%ecx
sub    -0x18(%rbp),%ecx
mov    $0xffffffff,%eax
shl    %cl,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_mask>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1178 <parse_mask+0x38>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rdx
mov    %rbx,%rsi
call   1040 <inet_pton@plt>
mov    0xc(%rsp),%edi
call   1060 <ntohl@plt>
jmp    118b <parse_mask+0x4b>
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
neg    %cl
mov    $0xffffffff,%eax
shl    %cl,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@AF_INET = global i32 0
define i32 @parse_mask(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @strchr(i8* %6, i8 signext 46)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = load i32, i32* @AF_INET
%11 = load i8*, i8** %3
%12 = call i32 @inet_pton(i32 %10, i8* %11, i32* %4)
%13 = load i32, i32* %4
%14 = call i32 @ntohl(i32 %13)
store i32 %14, i32* %2
br label %21
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = sub nsw i32 32, %18
%20 = shl i32 -1, %19
store i32 %20, i32* %2
br label %21
21: ; preds = %15, %9
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
@AF_INET = global i32 0
define i32 @parse_mask(i8* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i64 @strchr(i8* %0, i8 signext 46)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = load i32, i32* @AF_INET
%8 = call i32 @inet_pton(i32 %7, i8* %0, i32* %2)
%9 = load i32, i32* %2
%10 = call i32 @ntohl(i32 %9)
br label %15
11: ; preds = %1
%12 = tail call i32 @atoi(i8* %0)
%13 = sub nsw i32 32, %12
%14 = shl nsw i32 -1, %13
br label %15
15: ; preds = %11, %6
%16 = phi i32 [ %10, %6 ], [ %14, %11 ]
ret i32 %16
}