#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 *, int *, int *, int *);
int is_ip(char *ip) {
  int result = 0;
  int a, b, c, d;
  result = sscanf(ip, "%d.%d.%d.%d", &a, &b, &c, &d);
  if (result == 4 && a >= 0 && a <= 255 && b >= 0 && b <= 255 && c >= 0 &&
      c <= 255 && d >= 0 && d <= 255) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<is_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xed2(%rip),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x20(%rbp),%r8
lea    -0x24(%rbp),%r9
call   1030 <sscanf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jne    11b8 <is_ip+0xa8>
cmpl   $0x0,-0x18(%rbp)
jl     11b8 <is_ip+0xa8>
cmpl   $0xff,-0x18(%rbp)
jg     11b8 <is_ip+0xa8>
cmpl   $0x0,-0x1c(%rbp)
jl     11b8 <is_ip+0xa8>
cmpl   $0xff,-0x1c(%rbp)
jg     11b8 <is_ip+0xa8>
cmpl   $0x0,-0x20(%rbp)
jl     11b8 <is_ip+0xa8>
cmpl   $0xff,-0x20(%rbp)
jg     11b8 <is_ip+0xa8>
cmpl   $0x0,-0x24(%rbp)
jl     11b8 <is_ip+0xa8>
cmpl   $0xff,-0x24(%rbp)
jg     11b8 <is_ip+0xa8>
movl   $0x1,-0x4(%rbp)
jmp    11bf <is_ip+0xaf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_ip>:
sub    $0x18,%rsp
lea    0xee5(%rip),%rsi
lea    0x14(%rsp),%rdx
lea    0x10(%rsp),%rcx
lea    0xc(%rsp),%r8
lea    0x8(%rsp),%r9
call   1030 <sscanf@plt>
cmp    $0x4,%eax
sete   %al
mov    0x14(%rsp),%ecx
test   %ecx,%ecx
setns  %dl
and    %al,%dl
cmp    $0x100,%ecx
setl   %sil
mov    0x10(%rsp),%ecx
test   %ecx,%ecx
setns  %al
and    %sil,%al
and    %dl,%al
cmp    $0x100,%ecx
setl   %sil
mov    0xc(%rsp),%edx
test   %edx,%edx
setns  %cl
and    %sil,%cl
cmp    $0x100,%edx
setl   %dl
and    %cl,%dl
and    %al,%dl
mov    0x8(%rsp),%eax
test   %eax,%eax
setns  %cl
cmp    $0x100,%eax
setl   %al
and    %cl,%al
and    %dl,%al
movzbl %al,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i32 @is_ip(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %4
%9 = load i8*, i8** %3
%10 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6, i32* %7, i32* %8)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 4
br i1 %12, label %13, label %38
13: ; preds = %1
%14 = load i32, i32* %5
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %38
16: ; preds = %13
%17 = load i32, i32* %5
%18 = icmp sle i32 %17, 255
br i1 %18, label %19, label %38
19: ; preds = %16
%20 = load i32, i32* %6
%21 = icmp sge i32 %20, 0
br i1 %21, label %22, label %38
22: ; preds = %19
%23 = load i32, i32* %6
%24 = icmp sle i32 %23, 255
br i1 %24, label %25, label %38
25: ; preds = %22
%26 = load i32, i32* %7
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = load i32, i32* %7
%30 = icmp sle i32 %29, 255
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = load i32, i32* %8
%33 = icmp sge i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* %8
%36 = icmp sle i32 %35, 255
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 1, i32* %2
br label %39
38: ; preds = %34, %31, %28, %25, %22, %19, %16, %13, %1
store i32 0, i32* %2
br label %39
39: ; preds = %38, %37
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@.str = [12 x i8] c"%d.%d.%d.%d\00"
define i32 @is_ip(i8* nocapture %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %5)
%11 = icmp eq i32 %10, 4
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, -1
%14 = select i1 %11, i1 %13, i1 false
%15 = icmp slt i32 %12, 256
%16 = select i1 %14, i1 %15, i1 false
%17 = load i32, i32* %3
%18 = icmp sgt i32 %17, -1
%19 = select i1 %16, i1 %18, i1 false
%20 = icmp slt i32 %17, 256
%21 = select i1 %19, i1 %20, i1 false
%22 = load i32, i32* %4
%23 = icmp sgt i32 %22, -1
%24 = select i1 %21, i1 %23, i1 false
%25 = icmp slt i32 %22, 256
%26 = select i1 %24, i1 %25, i1 false
%27 = load i32, i32* %5
%28 = icmp sgt i32 %27, -1
%29 = select i1 %26, i1 %28, i1 false
%30 = icmp slt i32 %27, 256
%31 = select i1 %29, i1 %30, i1 false
%32 = zext i1 %31 to i32
ret i32 %32
}