#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 */

/* Variables and functions */
int atoi(char const *);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
unsigned char IpLegal(unsigned char *buf, unsigned short bufSize) {
  unsigned char *p = buf;
  unsigned short i = 0, j = 0;
  unsigned char delimCnt = 0;
  unsigned char value[10] = {0};
  for (i = 0; i < bufSize; p++, i++) {
    if (*p == '.') {
      delimCnt++;
      if (atoi((const char *)value) > 255 ||
          (delimCnt == 1 ? (atoi((const char *)value) == 0) : 1)) {
        return 0x01;
      }
      j = 0;
      memset(value, 0, 10);
    } else if (((unsigned)((*p) - '0') < 10)) {
      value[j] = *p;
      j++;
    } else {
      return 0x01;
    }
  }
  if (delimCnt != 3)
    return 0x01;
  if (atoi((const char *)value) > 255) {
    return 0x01;
  }
  return 0x00;
}


x86 assembly (clang, -O0):
<IpLegal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %si,%ax
mov    %rdi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movw   $0x0,-0x22(%rbp)
movw   $0x0,-0x24(%rbp)
movb   $0x0,-0x25(%rbp)
lea    -0x2f(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <memset@plt>
movw   $0x0,-0x22(%rbp)
movzwl -0x22(%rbp),%eax
movzwl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jge    1256 <IpLegal+0x136>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
cmp    $0x2e,%eax
jne    11f4 <IpLegal+0xd4>
mov    -0x25(%rbp),%al
add    $0x1,%al
mov    %al,-0x25(%rbp)
lea    -0x2f(%rbp),%rdi
call   1040 <atoi@plt>
cmp    $0xff,%eax
jg     11d0 <IpLegal+0xb0>
movzbl -0x25(%rbp),%eax
cmp    $0x1,%eax
jne    11c1 <IpLegal+0xa1>
lea    -0x2f(%rbp),%rdi
call   1040 <atoi@plt>
cmp    $0x0,%eax
je     11d0 <IpLegal+0xb0>
jmp    11d9 <IpLegal+0xb9>
mov    $0x1,%al
test   $0x1,%al
jne    11d0 <IpLegal+0xb0>
jmp    11d9 <IpLegal+0xb9>
movb   $0x1,-0x1(%rbp)
jmp    128d <IpLegal+0x16d>
movw   $0x0,-0x24(%rbp)
lea    -0x2f(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <memset@plt>
jmp    1234 <IpLegal+0x114>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
sub    $0x30,%eax
cmp    $0xa,%eax
jae    1226 <IpLegal+0x106>
mov    -0x20(%rbp),%rax
mov    (%rax),%cl
movzwl -0x24(%rbp),%eax
mov    %cl,-0x2f(%rbp,%rax,1)
mov    -0x24(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x24(%rbp)
jmp    122f <IpLegal+0x10f>
movb   $0x1,-0x1(%rbp)
jmp    128d <IpLegal+0x16d>
jmp    1234 <IpLegal+0x114>
jmp    1239 <IpLegal+0x119>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x22(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x22(%rbp)
jmp    1161 <IpLegal+0x41>
movzbl -0x25(%rbp),%eax
cmp    $0x3,%eax
je     126c <IpLegal+0x14c>
movb   $0x1,-0x1(%rbp)
jmp    128d <IpLegal+0x16d>
lea    -0x2f(%rbp),%rdi
call   1040 <atoi@plt>
cmp    $0xff,%eax
jle    1289 <IpLegal+0x169>
movb   $0x1,-0x1(%rbp)
jmp    128d <IpLegal+0x16d>
movb   $0x0,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IpLegal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movw   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
test   %esi,%esi
je     11c4 <IpLegal+0xa4>
mov    %rdi,%r12
movzwl %si,%r15d
xor    %ebx,%ebx
lea    0x8(%rsp),%r14
xor    %r13d,%r13d
xor    %ebp,%ebp
jmp    116a <IpLegal+0x4a>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %bx,%r15w
je     11c4 <IpLegal+0xa4>
movzbl (%r12,%rbx,1),%eax
cmp    $0x2e,%eax
jne    11b0 <IpLegal+0x90>
mov    %r14,%rdi
call   1040 <atoi@plt>
test   %eax,%eax
je     11c4 <IpLegal+0xa4>
cmp    $0xff,%eax
jg     11c4 <IpLegal+0xa4>
test   %r13b,%r13b
jne    11c4 <IpLegal+0xa4>
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1030 <memset@plt>
mov    $0x1,%r13b
jmp    1160 <IpLegal+0x40>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x30(%rax),%ecx
cmp    $0x9,%ecx
ja     11c4 <IpLegal+0xa4>
movzwl %bp,%ecx
mov    %al,0x8(%rsp,%rcx,1)
add    $0x1,%ebp
jmp    1160 <IpLegal+0x40>
mov    $0x1,%al
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define zeroext i8 @IpLegal(i8* %0, i16 zeroext %1) {
%3 = alloca i8
%4 = alloca i8*
%5 = alloca i16
%6 = alloca i8*
%7 = alloca i16
%8 = alloca i16
%9 = alloca i8
%10 = alloca [10 x i8]
store i8* %0, i8** %4
store i16 %1, i16* %5
%11 = load i8*, i8** %4
store i8* %11, i8** %6
store i16 0, i16* %7
store i16 0, i16* %8
store i8 0, i8* %9
%12 = bitcast [10 x i8]* %10 to i8*
store i16 0, i16* %7
br label %13
13: ; preds = %60, %2
%14 = load i16, i16* %7
%15 = zext i16 %14 to i32
%16 = load i16, i16* %5
%17 = zext i16 %16 to i32
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %65
19: ; preds = %13
%20 = load i8*, i8** %6
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = icmp eq i32 %22, 46
br i1 %23, label %24, label %43
24: ; preds = %19
%25 = load i8, i8* %9
%26 = add i8 %25, 1
store i8 %26, i8* %9
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%28 = call i32 @atoi(i8* %27)
%29 = icmp sgt i32 %28, 255
br i1 %29, label %39, label %30
30: ; preds = %24
%31 = load i8, i8* %9
%32 = zext i8 %31 to i32
%33 = icmp eq i32 %32, 1
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%36 = call i32 @atoi(i8* %35)
%37 = icmp eq i32 %36, 0
br i1 %37, label %39, label %40
38: ; preds = %30
br i1 true, label %39, label %40
39: ; preds = %38, %34, %24
store i8 1, i8* %3
br label %76
40: ; preds = %38, %34
store i16 0, i16* %8
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i32 0, i32 10)
br label %59
43: ; preds = %19
%44 = load i8*, i8** %6
%45 = load i8, i8* %44
%46 = zext i8 %45 to i32
%47 = sub nsw i32 %46, 48
%48 = icmp ult i32 %47, 10
br i1 %48, label %49, label %57
49: ; preds = %43
%50 = load i8*, i8** %6
%51 = load i8, i8* %50
%52 = load i16, i16* %8
%53 = zext i16 %52 to i64
%54 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 %53
store i8 %51, i8* %54
%55 = load i16, i16* %8
%56 = add i16 %55, 1
store i16 %56, i16* %8
br label %58
57: ; preds = %43
store i8 1, i8* %3
br label %76
58: ; preds = %49
br label %59
59: ; preds = %58, %40
br label %60
60: ; preds = %59
%61 = load i8*, i8** %6
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %6
%63 = load i16, i16* %7
%64 = add i16 %63, 1
store i16 %64, i16* %7
br label %13
65: ; preds = %13
%66 = load i8, i8* %9
%67 = zext i8 %66 to i32
%68 = icmp ne i32 %67, 3
br i1 %68, label %69, label %70
69: ; preds = %65
store i8 1, i8* %3
br label %76
70: ; preds = %65
%71 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%72 = call i32 @atoi(i8* %71)
%73 = icmp sgt i32 %72, 255
br i1 %73, label %74, label %75
74: ; preds = %70
store i8 1, i8* %3
br label %76
75: ; preds = %70
store i8 0, i8* %3
br label %76
76: ; preds = %75, %74, %69, %57, %39
%77 = load i8, i8* %3
ret i8 %77
}

LLVM IR (-O2):
define zeroext i8 @IpLegal(i8* nocapture %0, i16 zeroext %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = icmp eq i16 %1, 0
br i1 %5, label %36, label %6
6: ; preds = %2, %30
%7 = phi i8 [ %32, %30 ], [ 0, %2 ]
%8 = phi i16 [ %31, %30 ], [ 0, %2 ]
%9 = phi i16 [ %34, %30 ], [ 0, %2 ]
%10 = phi i8* [ %33, %30 ], [ %0, %2 ]
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 46
br i1 %12, label %13, label %22
13: ; preds = %6
%14 = call i32 @atoi(i8* %4)
%15 = icmp sgt i32 %14, 255
%16 = icmp ne i8 %7, 0
%17 = select i1 %15, i1 true, i1 %16
%18 = icmp eq i32 %14, 0
%19 = or i1 %18, %17
br i1 %19, label %36, label %20
20: ; preds = %13
%21 = call i32 @memset(i8* %4, i32 0, i32 10)
br label %30
22: ; preds = %6
%23 = zext i8 %11 to i32
%24 = add nsw i32 %23, -48
%25 = icmp ult i32 %24, 10
br i1 %25, label %26, label %36
26: ; preds = %22
%27 = zext i16 %8 to i64
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %27
store i8 %11, i8* %28
%29 = add i16 %8, 1
br label %30
30: ; preds = %20, %26
%31 = phi i16 [ 0, %20 ], [ %29, %26 ]
%32 = phi i8 [ 1, %20 ], [ %7, %26 ]
%33 = getelementptr inbounds i8, i8* %10, i64 1
%34 = add nuw i16 %9, 1
%35 = icmp eq i16 %34, %1
br i1 %35, label %36, label %6
36: ; preds = %22, %13, %30, %2
ret i8 1
}