#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 sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_INET6;
int inet_pton(int /*<<< orphan*/, char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *strchr(char const *, char);
int is_valid_client_ip(const char *ip) {
  struct sockaddr_in sa;
  struct sockaddr_in6 sa6;
  int result = -1;
  if (strchr(ip, '.') != NULL) {
    result = inet_pton(AF_INET, ip, &(sa.sin_addr));
  }
  if (strchr(ip, ':') != NULL) {
    result = inet_pton(AF_INET6, ip, &(sa6.sin6_addr));
  }
  return result;
}


x86 assembly (clang, -O0):
<is_valid_client_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1164 <is_valid_client_ip+0x44>
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <inet_pton@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1195 <is_valid_client_ip+0x75>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <inet_pton@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_valid_client_ip>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    $0x2e,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1152 <is_valid_client_ip+0x32>
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rdx
mov    %rbx,%rsi
call   1040 <inet_pton@plt>
mov    %eax,%ebp
jmp    1157 <is_valid_client_ip+0x37>
mov    $0xffffffff,%ebp
mov    %rbx,%rdi
mov    $0x3a,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1181 <is_valid_client_ip+0x61>
mov    0x2e70(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rdx
mov    %rbx,%rsi
call   1040 <inet_pton@plt>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@AF_INET = global i32 0
@AF_INET6 = global i32 0
define i32 @is_valid_client_ip(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in6
%5 = alloca i32
store i8* %0, i8** %2
store i32 -1, i32* %5
%6 = load i8*, i8** %2
%7 = call i32* @strchr(i8* %6, i8 signext 46)
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load i32, i32* @AF_INET
%11 = load i8*, i8** %2
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%13 = call i32 @inet_pton(i32 %10, i8* %11, i32* %12)
store i32 %13, i32* %5
br label %14
14: ; preds = %9, %1
%15 = load i8*, i8** %2
%16 = call i32* @strchr(i8* %15, i8 signext 58)
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %23
18: ; preds = %14
%19 = load i32, i32* @AF_INET6
%20 = load i8*, i8** %2
%21 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %4, i32 0, i32 0
%22 = call i32 @inet_pton(i32 %19, i8* %20, i32* %21)
store i32 %22, i32* %5
br label %23
23: ; preds = %18, %14
%24 = load i32, i32* %5
ret i32 %24
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@AF_INET = global i32 0
@AF_INET6 = global i32 0
define i32 @is_valid_client_ip(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.sockaddr_in6
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = bitcast %struct.sockaddr_in6* %3 to i8*
%6 = tail call i32* @strchr(i8* %0, i8 signext 46)
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0
%11 = call i32 @inet_pton(i32 %9, i8* %0, i32* %10)
br label %12
12: ; preds = %8, %1
%13 = phi i32 [ %11, %8 ], [ -1, %1 ]
%14 = call i32* @strchr(i8* %0, i8 signext 58)
%15 = icmp eq i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %12
%17 = load i32, i32* @AF_INET6
%18 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %3, i64 0, i32 0
%19 = call i32 @inet_pton(i32 %17, i8* %0, i32* %18)
br label %20
20: ; preds = %16, %12
%21 = phi i32 [ %19, %16 ], [ %13, %12 ]
ret i32 %21
}