#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 */
typedef long uint32_t;
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
struct hostent *gethostbyname(char const *);
long inet_addr(char const *);
uint32_t srv_resolve(const char *host) {
  long i;
  struct hostent *he;
  if ((i = inet_addr(host)) == -1) {
    if (!(he = gethostbyname(host)))
      return 0;
    else
      return (*(uint32_t *)he->h_addr);
  }
  return i;
}


x86 assembly (clang, -O0):
<srv_resolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <inet_addr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    117a <srv_resolve+0x5a>
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1167 <srv_resolve+0x47>
movq   $0x0,-0x8(%rbp)
jmp    1182 <srv_resolve+0x62>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    1182 <srv_resolve+0x62>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<srv_resolve>:
push   %rbx
mov    %rdi,%rbx
call   1030 <inet_addr@plt>
cmp    $0xffffffffffffffff,%rax
je     1131 <srv_resolve+0x11>
pop    %rbx
ret
mov    %rbx,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1146 <srv_resolve+0x26>
mov    (%rax),%rax
mov    (%rax),%rax
pop    %rbx
ret
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i64 }
define i64 @srv_resolve(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.hostent*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @inet_addr(i8* %6)
store i64 %7, i64* %4
%8 = icmp eq i64 %7, -1
br i1 %8, label %9, label %20
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call %struct.hostent* @gethostbyname(i8* %10)
store %struct.hostent* %11, %struct.hostent** %5
%12 = icmp ne %struct.hostent* %11, null
br i1 %12, label %14, label %13
13: ; preds = %9
store i64 0, i64* %2
br label %22
14: ; preds = %9
%15 = load %struct.hostent*, %struct.hostent** %5
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = inttoptr i64 %17 to i64*
%19 = load i64, i64* %18
store i64 %19, i64* %2
br label %22
20: ; preds = %1
%21 = load i64, i64* %4
store i64 %21, i64* %2
br label %22
22: ; preds = %20, %14, %13
%23 = load i64, i64* %2
ret i64 %23
}

LLVM IR (-O2):
%struct.hostent = type { i64 }
define i64 @srv_resolve(i8* %0) {
%2 = tail call i64 @inet_addr(i8* %0)
%3 = icmp eq i64 %2, -1
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = tail call %struct.hostent* @gethostbyname(i8* %0)
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%9 = load i64, i64* %8
%10 = inttoptr i64 %9 to i64*
%11 = load i64, i64* %10
br label %12
12: ; preds = %1, %4, %7
%13 = phi i64 [ %11, %7 ], [ 0, %4 ], [ %2, %1 ]
ret i64 %13
}