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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyname(char const *);
scalar_t__ inet_pton(int /*<<< orphan*/, char const *, struct in_addr *);
int orta_addr_valid(const char *addr) {
  struct in_addr addr4;
  struct hostent *h;
  if (inet_pton(AF_INET, addr, &addr4)) {
    return 1;
  }
  h = gethostbyname(addr);
  if (h != NULL) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<orta_addr_valid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <inet_pton@plt>
cmp    $0x0,%rax
je     1158 <orta_addr_valid+0x38>
movl   $0x1,-0x4(%rbp)
jmp    1183 <orta_addr_valid+0x63>
mov    -0x10(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     117c <orta_addr_valid+0x5c>
movl   $0x1,-0x4(%rbp)
jmp    1183 <orta_addr_valid+0x63>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<orta_addr_valid>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2eb9(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rdx
mov    %rbx,%rsi
call   1040 <inet_pton@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    115e <orta_addr_valid+0x3e>
mov    %rbx,%rdi
call   1030 <gethostbyname@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
add    $0x10,%rsp
pop    %rbx
ret

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

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