#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 dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ error(char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
void connecttoDNSserver(struct sockaddr_in *serveradd) {
  struct hostent *Server;
  if ((Server = gethostbyname("NS1.oregonstate.edu")) == NULL)
    error("ERROR, no such host\n");
  serveradd->sin_family = AF_INET;
  serveradd->sin_port = htons(53);
  serveradd->sin_addr = *((struct in_addr *)Server->h_addr);
}


x86 assembly (clang, -O0):
<connecttoDNSserver>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1162 <connecttoDNSserver+0x32>
lea    0xeb7(%rip),%rdi
call   1050 <error@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    $0x35,%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connecttoDNSserver>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xec2(%rip),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1157 <connecttoDNSserver+0x27>
lea    0xec2(%rip),%rdi
call   1050 <error@plt>
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    $0x35,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rbx)
mov    (%r14),%rax
mov    (%rax),%eax
mov    %eax,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
@.str = [20 x i8] c"NS1.oregonstate.edu\00"
@.str.1 = [21 x i8] c"ERROR, no such host\0A\00"
@AF_INET = global i32 0
define void @connecttoDNSserver(%struct.sockaddr_in* %0) {
%2 = alloca %struct.sockaddr_in*
%3 = alloca %struct.hostent*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %2
%4 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store %struct.hostent* %4, %struct.hostent** %3
%5 = icmp eq %struct.hostent* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i32, i32* @AF_INET
%10 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %9, i32* %11
%12 = call i32 @htons(i32 53)
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
store i32 %12, i32* %14
%15 = load %struct.sockaddr_in*, %struct.sockaddr_in** %2
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 0
%17 = load %struct.hostent*, %struct.hostent** %3
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to %struct.in_addr*
%21 = bitcast %struct.in_addr* %16 to i8*
%22 = bitcast %struct.in_addr* %20 to i8*
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
@.str = [20 x i8] c"NS1.oregonstate.edu\00"
@.str.1 = [21 x i8] c"ERROR, no such host\0A\00"
@AF_INET = global i32 0
define void @connecttoDNSserver(%struct.sockaddr_in* nocapture writeonly %0) {
%2 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq %struct.hostent* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 2
store i32 %7, i32* %8
%9 = tail call i32 @htons(i32 53)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1
store i32 %9, i32* %10
%11 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%12 = load i64, i64* %11
%13 = inttoptr i64 %12 to i32*
%14 = getelementptr %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0, i32 0
%15 = load i32, i32* %13
store i32 %15, i32* %14
ret void
}