#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 */
typedef int /*<<< orphan*/ tv;
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};
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*/ SOL_SOCKET;
int /*<<< orphan*/ SO_RCVTIMEO;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              char const *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sock;
  struct sockaddr_in server;
  char message[1000], server_reply[2000];
  sock = socket(AF_INET, SOCK_STREAM, 0);
  if (sock == -1) {
    printf("Could not create socket");
  }
  puts("Socket created");
  server.sin_addr.s_addr = inet_addr("128.6.13.219");
  server.sin_family = AF_INET;
  server.sin_port = htons(8888);
  if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0) {
    perror("connect failed. Error");
    return 1;
  }
  puts("Connected\n");
  char *buffer = "GET / HTTP/1.0\r\n\r\n";
  int wSize = 0;
  wSize = write(sock, buffer, strlen(buffer));
  printf("return value of wSize %d\n", wSize);
  puts("message has been sent, prepare to get the respond from the server");
  if (wSize < 0) {
    puts("Send failed");
    return 1;
  }
  puts("Server reply :");
  char resp[10000];
  int len;
  struct timeval tv;
  tv.tv_sec = 5;
  tv.tv_usec = 0;
  setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof(tv));
  while (1) {
    len = read(sock, resp, 9999);
    printf("%s\n", resp);
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3330,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11fd <main+0x4d>
lea    0xe0a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xe14(%rip),%rdi
call   1030 <puts@plt>
lea    0xe17(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x22b8,%edi
call   1070 <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    1264 <main+0xb4>
lea    0xde1(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1386 <main+0x1d6>
lea    0xddf(%rip),%rdi
call   1030 <puts@plt>
lea    0xdde(%rip),%rax
mov    %rax,-0xbe8(%rbp)
movl   $0x0,-0xbec(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x3324(%rbp)
mov    -0xbe8(%rbp),%rax
mov    %rax,-0x3320(%rbp)
mov    -0xbe8(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x3324(%rbp),%edi
mov    -0x3320(%rbp),%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %eax,-0xbec(%rbp)
mov    -0xbec(%rbp),%esi
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xda2(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x0,-0xbec(%rbp)
jge    130a <main+0x15a>
lea    0xdcb(%rip),%rdi
call   1030 <puts@plt>
movl   $0x1,-0x4(%rbp)
jmp    1386 <main+0x1d6>
lea    0xdbf(%rip),%rdi
call   1030 <puts@plt>
movl   $0x5,-0x3318(%rbp)
movq   $0x0,-0x3310(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2cb3(%rip),%rax
mov    (%rax),%esi
mov    0x2c92(%rip),%rax
mov    (%rax),%edx
lea    -0x3318(%rbp),%rcx
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
mov    -0x14(%rbp),%edi
lea    -0x3300(%rbp),%rsi
mov    $0x270f,%edx
call   1090 <read@plt>
mov    %eax,-0x3304(%rbp)
lea    -0x3300(%rbp),%rsi
lea    0xd65(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1352 <main+0x1a2>
mov    -0x4(%rbp),%eax
add    $0x3330,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x2738,%rsp
mov    0x2e20(%rip),%rbx
mov    (%rbx),%edi
mov    0x2dff(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11e7 <main+0x37>
lea    0xe20(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe2a(%rip),%rdi
call   1030 <puts@plt>
lea    0xe2d(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x8(%rsp)
mov    (%rbx),%eax
mov    %eax,0x4(%rsp)
mov    $0x22b8,%edi
call   1070 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10c0 <connect@plt>
test   %rax,%rax
js     12f4 <main+0x144>
lea    0xe15(%rip),%rdi
call   1030 <puts@plt>
lea    0xe14(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
mov    %eax,%ebx
lea    0xe0a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xe14(%rip),%rdi
call   1030 <puts@plt>
test   %ebx,%ebx
js     12d9 <main+0x129>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
movl   $0x5,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%esi
mov    0x2d2c(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    %ebp,%edi
mov    $0x10,%r8d
call   1040 <setsockopt@plt>
lea    0x20(%rsp),%rbx
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x270f,%edx
call   1090 <read@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
jmp    12c0 <main+0x110>
lea    0xde4(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
add    $0x2738,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xd39(%rip),%rdi
call   10b0 <perror@plt>
jmp    12e5 <main+0x135>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c"Could not create socket\00"
@.str.1 = [15 x i8] c"Socket created\00"
@.str.2 = [13 x i8] c"128.6.13.219\00"
@.str.3 = [22 x i8] c"connect failed. Error\00"
@.str.4 = [11 x i8] c"Connected\0A\00"
@.str.5 = [19 x i8] c"GET / HTTP/1.0\0D\0A\0D\0A\00"
@.str.6 = [26 x i8] c"return value of wSize %d\0A\00"
@.str.7 = [66 x i8] c"message has been sent, prepare to get the respond from the server\00"
@.str.8 = [12 x i8] c"Send failed\00"
@.str.9 = [15 x i8] c"Server reply :\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
@.str.10 = [4 x i8] c"%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 [1000 x i8]
%9 = alloca [2000 x i8]
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [10000 x i8]
%13 = alloca i32
%14 = alloca %struct.timeval
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = call i32 @socket(i32 %15, i32 %16, i32 0)
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %2
%23 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @inet_addr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
store i32 %27, i32* %28
%29 = call i32 @htons(i32 8888)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %29, i32* %30
%31 = load i32, i32* %6
%32 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%33 = call i64 @connect(i32 %31, %struct.sockaddr* %32, i32 12)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %22
%36 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %66
37: ; preds = %22
%38 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8** %10
store i32 0, i32* %11
%39 = load i32, i32* %6
%40 = load i8*, i8** %10
%41 = load i8*, i8** %10
%42 = call i32 @strlen(i8* %41)
%43 = call i32 @write(i32 %39, i8* %40, i32 %42)
store i32 %43, i32* %11
%44 = load i32, i32* %11
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %44)
%46 = call i32 @puts(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.7, i64 0, i64 0))
%47 = load i32, i32* %11
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %37
%50 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %66
51: ; preds = %37
%52 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
store i32 5, i32* %53
%54 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
store i64 0, i64* %54
%55 = load i32, i32* %6
%56 = load i32, i32* @SOL_SOCKET
%57 = load i32, i32* @SO_RCVTIMEO
%58 = bitcast %struct.timeval* %14 to i8*
%59 = call i32 @setsockopt(i32 %55, i32 %56, i32 %57, i8* %58, i32 16)
br label %60
60: ; preds = %51, %60
%61 = load i32, i32* %6
%62 = getelementptr inbounds [10000 x i8], [10000 x i8]* %12, i64 0, i64 0
%63 = call i32 @read(i32 %61, i8* %62, i32 9999)
store i32 %63, i32* %13
%64 = getelementptr inbounds [10000 x i8], [10000 x i8]* %12, i64 0, i64 0
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %64)
br label %60
66: ; preds = %49, %35
%67 = load i32, i32* %3
ret i32 %67
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c"Could not create socket\00"
@.str.1 = [15 x i8] c"Socket created\00"
@.str.2 = [13 x i8] c"128.6.13.219\00"
@.str.3 = [22 x i8] c"connect failed. Error\00"
@.str.4 = [11 x i8] c"Connected\0A\00"
@.str.5 = [19 x i8] c"GET / HTTP/1.0\0D\0A\0D\0A\00"
@.str.6 = [26 x i8] c"return value of wSize %d\0A\00"
@.str.7 = [66 x i8] c"message has been sent, prepare to get the respond from the server\00"
@.str.8 = [12 x i8] c"Send failed\00"
@.str.9 = [15 x i8] c"Server reply :\00"
@SOL_SOCKET = global i32 0
@SO_RCVTIMEO = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [10000 x i8]
%5 = alloca %struct.timeval
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%15 = tail call i32 @inet_addr(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2, i32 0
store i32 %15, i32* %16
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %17, i32* %18
%19 = tail call i32 @htons(i32 8888)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %19, i32* %20
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i64 @connect(i32 %9, %struct.sockaddr* %21, i32 12)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %13
%25 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %47
26: ; preds = %13
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0))
%29 = call i32 @write(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %28)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0), i32 %29)
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.7, i64 0, i64 0))
%32 = icmp slt i32 %29, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
br label %47
35: ; preds = %26
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.9, i64 0, i64 0))
%37 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%38 = bitcast %struct.timeval* %5 to i8*
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
store i32 5, i32* %39
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
store i64 0, i64* %40
%41 = load i32, i32* @SOL_SOCKET
%42 = load i32, i32* @SO_RCVTIMEO
%43 = call i32 @setsockopt(i32 %9, i32 %41, i32 %42, i8* %38, i32 16)
br label %44
44: ; preds = %44, %35
%45 = call i32 @read(i32 %9, i8* %37, i32 9999)
%46 = call i32 @puts(i8* %37)
br label %44
47: ; preds = %33, %24
ret i32 1
}