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

/* Variables and functions */
int /*<<< orphan*/ bcopy(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int inet_addr(char *);
int /*<<< orphan*/ printf(char *, char *);
u_long nameResolve(char *hostname) {
  struct in_addr addr;
  struct hostent *hostEnt;
  if ((addr.s_addr = inet_addr(hostname)) == -1) {
    if (!(hostEnt = gethostbyname(hostname))) {
      printf("Name Resolution Error:`%s`\n", hostname);
      exit(0);
    }
    bcopy(hostEnt->h_addr, (char *)&addr.s_addr, hostEnt->h_length);
  }
  return addr.s_addr;
}


x86 assembly (clang, -O0):
<nameResolve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %eax,-0x10(%rbp)
cmp    $0xffffffff,%eax
jne    11b5 <nameResolve+0x65>
mov    -0x8(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    119f <nameResolve+0x4f>
mov    -0x8(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1060 <bcopy@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nameResolve>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1040 <inet_addr@plt>
mov    %eax,0x8(%rsp)
cmp    $0xffffffff,%eax
jne    1186 <nameResolve+0x36>
mov    %rbx,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     118c <nameResolve+0x3c>
mov    (%rax),%edx
mov    0x4(%rax),%edi
lea    0x8(%rsp),%rsi
call   1060 <bcopy@plt>
mov    0x8(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe6d(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i32 }
@.str = [28 x i8] c"Name Resolution Error:`%s`\0A\00"
define i32 @nameResolve(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.in_addr
%4 = alloca %struct.hostent*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @inet_addr(i8* %5)
%7 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
store i32 %6, i32* %7
%8 = icmp eq i32 %6, -1
br i1 %8, label %9, label %27
9: ; preds = %1
%10 = load i8*, i8** %2
%11 = call %struct.hostent* @gethostbyname(i8* %10)
store %struct.hostent* %11, %struct.hostent** %4
%12 = icmp ne %struct.hostent* %11, null
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = load i8*, i8** %2
%15 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %9
%18 = load %struct.hostent*, %struct.hostent** %4
%19 = getelementptr inbounds %struct.hostent, %struct.hostent* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%22 = bitcast i32* %21 to i8*
%23 = load %struct.hostent*, %struct.hostent** %4
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 0
%25 = load i32, i32* %24
%26 = call i32 @bcopy(i32 %20, i8* %22, i32 %25)
br label %27
27: ; preds = %17, %1
%28 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %3, i32 0, i32 0
%29 = load i32, i32* %28
ret i32 %29
}

LLVM IR (-O2):
%struct.in_addr = type { i32 }
%struct.hostent = type { i32, i32 }
@.str = [28 x i8] c"Name Resolution Error:`%s`\0A\00"
define i32 @nameResolve(i8* %0) {
%2 = alloca %struct.in_addr
%3 = bitcast %struct.in_addr* %2 to i8*
%4 = tail call i32 @inet_addr(i8* %0)
%5 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %2, i64 0, i32 0
store i32 %4, i32* %5
%6 = icmp eq i32 %4, -1
br i1 %6, label %7, label %20
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 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %7
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @bcopy(i32 %15, i8* %3, i32 %17)
%19 = load i32, i32* %5
br label %20
20: ; preds = %13, %1
%21 = phi i32 [ %19, %13 ], [ %4, %1 ]
ret i32 %21
}