#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 sscanf(char *, char *, int *, char *, int *, char *, int *, char *, int *,
           char *);
int netutils_is_valid_ip_addr(char *buf) {
  int n[4];
  char c[4];
  char *p = buf;
  if (sscanf(p, "%d%c%d%c%d%c%d%c", &n[0], &c[0], &n[1], &c[1], &n[2], &c[2],
             &n[3], &c[3]) == 7) {
    int i;
    for (i = 0; i < 3; ++i)
      if (c[i] != '.')
        return 0;
    for (i = 0; i < 4; ++i)
      if (n[i] > 255 || n[i] < 0)
        return 0;
    return 0;
  } else
    return -1;
}


x86 assembly (clang, -O0):
<netutils_is_valid_ip_addr>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x68,%rsp
mov    %rdi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
lea    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
lea    -0x30(%rbp),%r8
add    $0x4,%r8
lea    -0x34(%rbp),%r9
add    $0x1,%r9
lea    -0x30(%rbp),%rbx
add    $0x8,%rbx
lea    -0x34(%rbp),%r11
add    $0x2,%r11
lea    -0x30(%rbp),%r10
add    $0xc,%r10
lea    -0x34(%rbp),%rax
add    $0x3,%rax
lea    0xe98(%rip),%rsi
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1030 <sscanf@plt>
cmp    $0x7,%eax
jne    1228 <netutils_is_valid_ip_addr+0x118>
movl   $0x0,-0x44(%rbp)
cmpl   $0x3,-0x44(%rbp)
jge    11cb <netutils_is_valid_ip_addr+0xbb>
movslq -0x44(%rbp),%rax
movsbl -0x34(%rbp,%rax,1),%eax
cmp    $0x2e,%eax
je     11b8 <netutils_is_valid_ip_addr+0xa8>
movl   $0x0,-0xc(%rbp)
jmp    122f <netutils_is_valid_ip_addr+0x11f>
jmp    11bd <netutils_is_valid_ip_addr+0xad>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1190 <netutils_is_valid_ip_addr+0x80>
movl   $0x0,-0x44(%rbp)
cmpl   $0x4,-0x44(%rbp)
jge    121c <netutils_is_valid_ip_addr+0x10c>
movslq -0x44(%rbp),%rax
cmpl   $0xff,-0x30(%rbp,%rax,4)
jg     11fd <netutils_is_valid_ip_addr+0xed>
movslq -0x44(%rbp),%rax
cmpl   $0x0,-0x30(%rbp,%rax,4)
jge    1209 <netutils_is_valid_ip_addr+0xf9>
movl   $0x0,-0xc(%rbp)
jmp    122f <netutils_is_valid_ip_addr+0x11f>
jmp    120e <netutils_is_valid_ip_addr+0xfe>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11d2 <netutils_is_valid_ip_addr+0xc2>
movl   $0x0,-0xc(%rbp)
jmp    122f <netutils_is_valid_ip_addr+0x11f>
movl   $0xffffffff,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x68,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<netutils_is_valid_ip_addr>:
push   %rbx
sub    $0x20,%rsp
lea    0x14(%rsp),%r8
lea    0xd(%rsp),%r9
lea    0x18(%rsp),%r10
lea    0xe(%rsp),%r11
lea    0x1c(%rsp),%rax
lea    0xf(%rsp),%rbx
lea    0xec6(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
push   %rbx
push   %rax
push   %r11
push   %r10
call   1030 <sscanf@plt>
add    $0x20,%rsp
xor    %ecx,%ecx
cmp    $0x7,%eax
setne  %cl
neg    %ecx
mov    %ecx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"%d%c%d%c%d%c%d%c\00"
define i32 @netutils_is_valid_ip_addr(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [4 x i32]
%5 = alloca [4 x i8]
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
%8 = load i8*, i8** %3
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%11 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 1
%14 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 2
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%17 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 3
%18 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %10, i8* %11, i32* %12, i8* %13, i32* %14, i8* %15, i32* %16, i8* %17)
%19 = icmp eq i32 %18, 7
br i1 %19, label %20, label %58
20: ; preds = %1
store i32 0, i32* %7
br label %21
21: ; preds = %33, %20
%22 = load i32, i32* %7
%23 = icmp slt i32 %22, 3
br i1 %23, label %24, label %36
24: ; preds = %21
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [4 x i8], [4 x i8]* %5, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 46
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 0, i32* %2
br label %59
32: ; preds = %24
br label %33
33: ; preds = %32
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %21
36: ; preds = %21
store i32 0, i32* %7
br label %37
37: ; preds = %54, %36
%38 = load i32, i32* %7
%39 = icmp slt i32 %38, 4
br i1 %39, label %40, label %57
40: ; preds = %37
%41 = load i32, i32* %7
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = icmp sgt i32 %44, 255
br i1 %45, label %52, label %46
46: ; preds = %40
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 %48
%50 = load i32, i32* %49
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %46, %40
store i32 0, i32* %2
br label %59
53: ; preds = %46
br label %54
54: ; preds = %53
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %37
57: ; preds = %37
store i32 0, i32* %2
br label %59
58: ; preds = %1
store i32 -1, i32* %2
br label %59
59: ; preds = %58, %57, %52, %31
%60 = load i32, i32* %2
ret i32 %60
}

LLVM IR (-O2):
@.str = [17 x i8] c"%d%c%d%c%d%c%d%c\00"
define i32 @netutils_is_valid_ip_addr(i8* nocapture %0) {
%2 = alloca [4 x i32]
%3 = alloca [4 x i8]
%4 = bitcast [4 x i32]* %2 to i8*
%5 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 0
%7 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 1
%8 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%9 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 2
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %2, i64 0, i64 3
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%13 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* %6, i8* %5, i32* %7, i8* %8, i32* %9, i8* %10, i32* %11, i8* %12)
%14 = icmp ne i32 %13, 7
%15 = sext i1 %14 to i32
ret i32 %15
}