#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_port;
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  scalar_t__ ai_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ getaddrinfo(char *, int /*<<< orphan*/ *,
                               int /*<<< orphan*/ *, struct addrinfo **);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntoa(struct in_addr);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int ac, char *av[]) {
  int socket_handle;
  struct sockaddr_in socket_details;
  char *input_buffer;
  char httpget[] = "GET / HTTP/1.0\r\n\r\n";
  struct addrinfo *result;
  getaddrinfo("www.naver.com", NULL, NULL, &result);
  struct in_addr ip = ((struct sockaddr_in *)(result->ai_addr))->sin_addr;
  input_buffer = malloc(20000);
  socket_handle = socket(AF_INET, SOCK_STREAM, 0);
  socket_details.sin_family = AF_INET;
  socket_details.sin_addr.s_addr = inet_addr(inet_ntoa(ip));
  socket_details.sin_port = htons(80);
  connect(socket_handle, (struct sockaddr *)&socket_details,
          sizeof(struct sockaddr));
  send(socket_handle, httpget, strlen(httpget), 0);
  recv(socket_handle, input_buffer, 20000, 0);
  printf("input: %s\n", input_buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe33(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe30(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe2d(%rip),%ax
mov    %ax,-0x30(%rbp)
mov    0xe25(%rip),%al
mov    %al,-0x2e(%rbp)
lea    0xe1c(%rip),%rdi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x48(%rbp),%rcx
mov    %rdx,%rsi
call   10c0 <getaddrinfo@plt>
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x50(%rbp)
mov    $0x4e20,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x50(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %eax,%edi
call   1090 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x50,%edi
call   1060 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   10b0 <connect@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x5c(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
lea    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x4e20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    -0x28(%rbp),%rsi
lea    0xd62(%rip),%rdi
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
movaps 0xe3f(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0xa0d0a,0x2f(%rsp)
lea    0xe3e(%rip),%rdi
lea    0x18(%rsp),%rcx
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <getaddrinfo@plt>
mov    0x18(%rsp),%rax
mov    (%rax),%rax
mov    0x4(%rax),%ebx
mov    $0x4e20,%edi
call   10a0 <malloc@plt>
mov    %rax,%r14
mov    0x2de6(%rip),%r15
mov    (%r15),%edi
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
mov    (%r15),%eax
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
call   1040 <inet_ntoa@plt>
mov    %eax,%edi
call   1090 <inet_addr@plt>
mov    %eax,0xc(%rsp)
mov    $0x50,%edi
call   1060 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   10b0 <connect@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x4e20,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xd9f(%rip),%rdi
mov    %r14,%rsi
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.addrinfo = type { i64 }
%struct.sockaddr = type { i32 }
@__const.main.httpget = [19 x i8] c"GET / HTTP/1.0\0D\0A\0D\0A\00"
@.str = [14 x i8] c"www.naver.com\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [11 x i8] c"input: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_in
%8 = alloca i8*
%9 = alloca [19 x i8]
%10 = alloca %struct.addrinfo*
%11 = alloca %struct.in_addr
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [19 x i8]* %9 to i8*
%13 = call i32 @getaddrinfo(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* null, i32* null, %struct.addrinfo** %10)
%14 = load %struct.addrinfo*, %struct.addrinfo** %10
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = inttoptr i64 %16 to %struct.sockaddr_in*
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 1
%19 = bitcast %struct.in_addr* %11 to i8*
%20 = bitcast %struct.in_addr* %18 to i8*
%21 = call i8* @malloc(i32 20000)
store i8* %21, i8** %8
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %6
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %11, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @inet_ntoa(i32 %28)
%30 = call i32 @inet_addr(i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%32 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %31, i32 0, i32 0
store i32 %30, i32* %32
%33 = call i32 @htons(i32 80)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %33, i32* %34
%35 = load i32, i32* %6
%36 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%37 = call i32 @connect(i32 %35, %struct.sockaddr* %36, i32 4)
%38 = load i32, i32* %6
%39 = getelementptr inbounds [19 x i8], [19 x i8]* %9, i64 0, i64 0
%40 = getelementptr inbounds [19 x i8], [19 x i8]* %9, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = call i32 @send(i32 %38, i8* %39, i32 %41, i32 0)
%43 = load i32, i32* %6
%44 = load i8*, i8** %8
%45 = call i32 @recv(i32 %43, i8* %44, i32 20000, i32 0)
%46 = load i8*, i8** %8
%47 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %46)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32 }
%struct.in_addr = type { i32 }
%struct.addrinfo = type { i64 }
%struct.sockaddr = type { i32 }
@__const.main.httpget = [19 x i8] c"GET / HTTP/1.0\0D\0A\0D\0A\00"
@.str = [14 x i8] c"www.naver.com\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [11 x i8] c"input: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [19 x i8]
%5 = alloca %struct.addrinfo*
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [19 x i8], [19 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.addrinfo** %5 to i8*
%9 = call i32 @getaddrinfo(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32* null, i32* null, %struct.addrinfo** %5)
%10 = load %struct.addrinfo*, %struct.addrinfo** %5
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i64 0, i32 0
%12 = load i64, i64* %11
%13 = inttoptr i64 %12 to %struct.sockaddr_in*
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i64 0, i32 1, i32 0
%15 = load i32, i32* %14
%16 = call dereferenceable_or_null(20000) i8* @malloc(i32 20000)
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @inet_ntoa(i32 %15)
%23 = call i32 @inet_addr(i32 %22)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %23, i32* %24
%25 = call i32 @htons(i32 80)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %25, i32* %26
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i32 @connect(i32 %19, %struct.sockaddr* %27, i32 4)
%29 = call i32 @strlen(i8* %7)
%30 = call i32 @send(i32 %19, i8* %7, i32 %29, i32 0)
%31 = call i32 @recv(i32 %19, i8* %16, i32 20000, i32 0)
%32 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %16)
ret i32 0
}