#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 u_char;
struct in_addr {
  int s_addr;
};

/* Variables and functions */
int valid_ipaddr(struct in_addr address) {
  u_char octet[4];
  octet[0] = address.s_addr;
  octet[1] = address.s_addr >> 8;
  octet[2] = address.s_addr >> 16;
  octet[3] = address.s_addr >> 24;
  if (!octet[0] || !octet[3])
    return (0);
  if (address.s_addr == 0xffffffff)
    return (0);
  return (1);
}


x86 assembly (clang, -O0):
<valid_ipaddr>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x10,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
sar    $0x18,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     113c <valid_ipaddr+0x3c>
cmpl   $0x0,-0x14(%rbp)
jne    1148 <valid_ipaddr+0x48>
movl   $0x0,-0x4(%rbp)
jmp    1165 <valid_ipaddr+0x65>
cmpl   $0xffffffff,-0x8(%rbp)
jne    115e <valid_ipaddr+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    1165 <valid_ipaddr+0x65>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<valid_ipaddr>:
add    $0xff000000,%edi
xor    %eax,%eax
cmp    $0xfeffffff,%edi
setb   %al
ret

LLVM IR (-O0):
%struct.in_addr = type { i32 }
define i32 @valid_ipaddr(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.in_addr
%4 = alloca [4 x i32]
%5 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
store i32 %0, i32* %5
%6 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%7 = load i32, i32* %6
%8 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%10 = load i32, i32* %9
%11 = ashr i32 %10, 8
%12 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 1
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%14 = load i32, i32* %13
%15 = ashr i32 %14, 16
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 2
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%18 = load i32, i32* %17
%19 = ashr i32 %18, 24
%20 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
store i32 %19, i32* %20
%21 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 0
%22 = load i32, i32* %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %1
%25 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 3
%26 = load i32, i32* %25
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %24, %1
store i32 0, i32* %2
br label %35
29: ; preds = %24
%30 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%31 = load i32, i32* %30
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %34
33: ; preds = %29
store i32 0, i32* %2
br label %35
34: ; preds = %29
store i32 1, i32* %2
br label %35
35: ; preds = %34, %33, %28
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
define i32 @valid_ipaddr(i32 %0) {
%2 = add i32 %0, -16777216
%3 = icmp ult i32 %2, -16777217
%4 = zext i1 %3 to i32
ret i32 %4
}