#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
  TYPE_1__ sin_addr;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int socket_desc = -1;
  struct sockaddr_in server;
  char *message = NULL;
  char server_reply[2000] = {};
  socket_desc = socket(AF_INET, SOCK_STREAM, 0);
  if (socket_desc == -1) {
    printf("Could not create socket\n");
  }
  server.sin_addr.s_addr = inet_addr("115.239.211.112");
  server.sin_family = AF_INET;
  server.sin_port = htons(80);
  if (connect(socket_desc, (struct sockaddr *)&server, sizeof(server)) < 0) {
    printf("Connect error\n");
    return 1;
  }
  printf("Connected\n");
  message = "GET / HTTP/1.1\r\n\r\n";
  if (send(socket_desc, message, strlen(message), 0) < 0) {
    printf("Send failed.\n");
    return 1;
  }
  printf("Data Send\n");
  if (recv(socket_desc, server_reply, 2000, 0) < 0) {
    printf("recv failed.\n");
  }
  printf("Reply received.\n");
  puts(server_reply);
  close(socket_desc);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x810,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x800(%rbp),%rdi
xor    %esi,%esi
mov    $0x7d0,%edx
call   1090 <memset@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    121d <main+0x6d>
lea    0xde8(%rip),%rdi
call   1080 <printf@plt>
lea    0xdf5(%rip),%rdi
call   10b0 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    0x2db5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x50,%edi
call   1060 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <connect@plt>
cmp    $0x0,%rax
jge    1278 <main+0xc8>
lea    0xdc2(%rip),%rdi
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1343 <main+0x193>
lea    0xdb9(%rip),%rdi
call   1080 <printf@plt>
lea    0xdb8(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x80c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x808(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x80c(%rbp),%edi
mov    -0x808(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0x0,%rax
jge    12e4 <main+0x134>
lea    0xd83(%rip),%rdi
call   1080 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1343 <main+0x193>
lea    0xd79(%rip),%rdi
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x800(%rbp),%rsi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cmp    $0x0,%rax
jge    131c <main+0x16c>
lea    0xd58(%rip),%rdi
call   1080 <printf@plt>
lea    0xd5a(%rip),%rdi
call   1080 <printf@plt>
lea    -0x800(%rbp),%rdi
call   1040 <puts@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x810,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x7e8,%rsp
lea    0x10(%rsp),%rdi
mov    $0x7d0,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    0x2e27(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11e7 <main+0x47>
lea    0xe8d(%rip),%rdi
call   1040 <puts@plt>
lea    0xe12(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    0x0(%rbp),%eax
mov    %eax,0x4(%rsp)
mov    $0x50,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10b0 <connect@plt>
test   %rax,%rax
js     129e <main+0xfe>
lea    0xdfd(%rip),%rdi
call   1040 <puts@plt>
lea    0xdde(%rip),%rbp
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
test   %rax,%rax
js     12a7 <main+0x107>
lea    0xdd9(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rsi
xor    %ebp,%ebp
mov    %ebx,%edi
mov    $0x7d0,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %rax,%rax
jns    127f <main+0xdf>
lea    0xdcd(%rip),%rdi
call   1040 <puts@plt>
lea    0xdb1(%rip),%rdi
call   1040 <puts@plt>
lea    0x10(%rsp),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1090 <close@plt>
jmp    12b8 <main+0x118>
lea    0xdbc(%rip),%rdi
jmp    12ae <main+0x10e>
lea    0xda6(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x7e8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [25 x i8] c"Could not create socket\0A\00"
@.str.1 = [16 x i8] c"115.239.211.112\00"
@.str.2 = [15 x i8] c"Connect error\0A\00"
@.str.3 = [11 x i8] c"Connected\0A\00"
@.str.4 = [19 x i8] c"GET / HTTP/1.1\0D\0A\0D\0A\00"
@.str.5 = [14 x i8] c"Send failed.\0A\00"
@.str.6 = [11 x i8] c"Data Send\0A\00"
@.str.7 = [14 x i8] c"recv failed.\0A\00"
@.str.8 = [17 x i8] c"Reply received.\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 [2000 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i8* null, i8** %8
%10 = bitcast [2000 x i8]* %9 to i8*
%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* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %22, i32* %23
%24 = call i32 @htons(i32 80)
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %24, i32* %25
%26 = load i32, i32* %6
%27 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%28 = call i64 @connect(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %18
%31 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %56
32: ; preds = %18
%33 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i8** %8
%34 = load i32, i32* %6
%35 = load i8*, i8** %8
%36 = load i8*, i8** %8
%37 = call i32 @strlen(i8* %36)
%38 = call i64 @send(i32 %34, i8* %35, i32 %37, i32 0)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %32
%41 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %3
br label %56
42: ; preds = %32
%43 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%44 = load i32, i32* %6
%45 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%46 = call i64 @recv(i32 %44, i8* %45, i32 2000, i32 0)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
br label %50
50: ; preds = %48, %42
%51 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i64 0, i64 0))
%52 = getelementptr inbounds [2000 x i8], [2000 x i8]* %9, i64 0, i64 0
%53 = call i32 @puts(i8* %52)
%54 = load i32, i32* %6
%55 = call i32 @close(i32 %54)
store i32 0, i32* %3
br label %56
56: ; preds = %50, %40, %30
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"115.239.211.112\00"
@.str.4 = [19 x i8] c"GET / HTTP/1.1\0D\0A\0D\0A\00"
@str = [10 x i8] c"Connected\00"
@str.9 = [10 x i8] c"Data Send\00"
@str.10 = [16 x i8] c"Reply received.\00"
@str.11 = [13 x i8] c"recv failed.\00"
@str.12 = [13 x i8] c"Send failed.\00"
@str.13 = [14 x i8] c"Connect error\00"
@str.14 = [24 x i8] c"Could not create socket\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [2000 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [2000 x i8], [2000 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.14, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = tail call i32 @inet_addr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %16, i32* %17
%18 = tail call i32 @htons(i32 80)
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %18, i32* %19
%20 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%21 = call i64 @connect(i32 %9, %struct.sockaddr* %20, i32 12)
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.13, i64 0, i64 0))
br label %42
25: ; preds = %13
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%27 = call i32 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%28 = call i64 @send(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %27, i32 0)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %25
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.12, i64 0, i64 0))
br label %42
32: ; preds = %25
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.9, i64 0, i64 0))
%34 = call i64 @recv(i32 %9, i8* %6, i32 2000, i32 0)
%35 = icmp slt i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.11, i64 0, i64 0))
br label %38
38: ; preds = %36, %32
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.10, i64 0, i64 0))
%40 = call i32 @puts(i8* %6)
%41 = call i32 @close(i32 %9)
br label %42
42: ; preds = %38, %30, %23
%43 = phi i32 [ 1, %23 ], [ 1, %30 ], [ 0, %38 ]
ret i32 %43
}