#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 in_addr {
  int s_addr;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ *h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int inet_addr(char *);
int /*<<< orphan*/ stderr;
void resolv_from(char *hostfrom, struct in_addr *fromaddr) {
  struct hostent *hp;
  if (hostfrom == NULL) {
    fromaddr->s_addr = 0;
    return;
  }
  if ((hp = gethostbyname(hostfrom)) == NULL) {
    if ((fromaddr->s_addr = inet_addr(hostfrom)) == -1) {
      fprintf(stderr, "could not resolve from address\n");
      exit(0);
    }
  } else {
    bcopy(hp->h_addr_list[0], &fromaddr->s_addr, hp->h_length);
  }
}


x86 assembly (clang, -O0):
<resolv_from>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    117a <resolv_from+0x2a>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
jmp    11e3 <resolv_from+0x93>
mov    -0x8(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ca <resolv_from+0x7a>
mov    -0x8(%rbp),%rdi
call   1030 <inet_addr@plt>
mov    -0x10(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    11c5 <resolv_from+0x75>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe47(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
jmp    11e3 <resolv_from+0x93>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1060 <bcopy@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolv_from>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
test   %rdi,%rdi
je     1180 <resolv_from+0x30>
mov    %rdi,%rbx
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1189 <resolv_from+0x39>
mov    0x8(%rax),%rcx
mov    (%rcx),%edi
mov    (%rax),%edx
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <bcopy@plt>
movl   $0x0,(%r14)
jmp    1199 <resolv_from+0x49>
mov    %rbx,%rdi
call   1030 <inet_addr@plt>
mov    %eax,(%r14)
cmp    $0xffffffff,%eax
je     11a1 <resolv_from+0x51>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1050 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i32* }
@stderr = global i32 0
@.str = [32 x i8] c"could not resolve from address\0A\00"
define void @resolv_from(i8* %0, %struct.in_addr* %1) {
%3 = alloca i8*
%4 = alloca %struct.in_addr*
%5 = alloca %struct.hostent*
store i8* %0, i8** %3
store %struct.in_addr* %1, %struct.in_addr** %4
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load %struct.in_addr*, %struct.in_addr** %4
%10 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %9, i32 0, i32 0
store i32 0, i32* %10
br label %38
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call %struct.hostent* @gethostbyname(i8* %12)
store %struct.hostent* %13, %struct.hostent** %5
%14 = icmp eq %struct.hostent* %13, null
br i1 %14, label %15, label %26
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = call i32 @inet_addr(i8* %16)
%18 = load %struct.in_addr*, %struct.in_addr** %4
%19 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %18, i32 0, i32 0
store i32 %17, i32* %19
%20 = icmp eq i32 %17, -1
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %15
br label %38
26: ; preds = %11
%27 = load %struct.hostent*, %struct.hostent** %5
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i32 0, i32 1
%29 = load i32*, i32** %28
%30 = getelementptr inbounds i32, i32* %29, i64 0
%31 = load i32, i32* %30
%32 = load %struct.in_addr*, %struct.in_addr** %4
%33 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %32, i32 0, i32 0
%34 = load %struct.hostent*, %struct.hostent** %5
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @bcopy(i32 %31, i32* %33, i32 %36)
br label %38
38: ; preds = %8, %26, %25
ret void
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i32* }
@stderr = global i32 0
@.str = [32 x i8] c"could not resolve from address\0A\00"
define void @resolv_from(i8* %0, %struct.in_addr* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %1, i64 0, i32 0
store i32 0, i32* %5
br label %25
6: ; preds = %2
%7 = tail call %struct.hostent* @gethostbyname(i8* %0)
%8 = icmp eq %struct.hostent* %7, null
br i1 %8, label %9, label %17
9: ; preds = %6
%10 = tail call i32 @inet_addr(i8* %0)
%11 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %1, i64 0, i32 0
store i32 %10, i32* %11
%12 = icmp eq i32 %10, -1
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %6
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 1
%19 = load i32*, i32** %18
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %1, i64 0, i32 0
%22 = getelementptr inbounds %struct.hostent, %struct.hostent* %7, i64 0, i32 0
%23 = load i32, i32* %22
%24 = tail call i32 @bcopy(i32 %20, i32* %21, i32 %23)
br label %25
25: ; preds = %17, %9, %4
ret void
}