#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 in6_addr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_INET6;
int inet_pton(int /*<<< orphan*/, char const *, struct in6_addr *);
int is_ip(const char *ip) {
  struct in6_addr test_ip;
  if (inet_pton(AF_INET, ip, &test_ip) != false)
    return true;
  else if (inet_pton(AF_INET6, ip, &test_ip) != false)
    return true;
  else
    return false;
}


x86 assembly (clang, -O0):
<is_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ec5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <inet_pton@plt>
cmp    $0x0,%eax
je     1147 <is_ip+0x37>
movl   $0x1,-0x4(%rbp)
jmp    1179 <is_ip+0x69>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <inet_pton@plt>
cmp    $0x0,%eax
je     1172 <is_ip+0x62>
movl   $0x1,-0x4(%rbp)
jmp    1179 <is_ip+0x69>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_ip>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2ec9(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rdx
mov    %rbx,%rsi
call   1030 <inet_pton@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jne    1158 <is_ip+0x48>
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rdx
mov    %rbx,%rsi
call   1030 <inet_pton@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
setne  %al
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.in6_addr = type { i32 }
@AF_INET = global i32 0
@AF_INET6 = global i32 0
define i32 @is_ip(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca %struct.in6_addr
store i8* %0, i8** %3
%5 = load i32, i32* @AF_INET
%6 = load i8*, i8** %3
%7 = call i32 @inet_pton(i32 %5, i8* %6, %struct.in6_addr* %4)
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %1
store i32 1, i32* %2
br label %17
10: ; preds = %1
%11 = load i32, i32* @AF_INET6
%12 = load i8*, i8** %3
%13 = call i32 @inet_pton(i32 %11, i8* %12, %struct.in6_addr* %4)
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
store i32 1, i32* %2
br label %17
16: ; preds = %10
store i32 0, i32* %2
br label %17
17: ; preds = %16, %15, %9
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
%struct.in6_addr = type { i32 }
@AF_INET = global i32 0
@AF_INET6 = global i32 0
define i32 @is_ip(i8* %0) {
%2 = alloca %struct.in6_addr
%3 = bitcast %struct.in6_addr* %2 to i8*
%4 = load i32, i32* @AF_INET
%5 = call i32 @inet_pton(i32 %4, i8* %0, %struct.in6_addr* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = load i32, i32* @AF_INET6
%9 = call i32 @inet_pton(i32 %8, i8* %0, %struct.in6_addr* %2)
%10 = icmp ne i32 %9, 0
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %7, %1
%13 = phi i32 [ 1, %1 ], [ %11, %7 ]
ret i32 %13
}