#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 /*<<< orphan*/ words;

/* Variables and functions */
int atoi(char *);
int chopString(char *, char *, char **, int);
int /*<<< orphan*/ freez(char **);
int /*<<< orphan*/ isdigit(char);
int /*<<< orphan*/ notGoodSubnet(char *);
char *strdup(char *);
void netParseSubnet(char *in, unsigned char out[4]) {
  out[0] = out[1] = out[2] = out[3] = 255;
  if (in != NULL) {
    char *snsCopy = strdup(in);
    char *words[5];
    int wordCount, i;
    wordCount =
        chopString(snsCopy, ".", words, (sizeof(words) / sizeof((words)[0])));
    if (wordCount > 3 || wordCount < 1)
      notGoodSubnet(in);
    for (i = 0; i < wordCount; ++i) {
      char *s = words[i];
      int x;
      if (!isdigit(s[0]))
        notGoodSubnet(in);
      x = atoi(s);
      if (x > 255)
        notGoodSubnet(in);
      out[i] = x;
    }
    freez(&snsCopy);
  }
}


x86 assembly (clang, -O0):
<netParseSubnet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movb   $0xff,0x3(%rax)
mov    -0x10(%rbp),%rax
movb   $0xff,0x2(%rax)
mov    -0x10(%rbp),%rax
movb   $0xff,0x1(%rax)
mov    -0x10(%rbp),%rax
movb   $0xff,(%rax)
cmpq   $0x0,-0x8(%rbp)
je     1267 <netParseSubnet+0x107>
mov    -0x8(%rbp),%rdi
call   1080 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x40(%rbp),%rdx
lea    0xe4a(%rip),%rsi
mov    $0x5,%ecx
call   1030 <chopString@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x3,-0x44(%rbp)
jg     11d7 <netParseSubnet+0x77>
cmpl   $0x1,-0x44(%rbp)
jge    11e0 <netParseSubnet+0x80>
mov    -0x8(%rbp),%rdi
call   1050 <notGoodSubnet@plt>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    125e <netParseSubnet+0xfe>
movslq -0x48(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
movsbl (%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
jne    121e <netParseSubnet+0xbe>
mov    -0x8(%rbp),%rdi
call   1050 <notGoodSubnet@plt>
mov    -0x50(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xff,-0x54(%rbp)
jle    1240 <netParseSubnet+0xe0>
mov    -0x8(%rbp),%rdi
call   1050 <notGoodSubnet@plt>
mov    -0x54(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    11e7 <netParseSubnet+0x87>
lea    -0x18(%rbp),%rdi
call   1060 <freez@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netParseSubnet>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
movl   $0xffffffff,(%rsi)
test   %rdi,%rdi
je     121d <netParseSubnet+0xbd>
mov    %rsi,%r15
mov    %rdi,%r14
call   1080 <strdup@plt>
mov    %rax,0x8(%rsp)
lea    0xe6c(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rax,%rdi
mov    $0x5,%ecx
call   1030 <chopString@plt>
mov    %eax,%ebx
lea    -0x4(%rbx),%eax
cmp    $0xfffffffc,%eax
ja     11bc <netParseSubnet+0x5c>
mov    %r14,%rdi
call   1050 <notGoodSubnet@plt>
test   %ebx,%ebx
jle    1213 <netParseSubnet+0xb3>
mov    %ebx,%r12d
xor    %ebx,%ebx
jmp    11dd <netParseSubnet+0x7d>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %bpl,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
je     1213 <netParseSubnet+0xb3>
mov    0x10(%rsp,%rbx,8),%r13
movsbl 0x0(%r13),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
jne    11f8 <netParseSubnet+0x98>
mov    %r14,%rdi
call   1050 <notGoodSubnet@plt>
mov    %r13,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
cmp    $0x100,%eax
jl     11d0 <netParseSubnet+0x70>
mov    %r14,%rdi
call   1050 <notGoodSubnet@plt>
jmp    11d0 <netParseSubnet+0x70>
lea    0x8(%rsp),%rdi
call   1060 <freez@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
define void @netParseSubnet(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [5 x i8*]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 3
store i8 -1, i8* %12
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 2
store i8 -1, i8* %14
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 1
store i8 -1, i8* %16
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 0
store i8 -1, i8* %18
%19 = load i8*, i8** %3
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %73
21: ; preds = %2
%22 = load i8*, i8** %3
%23 = call i8* @strdup(i8* %22)
store i8* %23, i8** %5
%24 = load i8*, i8** %5
%25 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 0
%26 = call i32 @chopString(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %25, i32 5)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp sgt i32 %27, 3
br i1 %28, label %32, label %29
29: ; preds = %21
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 1
br i1 %31, label %32, label %35
32: ; preds = %29, %21
%33 = load i8*, i8** %3
%34 = call i32 @notGoodSubnet(i8* %33)
br label %35
35: ; preds = %32, %29
store i32 0, i32* %8
br label %36
36: ; preds = %68, %35
%37 = load i32, i32* %8
%38 = load i32, i32* %7
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %71
40: ; preds = %36
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [5 x i8*], [5 x i8*]* %6, i64 0, i64 %42
%44 = load i8*, i8** %43
store i8* %44, i8** %9
%45 = load i8*, i8** %9
%46 = getelementptr inbounds i8, i8* %45, i64 0
%47 = load i8, i8* %46
%48 = call i32 @isdigit(i8 signext %47)
%49 = icmp ne i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %40
%51 = load i8*, i8** %3
%52 = call i32 @notGoodSubnet(i8* %51)
br label %53
53: ; preds = %50, %40
%54 = load i8*, i8** %9
%55 = call i32 @atoi(i8* %54)
store i32 %55, i32* %10
%56 = load i32, i32* %10
%57 = icmp sgt i32 %56, 255
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = load i8*, i8** %3
%60 = call i32 @notGoodSubnet(i8* %59)
br label %61
61: ; preds = %58, %53
%62 = load i32, i32* %10
%63 = trunc i32 %62 to i8
%64 = load i8*, i8** %4
%65 = load i32, i32* %8
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
store i8 %63, i8* %67
br label %68
68: ; preds = %61
%69 = load i32, i32* %8
%70 = add nsw i32 %69, 1
store i32 %70, i32* %8
br label %36
71: ; preds = %36
%72 = call i32 @freez(i8** %5)
br label %73
73: ; preds = %71, %2
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
define void @netParseSubnet(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca i8*
%4 = alloca [5 x i8*]
%5 = icmp eq i8* %0, null
%6 = bitcast i8* %1 to i32*
store i32 -1, i32* %6
br i1 %5, label %41, label %7
7: ; preds = %2
%8 = bitcast i8** %3 to i8*
%9 = tail call i8* @strdup(i8* %0)
store i8* %9, i8** %3
%10 = bitcast [5 x i8*]* %4 to i8*
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 0
%12 = call i32 @chopString(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %11, i32 5)
%13 = add i32 %12, -4
%14 = icmp ult i32 %13, -3
br i1 %14, label %15, label %18
15: ; preds = %7
%16 = call i32 @notGoodSubnet(i8* %0)
%17 = icmp sgt i32 %12, 0
br i1 %17, label %18, label %39
18: ; preds = %7, %15
%19 = zext i32 %12 to i64
br label %20
20: ; preds = %18, %34
%21 = phi i64 [ 0, %18 ], [ %37, %34 ]
%22 = getelementptr inbounds [5 x i8*], [5 x i8*]* %4, i64 0, i64 %21
%23 = load i8*, i8** %22
%24 = load i8, i8* %23
%25 = call i32 @isdigit(i8 signext %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = call i32 @notGoodSubnet(i8* %0)
br label %29
29: ; preds = %27, %20
%30 = call i32 @atoi(i8* %23)
%31 = icmp sgt i32 %30, 255
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @notGoodSubnet(i8* %0)
br label %34
34: ; preds = %32, %29
%35 = trunc i32 %30 to i8
%36 = getelementptr inbounds i8, i8* %1, i64 %21
store i8 %35, i8* %36
%37 = add nuw nsw i64 %21, 1
%38 = icmp eq i64 %37, %19
br i1 %38, label %39, label %20
39: ; preds = %34, %15
%40 = call i32 @freez(i8** %3)
br label %41
41: ; preds = %39, %2
ret void
}