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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, struct in_addr *, int);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  struct sockaddr_in serverip;
  struct hostent *remotehost;
  int retval;
  int addrlen;
  int serversocket;
  serversocket = socket(AF_INET, SOCK_STREAM, 0);
  printf("1\n");
  serverip.sin_family = AF_INET;
  serverip.sin_port = htons(atoi("6667"));
  printf("1.5\n");
  remotehost = gethostbyname("localhost");
  printf("2\n");
  memcpy(&serverip.sin_addr, *((struct in_addr **)remotehost->h_addr_list),
         sizeof(struct in_addr));
  printf("3\n");
  retval =
      connect(serversocket, (struct sockaddr *)&serverip, sizeof(serverip));
  printf("4\n");
  close(serversocket);
  printf("6\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x34(%rbp)
lea    0xe47(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xe32(%rip),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
call   1030 <htons@plt>
mov    %eax,-0x1c(%rbp)
lea    0xe21(%rip),%rdi
call   1040 <printf@plt>
lea    0xe1a(%rip),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
lea    0xe14(%rip),%rdi
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rsi
mov    $0x4,%edx
call   1070 <memcpy@plt>
lea    0xdf3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x34(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
mov    %eax,-0x2c(%rbp)
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
lea    0xdc5(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x2e6b(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebp
lea    0xe72(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    $0x1a0b,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
lea    0xe54(%rip),%rdi
call   1030 <puts@plt>
lea    0xe3c(%rip),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,%rbx
lea    0xe3d(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%rax
mov    (%rax),%rsi
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x4,%edx
call   1070 <memcpy@plt>
lea    0xe1b(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1080 <connect@plt>
lea    0xe02(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xdf1(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [3 x i8] c"1\0A\00"
@.str.1 = [5 x i8] c"6667\00"
@.str.2 = [5 x i8] c"1.5\0A\00"
@.str.3 = [10 x i8] c"localhost\00"
@.str.4 = [3 x i8] c"2\0A\00"
@.str.5 = [3 x i8] c"3\0A\00"
@.str.6 = [3 x i8] c"4\0A\00"
@.str.7 = [3 x i8] c"6\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.hostent*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %10
%14 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %15, i32* %16
%17 = call i32 @atoi(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @htons(i32 %17)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %18, i32* %19
%20 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%21 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store %struct.hostent* %21, %struct.hostent** %7
%22 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%24 = load %struct.hostent*, %struct.hostent** %7
%25 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = inttoptr i64 %26 to %struct.in_addr**
%28 = load %struct.in_addr*, %struct.in_addr** %27
%29 = call i32 @memcpy(i32* %23, %struct.in_addr* %28, i32 4)
%30 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%31 = load i32, i32* %10
%32 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%33 = call i32 @connect(i32 %31, %struct.sockaddr* %32, i32 12)
store i32 %33, i32* %8
%34 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%35 = load i32, i32* %10
%36 = call i32 @close(i32 %35)
%37 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [10 x i8] c"localhost\00"
@str = [2 x i8] c"1\00"
@str.8 = [4 x i8] c"1.5\00"
@str.9 = [2 x i8] c"2\00"
@str.10 = [2 x i8] c"3\00"
@str.11 = [2 x i8] c"4\00"
@str.12 = [2 x i8] c"6\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = bitcast %struct.sockaddr_in* %3 to i8*
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %9, i32* %10
%11 = tail call i32 @htons(i32 6667)
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %11, i32* %12
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.8, i64 0, i64 0))
%14 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.9, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i64 0, i32 0
%18 = load i64, i64* %17
%19 = inttoptr i64 %18 to %struct.in_addr**
%20 = load %struct.in_addr*, %struct.in_addr** %19
%21 = call i32 @memcpy(i32* %16, %struct.in_addr* %20, i32 4)
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0))
%23 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%24 = call i32 @connect(i32 %7, %struct.sockaddr* %23, i32 12)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.11, i64 0, i64 0))
%26 = call i32 @close(i32 %7)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.12, i64 0, i64 0))
ret i32 0
}