#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 {
  int /*<<< orphan*/ h_addr;
};
typedef scalar_t__ in_addr_t;

/* Variables and functions */
scalar_t__ INADDR_NONE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
struct hostent *gethostbyname(char const *);
scalar_t__ inet_addr(char const *);
int /*<<< orphan*/ memcpy(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
in_addr_t resolve(const char *machine) {
  in_addr_t ret = inet_addr(machine);
  if (ret == INADDR_NONE) {
    const struct hostent *h = gethostbyname(machine);
    if (h == NULL) {
      fprintf(stderr, "Unknown host %s\n", machine);
      return INADDR_NONE;
    }
    memcpy((char *)&ret, h->h_addr, sizeof(in_addr_t));
  }
  return ret;
}


x86 assembly (clang, -O0):
<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)
mov    -0x18(%rbp),%rax
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%rax
jne    11c5 <resolve+0x85>
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b1 <resolve+0x71>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe67(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11cd <resolve+0x8d>
lea    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
mov    $0x8,%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <inet_addr@plt>
mov    %rax,(%rsp)
mov    0x2e91(%rip),%rbx
cmp    (%rbx),%rax
jne    117d <resolve+0x3d>
mov    %r14,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1182 <resolve+0x42>
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x8,%edx
call   1060 <memcpy@plt>
jmp    119a <resolve+0x5a>
mov    %rsp,%rbx
jmp    119a <resolve+0x5a>
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    (%rbx),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.hostent = type { i32 }
@INADDR_NONE = global i64 0
@stderr = global i32 0
@.str = [17 x i8] c"Unknown host %s\0A\00"
define i64 @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 = load i64, i64* %4
%9 = load i64, i64* @INADDR_NONE
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %27
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 eq %struct.hostent* %14, null
br i1 %15, label %16, label %21
16: ; preds = %11
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %3
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i64, i64* @INADDR_NONE
store i64 %20, i64* %2
br label %29
21: ; preds = %11
%22 = bitcast i64* %4 to i8*
%23 = load %struct.hostent*, %struct.hostent** %5
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @memcpy(i8* %22, i32 %25, i32 8)
br label %27
27: ; preds = %21, %1
%28 = load i64, i64* %4
store i64 %28, i64* %2
br label %29
29: ; preds = %27, %16
%30 = load i64, i64* %2
ret i64 %30
}

LLVM IR (-O2):
%struct.hostent = type { i32 }
@INADDR_NONE = global i64 0
@stderr = global i32 0
@.str = [17 x i8] c"Unknown host %s\0A\00"
define i64 @resolve(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 %17
7: ; preds = %1
%8 = tail call %struct.hostent* @gethostbyname(i8* %0)
%9 = icmp eq %struct.hostent* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %17
13: ; preds = %7
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @memcpy(i8* %3, i32 %15, i32 8)
br label %17
17: ; preds = %1, %13, %10
%18 = phi i64* [ @INADDR_NONE, %10 ], [ %2, %13 ], [ %2, %1 ]
%19 = load i64, i64* %18
ret i64 %19
}