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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(void *, int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  struct sockaddr_in addr;
  struct in_addr *a;
  struct hostent *h;
  int fd, n, addrlen;
  if ((h = gethostbyname("tejo")) == NULL)
    exit(1);
  a = (struct in_addr *)h->h_addr_list[0];
  fd = socket(AF_INET, SOCK_STREAM, 0);
  if (fd == -1) {
    exit(1);
  }
  addrlen = sizeof(addr);
  memset((void *)&addr, (int)'\0', addrlen);
  addr.sin_family = AF_INET;
  addr.sin_addr = *a;
  addr.sin_port = htons(8000);
  n = connect(fd, (struct sockaddr *)&addr, addrlen);
  if (n == -1)
    exit(1);
  close(fd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11a3 <main+0x33>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    11e1 <main+0x71>
mov    $0x1,%edi
call   1070 <exit@plt>
movl   $0xc,-0x2c(%rbp)
lea    -0x10(%rbp),%rdi
mov    -0x2c(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x1f40,%edi
call   1030 <htons@plt>
mov    %eax,-0x10(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1080 <connect@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    123e <main+0xce>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe7e(%rip),%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     11f9 <main+0x89>
mov    (%rax),%rax
mov    (%rax),%r15
mov    0x2e4f(%rip),%r12
mov    (%r12),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
cmp    $0xffffffff,%eax
je     11f9 <main+0x89>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    (%r12),%eax
mov    %eax,0x10(%rsp)
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    $0x1f40,%edi
call   1030 <htons@plt>
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
jne    1203 <main+0x93>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64* }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"tejo\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca %struct.in_addr*
%4 = alloca %struct.hostent*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store %struct.hostent* %8, %struct.hostent** %4
%9 = icmp eq %struct.hostent* %8, null
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = load %struct.hostent*, %struct.hostent** %4
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i32 0, i32 0
%15 = load i64*, i64** %14
%16 = getelementptr inbounds i64, i64* %15, i64 0
%17 = load i64, i64* %16
%18 = inttoptr i64 %17 to %struct.in_addr*
store %struct.in_addr* %18, %struct.in_addr** %3
%19 = load i32, i32* @AF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %12
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %12
store i32 12, i32* %7
%27 = bitcast %struct.sockaddr_in* %2 to i8*
%28 = load i32, i32* %7
%29 = call i32 @memset(i8* %27, i32 0, i32 %28)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 2
store i32 %30, i32* %31
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 1
%33 = load %struct.in_addr*, %struct.in_addr** %3
%34 = bitcast %struct.in_addr* %32 to i8*
%35 = bitcast %struct.in_addr* %33 to i8*
%36 = call i32 @htons(i32 8000)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i32 0, i32 0
store i32 %36, i32* %37
%38 = load i32, i32* %5
%39 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%40 = load i32, i32* %7
%41 = call i32 @connect(i32 %38, %struct.sockaddr* %39, i32 %40)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %46
44: ; preds = %26
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %26
%47 = load i32, i32* %5
%48 = call i32 @close(i32 %47)
%49 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64* }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"tejo\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = bitcast %struct.sockaddr_in* %1 to i8*
%3 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq %struct.hostent* %3, null
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%9 = load i64*, i64** %8
%10 = load i64, i64* %9
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = tail call i32 @exit(i32 1)
unreachable
17: ; preds = %7
%18 = call i32 @memset(i8* %2, i32 0, i32 12)
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %19, i32* %20
%21 = inttoptr i64 %10 to i32*
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
%23 = load i32, i32* %21
store i32 %23, i32* %22
%24 = call i32 @htons(i32 8000)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %24, i32* %25
%26 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%27 = call i32 @connect(i32 %13, %struct.sockaddr* %26, i32 12)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %17
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %17
%32 = call i32 @close(i32 %13)
%33 = call i32 @exit(i32 0)
unreachable
}