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

/* Variables and functions */
scalar_t__ INADDR_NONE;
struct hostent *gethostbyname(char *);
scalar_t__ inet_addr(char *);
int /*<<< orphan*/ memcpy(scalar_t__ *, int /*<<< orphan*/, int);
uint32_t resolveipv4(char *host) {
  uint32_t ip = 0x00000000;
  struct hostent *hp;
  ip = inet_addr(host);
  if (ip == INADDR_NONE) {
    hp = gethostbyname(host);
    if (hp != NULL) {
      memcpy(&ip, hp->h_addr, 4);
    }
  }
  return (ip);
}


x86 assembly (clang, -O0):
<resolveipv4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <inet_addr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2e8c(%rip),%rcx
cmp    (%rcx),%rax
jne    1196 <resolveipv4+0x66>
mov    -0x8(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1191 <resolveipv4+0x61>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
jmp    1196 <resolveipv4+0x66>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolveipv4>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <inet_addr@plt>
mov    %rax,%rbx
mov    %rax,(%rsp)
mov    0x2e9e(%rip),%rax
cmp    (%rax),%rbx
jne    116f <resolveipv4+0x3f>
mov    %r14,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     116f <resolveipv4+0x3f>
mov    (%rax),%esi
mov    %rsp,%rdi
mov    $0x4,%edx
call   1050 <memcpy@plt>
mov    (%rsp),%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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