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

/* Variables and functions */
int inet_addr(char *);
int /*<<< orphan*/ memcpy(char *, char const *, int);
scalar_t__ strcmp(char *, char *);
int ip_addr(const char *s, int len, struct in_addr *addr) {
  char ipbuf[16];
  if (len > 15)
    return -1;
  memcpy(ipbuf, s, len);
  ipbuf[len] = 0;
  addr->s_addr = inet_addr(ipbuf);
  if (addr->s_addr == 0xffffffff && strcmp(ipbuf, "255.255.255.255") != 0)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<ip_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpl   $0xf,-0x14(%rbp)
jle    1159 <ip_addr+0x29>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <ip_addr+0x8d>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
movslq -0x14(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
call   1030 <inet_addr@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    11b6 <ip_addr+0x86>
lea    -0x30(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11b6 <ip_addr+0x86>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <ip_addr+0x8d>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ip_addr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    $0xffffffff,%ebx
cmp    $0xf,%esi
jg     1186 <ip_addr+0x56>
mov    %rdx,%r14
mov    %rdi,%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %ebp,%edx
call   1050 <memcpy@plt>
movslq %ebp,%rax
movb   $0x0,(%rsp,%rax,1)
mov    %r15,%rdi
call   1030 <inet_addr@plt>
mov    %eax,(%r14)
cmp    $0xffffffff,%eax
jne    1184 <ip_addr+0x54>
lea    0xe89(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    1186 <ip_addr+0x56>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.in_addr = type { i32 }
@.str = [16 x i8] c"255.255.255.255\00"
define i32 @ip_addr(i8* %0, i32 %1, %struct.in_addr* nocapture writeonly %2) {
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%6 = icmp sgt i32 %1, 15
br i1 %6, label %18, label %7
7: ; preds = %3
%8 = call i32 @memcpy(i8* %5, i8* %0, i32 %1)
%9 = sext i32 %1 to i64
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 %9
store i8 0, i8* %10
%11 = call i32 @inet_addr(i8* %5)
%12 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
store i32 %11, i32* %12
%13 = icmp eq i32 %11, -1
br i1 %13, label %14, label %17
14: ; preds = %7
%15 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14, %7
br label %18
18: ; preds = %14, %3, %17
%19 = phi i32 [ 0, %17 ], [ -1, %3 ], [ -1, %14 ]
ret i32 %19
}