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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ bzero(int /*<<< orphan*/, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, char *);
int setNetInfo(struct sockaddr_in *netData, char *host, int port) {
  struct hostent *rel;
  if (host != NULL) {
    if ((rel = gethostbyname(host)) == NULL) {
      printf("Can't find server '%s'!\n", host);
      exit(EXIT_FAILURE);
    }
    (netData->sin_addr) = *((struct in_addr *)rel->h_addr);
  } else
    (netData->sin_addr.s_addr) = INADDR_ANY;
  (netData->sin_family) = AF_INET;
  (netData->sin_port) = htons(port);
  bzero(netData->sin_zero, 8);
  return 0;
}


x86 assembly (clang, -O0):
<setNetInfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b8 <setNetInfo+0x68>
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a3 <setNetInfo+0x53>
mov    -0x10(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
mov    (%rcx),%ecx
mov    %ecx,0xc(%rax)
jmp    11c8 <setNetInfo+0x78>
mov    0x2e21(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    0x2e19(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    $0x8,%esi
call   1060 <bzero@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setNetInfo>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rdi,%rbx
test   %rsi,%rsi
je     1174 <setNetInfo+0x24>
mov    %rsi,%rbp
mov    %rsi,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     11aa <setNetInfo+0x5a>
mov    (%rax),%rax
jmp    117b <setNetInfo+0x2b>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rbx)
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,0x4(%rbx)
mov    (%rbx),%edi
mov    $0x8,%esi
call   1060 <bzero@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe4f(%rip),%rdi
mov    %rbp,%rsi
call   1040 <printf@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32, %struct.in_addr }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
@.str = [25 x i8] c"Can't find server '%s'!\0A\00"
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@AF_INET = global i32 0
define i32 @setNetInfo(%struct.sockaddr_in* %0, i8* %1, i32 %2) {
%4 = alloca %struct.sockaddr_in*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.hostent*
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %28
10: ; preds = %3
%11 = load i8*, i8** %5
%12 = call %struct.hostent* @gethostbyname(i8* %11)
store %struct.hostent* %12, %struct.hostent** %7
%13 = icmp eq %struct.hostent* %12, null
br i1 %13, label %14, label %19
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %10
%20 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 3
%22 = load %struct.hostent*, %struct.hostent** %7
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %22, i32 0, i32 0
%24 = load i64, i64* %23
%25 = inttoptr i64 %24 to %struct.in_addr*
%26 = bitcast %struct.in_addr* %21 to i8*
%27 = bitcast %struct.in_addr* %25 to i8*
br label %33
28: ; preds = %3
%29 = load i32, i32* @INADDR_ANY
%30 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %30, i32 0, i32 3
%32 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %31, i32 0, i32 0
store i32 %29, i32* %32
br label %33
33: ; preds = %28, %19
%34 = load i32, i32* @AF_INET
%35 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %35, i32 0, i32 2
store i32 %34, i32* %36
%37 = load i32, i32* %6
%38 = call i32 @htons(i32 %37)
%39 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %39, i32 0, i32 1
store i32 %38, i32* %40
%41 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i32 @bzero(i32 %43, i32 8)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32, %struct.in_addr }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
@.str = [25 x i8] c"Can't find server '%s'!\0A\00"
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@AF_INET = global i32 0
define i32 @setNetInfo(%struct.sockaddr_in* nocapture %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %1, null
br i1 %4, label %18, label %5
5: ; preds = %3
%6 = tail call %struct.hostent* @gethostbyname(i8* %1)
%7 = icmp eq %struct.hostent* %6, null
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = tail call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %1)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %5
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %6, i64 0, i32 0
%14 = load i64, i64* %13
%15 = inttoptr i64 %14 to i32*
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 3, i32 0
%17 = load i32, i32* %15
store i32 %17, i32* %16
br label %21
18: ; preds = %3
%19 = load i32, i32* @INADDR_ANY
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 3, i32 0
store i32 %19, i32* %20
br label %21
21: ; preds = %18, %12
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 2
store i32 %22, i32* %23
%24 = tail call i32 @htons(i32 %2)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1
store i32 %24, i32* %25
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0
%27 = load i32, i32* %26
%28 = tail call i32 @bzero(i32 %27, i32 8)
ret i32 0
}