#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  unsigned int s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ caddr_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
unsigned int resolve(char *host) {
  struct hostent *he;
  struct sockaddr_in tmp;
  he = gethostbyname(host);
  if (he) {
    memcpy((caddr_t)&tmp.sin_addr.s_addr, he->h_addr, he->h_length);
  } else {
    perror("resolving");
    exit(-1);
  }
  return (tmp.sin_addr.s_addr);
}


x86 assembly (clang, -O0):
<resolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1181 <resolve+0x41>
lea    -0x18(%rbp),%rax
mov    %eax,%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
call   1040 <memcpy@plt>
jmp    1197 <resolve+0x57>
lea    0xe78(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve>:
push   %rax
call   1030 <gethostbyname@plt>
test   %rax,%rax
je     115d <resolve+0x1d>
mov    %rsp,%rdi
mov    (%rax),%edx
mov    0x4(%rax),%esi
call   1040 <memcpy@plt>
mov    (%rsp),%eax
pop    %rcx
ret
lea    0xe9c(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32, i32 }
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [10 x i8] c"resolving\00"
define i32 @resolve(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.hostent*
%4 = alloca %struct.sockaddr_in
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call %struct.hostent* @gethostbyname(i8* %5)
store %struct.hostent* %6, %struct.hostent** %3
%7 = load %struct.hostent*, %struct.hostent** %3
%8 = icmp ne %struct.hostent* %7, null
br i1 %8, label %9, label %20
9: ; preds = %1
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%11 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %10, i32 0, i32 0
%12 = ptrtoint i32* %11 to i32
%13 = load %struct.hostent*, %struct.hostent** %3
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = load %struct.hostent*, %struct.hostent** %3
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @memcpy(i32 %12, i32 %15, i32 %18)
br label %23
20: ; preds = %1
%21 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%22 = call i32 @exit(i32 -1)
unreachable
23: ; preds = %9
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
%26 = load i32, i32* %25
ret i32 %26
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32 }
@.str = [10 x i8] c"resolving\00"
define i32 @resolve(i8* %0) {
%2 = alloca %struct.sockaddr_in
%3 = bitcast %struct.sockaddr_in* %2 to i8*
%4 = tail call %struct.hostent* @gethostbyname(i8* %0)
%5 = icmp eq %struct.hostent* %4, null
br i1 %5, label %16, label %6
6: ; preds = %1
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
%8 = ptrtoint %struct.sockaddr_in* %2 to i64
%9 = trunc i64 %8 to i32
%10 = getelementptr inbounds %struct.hostent, %struct.hostent* %4, i64 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.hostent, %struct.hostent* %4, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @memcpy(i32 %9, i32 %11, i32 %13)
%15 = load i32, i32* %7
ret i32 %15
16: ; preds = %1
%17 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -1)
unreachable
}