#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 /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_INET6;
int EXIT_FAILURE;
int EXIT_SUCCESS;
void *calloc(int, int);
int /*<<< orphan*/ free(void *);
scalar_t__ inet_pton(int /*<<< orphan*/, char *, void *);
int is_ip_valid(char *ip) {
  int success = EXIT_SUCCESS;
  void *temp = calloc(1, 256);
  if (inet_pton(AF_INET, ip, temp) == 0) {
    if (inet_pton(AF_INET6, ip, temp) == 0) {
      success = EXIT_FAILURE;
    }
  }
  free(temp);
  return success;
}


x86 assembly (clang, -O0):
<is_ip_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x1,%edi
mov    $0x100,%esi
call   1040 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <inet_pton@plt>
cmp    $0x0,%rax
jne    11ac <is_ip_valid+0x7c>
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <inet_pton@plt>
cmp    $0x0,%rax
jne    11a7 <is_ip_valid+0x77>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
jmp    11ac <is_ip_valid+0x7c>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_ip_valid>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
mov    0x2e8a(%rip),%rax
mov    (%rax),%r14d
mov    $0x1,%edi
mov    $0x100,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1050 <inet_pton@plt>
test   %rax,%rax
jne    118f <is_ip_valid+0x5f>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rsi
mov    %rbx,%rdx
call   1050 <inet_pton@plt>
test   %rax,%rax
jne    118f <is_ip_valid+0x5f>
mov    0x2e44(%rip),%rax
mov    (%rax),%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @is_ip_valid(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i32, i32* @EXIT_SUCCESS
store i32 %5, i32* %3
%6 = call i8* @calloc(i32 1, i32 256)
store i8* %6, i8** %4
%7 = load i32, i32* @AF_INET
%8 = load i8*, i8** %2
%9 = load i8*, i8** %4
%10 = call i64 @inet_pton(i32 %7, i8* %8, i8* %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %1
%13 = load i32, i32* @AF_INET6
%14 = load i8*, i8** %2
%15 = load i8*, i8** %4
%16 = call i64 @inet_pton(i32 %13, i8* %14, i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %3
br label %20
20: ; preds = %18, %12
br label %21
21: ; preds = %20, %1
%22 = load i8*, i8** %4
%23 = call i32 @free(i8* %22)
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
@AF_INET = global i32 0
@AF_INET6 = global i32 0
@EXIT_FAILURE = global i32 0
define i32 @is_ip_valid(i8* %0) {
%2 = load i32, i32* @EXIT_SUCCESS
%3 = tail call dereferenceable_or_null(256) i8* @calloc(i32 1, i32 256)
%4 = load i32, i32* @AF_INET
%5 = tail call i64 @inet_pton(i32 %4, i8* %0, i8* %3)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i32, i32* @AF_INET6
%9 = tail call i64 @inet_pton(i32 %8, i8* %0, i8* %3)
%10 = icmp eq i64 %9, 0
%11 = load i32, i32* @EXIT_FAILURE
%12 = select i1 %10, i32 %11, i32 %2
br label %13
13: ; preds = %7, %1
%14 = phi i32 [ %2, %1 ], [ %12, %7 ]
%15 = tail call i32 @free(i8* %3)
ret i32 %14
}