#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 hostent {
  size_t h_length;
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyname(char *);
int inet_pton(int /*<<< orphan*/, char *, unsigned long *);
unsigned long ntohl(unsigned long);
int get_addr(char *str, unsigned long *ip, size_t *alen) {
  struct hostent *hep;
  unsigned long tip;
  hep = gethostbyname(str);
  if (hep && hep->h_addr_list && hep->h_addr_list[0]) {
    tip = *(unsigned long *)(hep->h_addr_list[0]);
    *ip = ntohl(tip);
    *alen = hep->h_length;
    return 1;
  }
  return inet_pton(AF_INET, str, ip);
}


x86 assembly (clang, -O0):
<get_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11bc <get_addr+0x8c>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11bc <get_addr+0x8c>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
cmpq   $0x0,(%rax)
je     11bc <get_addr+0x8c>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <ntohl@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11d5 <get_addr+0xa5>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <inet_pton@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_addr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
call   1030 <gethostbyname@plt>
test   %rax,%rax
je     1181 <get_addr+0x51>
mov    %rax,%rbx
mov    0x8(%rax),%rax
test   %rax,%rax
je     1181 <get_addr+0x51>
mov    (%rax),%rax
test   %rax,%rax
je     1181 <get_addr+0x51>
mov    (%rax),%rdi
call   1050 <ntohl@plt>
mov    %rax,(%r15)
mov    (%rbx),%rax
mov    %rax,(%r14)
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
mov    %r15,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <inet_pton@plt>

LLVM IR (-O0):
%struct.hostent = type { i64, i64* }
@AF_INET = global i32 0
define i32 @get_addr(i8* %0, i64* %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca %struct.hostent*
%9 = alloca i64
store i8* %0, i8** %5
store i64* %1, i64** %6
store i64* %2, i64** %7
%10 = load i8*, i8** %5
%11 = call %struct.hostent* @gethostbyname(i8* %10)
store %struct.hostent* %11, %struct.hostent** %8
%12 = load %struct.hostent*, %struct.hostent** %8
%13 = icmp ne %struct.hostent* %12, null
br i1 %13, label %14, label %41
14: ; preds = %3
%15 = load %struct.hostent*, %struct.hostent** %8
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i32 0, i32 1
%17 = load i64*, i64** %16
%18 = icmp ne i64* %17, null
br i1 %18, label %19, label %41
19: ; preds = %14
%20 = load %struct.hostent*, %struct.hostent** %8
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %20, i32 0, i32 1
%22 = load i64*, i64** %21
%23 = getelementptr inbounds i64, i64* %22, i64 0
%24 = load i64, i64* %23
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %41
26: ; preds = %19
%27 = load %struct.hostent*, %struct.hostent** %8
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i32 0, i32 1
%29 = load i64*, i64** %28
%30 = getelementptr inbounds i64, i64* %29, i64 0
%31 = load i64, i64* %30
%32 = inttoptr i64 %31 to i64*
%33 = load i64, i64* %32
store i64 %33, i64* %9
%34 = load i64, i64* %9
%35 = call i64 @ntohl(i64 %34)
%36 = load i64*, i64** %6
store i64 %35, i64* %36
%37 = load %struct.hostent*, %struct.hostent** %8
%38 = getelementptr inbounds %struct.hostent, %struct.hostent* %37, i32 0, i32 0
%39 = load i64, i64* %38
%40 = load i64*, i64** %7
store i64 %39, i64* %40
store i32 1, i32* %4
br label %46
41: ; preds = %19, %14, %3
%42 = load i32, i32* @AF_INET
%43 = load i8*, i8** %5
%44 = load i64*, i64** %6
%45 = call i32 @inet_pton(i32 %42, i8* %43, i64* %44)
store i32 %45, i32* %4
br label %46
46: ; preds = %41, %26
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
%struct.hostent = type { i64, i64* }
@AF_INET = global i32 0
define i32 @get_addr(i8* %0, i64* %1, i64* nocapture writeonly %2) {
%4 = tail call %struct.hostent* @gethostbyname(i8* %0)
%5 = icmp eq %struct.hostent* %4, null
br i1 %5, label %19, label %6
6: ; preds = %3
%7 = getelementptr inbounds %struct.hostent, %struct.hostent* %4, i64 0, i32 1
%8 = load i64*, i64** %7
%9 = icmp eq i64* %8, null
br i1 %9, label %19, label %10
10: ; preds = %6
%11 = load i64, i64* %8
%12 = icmp eq i64 %11, 0
br i1 %12, label %19, label %13
13: ; preds = %10
%14 = inttoptr i64 %11 to i64*
%15 = load i64, i64* %14
%16 = tail call i64 @ntohl(i64 %15)
store i64 %16, i64* %1
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %4, i64 0, i32 0
%18 = load i64, i64* %17
store i64 %18, i64* %2
br label %22
19: ; preds = %10, %6, %3
%20 = load i32, i32* @AF_INET
%21 = tail call i32 @inet_pton(i32 %20, i8* %0, i64* %1)
br label %22
22: ; preds = %19, %13
%23 = phi i32 [ 1, %13 ], [ %21, %19 ]
ret i32 %23
}