#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 /*<<< orphan*/ isdigit(char);
int good_ipaddr(char *addr) {
  int dot_count;
  int digit_count;
  dot_count = 0;
  digit_count = 0;
  while (*addr != '\0' && *addr != ' ') {
    if (*addr == '.') {
      dot_count++;
      digit_count = 0;
    } else if (!isdigit(*addr)) {
      dot_count = 5;
    } else {
      digit_count++;
      if (digit_count > 3) {
        dot_count = 5;
      }
    }
    addr++;
  }
  if (dot_count != 3) {
    return (-1);
  } else {
    return (0);
  }
}


x86 assembly (clang, -O0):
<good_ipaddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x19(%rbp)
je     114f <good_ipaddr+0x3f>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    115f <good_ipaddr+0x4f>
jmp    11da <good_ipaddr+0xca>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1184 <good_ipaddr+0x74>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
jmp    11c9 <good_ipaddr+0xb9>
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%eax
jne    11a5 <good_ipaddr+0x95>
movl   $0x5,-0x14(%rbp)
jmp    11c4 <good_ipaddr+0xb4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jle    11bf <good_ipaddr+0xaf>
movl   $0x5,-0x14(%rbp)
jmp    11c4 <good_ipaddr+0xb4>
jmp    11c9 <good_ipaddr+0xb9>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    112a <good_ipaddr+0x1a>
cmpl   $0x3,-0x14(%rbp)
je     11f0 <good_ipaddr+0xe0>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f7 <good_ipaddr+0xe7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<good_ipaddr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
mov    $0x5,%r14d
xor    %r15d,%r15d
jmp    113a <good_ipaddr+0x2a>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
xor    %r15d,%r15d
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x2e,%al
je     1130 <good_ipaddr+0x20>
test   %al,%al
je     1175 <good_ipaddr+0x65>
cmp    $0x20,%al
je     1175 <good_ipaddr+0x65>
movsbl %al,%edi
call   1030 <isdigit@plt>
test   %eax,%eax
je     116a <good_ipaddr+0x5a>
cmp    $0x3,%r15d
lea    0x1(%r15),%eax
cmovge %r14d,%ebp
mov    %eax,%r15d
add    $0x1,%rbx
jmp    113a <good_ipaddr+0x2a>
mov    $0x5,%ebp
add    $0x1,%rbx
jmp    113a <good_ipaddr+0x2a>
xor    %eax,%eax
cmp    $0x3,%ebp
setne  %al
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @good_ipaddr(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %40, %1
%7 = load i8*, i8** %3
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %6
%12 = load i8*, i8** %3
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 32
br label %16
16: ; preds = %11, %6
%17 = phi i1 [ false, %6 ], [ %15, %11 ]
br i1 %17, label %18, label %43
18: ; preds = %16
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 46
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
store i32 0, i32* %5
br label %40
26: ; preds = %18
%27 = load i8*, i8** %3
%28 = load i8, i8* %27
%29 = call i32 @isdigit(i8 signext %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %26
store i32 5, i32* %4
br label %39
32: ; preds = %26
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
%35 = load i32, i32* %5
%36 = icmp sgt i32 %35, 3
br i1 %36, label %37, label %38
37: ; preds = %32
store i32 5, i32* %4
br label %38
38: ; preds = %37, %32
br label %39
39: ; preds = %38, %31
br label %40
40: ; preds = %39, %23
%41 = load i8*, i8** %3
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %3
br label %6
43: ; preds = %16
%44 = load i32, i32* %4
%45 = icmp ne i32 %44, 3
br i1 %45, label %46, label %47
46: ; preds = %43
store i32 -1, i32* %2
br label %48
47: ; preds = %43
store i32 0, i32* %2
br label %48
48: ; preds = %47, %46
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
define i32 @good_ipaddr(i8* nocapture %0) {
br label %2
2: ; preds = %16, %1
%3 = phi i8* [ %0, %1 ], [ %19, %16 ]
%4 = phi i32 [ 0, %1 ], [ %17, %16 ]
%5 = phi i32 [ 0, %1 ], [ %18, %16 ]
%6 = load i8, i8* %3
switch i8 %6, label %9 [
i8 0, label %20
i8 32, label %20
i8 46, label %7
]
7: ; preds = %2
%8 = add nsw i32 %4, 1
br label %16
9: ; preds = %2
%10 = tail call i32 @isdigit(i8 signext %6)
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %9
%13 = add nsw i32 %5, 1
%14 = icmp sgt i32 %5, 2
%15 = select i1 %14, i32 5, i32 %4
br label %16
16: ; preds = %12, %9, %7
%17 = phi i32 [ %8, %7 ], [ 5, %9 ], [ %15, %12 ]
%18 = phi i32 [ 0, %7 ], [ %5, %9 ], [ %13, %12 ]
%19 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
20: ; preds = %2, %2
%21 = icmp ne i32 %4, 3
%22 = sext i1 %21 to i32
ret i32 %22
}