#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ dr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main() {
  int fd;
  struct sockaddr_in dr;
  char strreq[1024];
  char buf[10 * 1024];
  int r;
  fd = socket(AF_INET, SOCK_STREAM, 0);
  dr.sin_family = AF_INET;
  dr.sin_port = htons(80);
  dr.sin_addr.s_addr = inet_addr("192.168.137.3");
  r = connect(fd, (struct sockaddr *)&dr, sizeof(dr));
  sprintf(strreq, "GET /index.php HTTP/1.1\r\n"
                  "Host : 192.168.137.3:80"
                  "User-Agent : Mozilla/5.0\r\n"
                  "Accept : text/plain,text/html,text/xml\r\n"
                  "Accept-Language : zh-cn\r\n"
                  "Accept-Charset : utf-8\r\n"
                  "Keep-Alive : 300\r\n"
                  "Connection : keep-alive\r\n"
                  "\r\n");
  r = send(fd, strreq, strlen(strreq), 0);
  while (1) {
    r = recv(fd, buf, 1023, 0);
    if (r <= 0) {
      break;
    }
    buf[r] = 0;
    printf("----------------------------\n");
    printf("%s\n", buf);
    printf("----------------------------\n");
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2c40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x50,%edi
call   1050 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    0xe12(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
mov    %eax,-0x2c24(%rbp)
lea    -0x420(%rbp),%rdi
lea    0xdf3(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c34(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x2c30(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c34(%rbp),%edi
mov    -0x2c30(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x2c24(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x2c20(%rbp),%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x2c24(%rbp)
cmpl   $0x0,-0x2c24(%rbp)
jg     128d <main+0xed>
jmp    12d2 <main+0x132>
movslq -0x2c24(%rbp),%rax
movb   $0x0,-0x2c20(%rbp,%rax,1)
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x2c20(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    125f <main+0xbf>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x2c40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2c10,%rsp
mov    0x2e36(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,%r14d
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    $0x50,%edi
call   1060 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe1e(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10b0 <connect@plt>
lea    0xe0d(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    $0xd1,%edx
mov    %rbx,%rdi
call   10a0 <memcpy@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
lea    0x410(%rsp),%rsi
mov    %r14d,%edi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1298 <main+0xf8>
lea    0xe93(%rip),%rbx
lea    0x410(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%eax
movb   $0x0,0x410(%rsp,%rax,1)
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x3ff,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jg     1260 <main+0xc0>
mov    %r14d,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x2c10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [14 x i8] c"192.168.137.3\00"
@.str.1 = [209 x i8] c"GET /index.php HTTP/1.1\0D\0AHost : 192.168.137.3:80User-Agent : Mozilla/5.0\0D\0AAccept : text/plain,text/html,text/xml\0D\0AAccept-Language : zh-cn\0D\0AAccept-Charset : utf-8\0D\0AKeep-Alive : 300\0D\0AConnection : keep-alive\0D\0A\0D\0A\00"
@.str.2 = [30 x i8] c"----------------------------\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
%5 = alloca [10240 x i8]
%6 = alloca i32
store i32 0, i32* %1
%7 = load i32, i32* @AF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %2
%10 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %10, i32* %11
%12 = call i32 @htons(i32 80)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %12, i32* %13
%14 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%16 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %15, i32 0, i32 0
store i32 %14, i32* %16
%17 = load i32, i32* %2
%18 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%19 = call i32 @connect(i32 %17, %struct.sockaddr* %18, i32 12)
store i32 %19, i32* %6
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%21 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([209 x i8], [209 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* %2
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = call i32 @send(i32 %22, i8* %23, i32 %25, i32 0)
store i32 %26, i32* %6
br label %27
27: ; preds = %0, %34
%28 = load i32, i32* %2
%29 = getelementptr inbounds [10240 x i8], [10240 x i8]* %5, i64 0, i64 0
%30 = call i32 @recv(i32 %28, i8* %29, i32 1023, i32 0)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp sle i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
br label %42
34: ; preds = %27
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [10240 x i8], [10240 x i8]* %5, i64 0, i64 %36
store i8 0, i8* %37
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%39 = getelementptr inbounds [10240 x i8], [10240 x i8]* %5, i64 0, i64 0
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
br label %27
42: ; preds = %33
%43 = load i32, i32* %2
%44 = call i32 @close(i32 %43)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [14 x i8] c"192.168.137.3\00"
@.str.1 = [209 x i8] c"GET /index.php HTTP/1.1\0D\0AHost : 192.168.137.3:80User-Agent : Mozilla/5.0\0D\0AAccept : text/plain,text/html,text/xml\0D\0AAccept-Language : zh-cn\0D\0AAccept-Charset : utf-8\0D\0AKeep-Alive : 300\0D\0AConnection : keep-alive\0D\0A\0D\0A\00"
@str.4 = [29 x i8] c"----------------------------\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [1024 x i8]
%3 = alloca [10240 x i8]
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [10240 x i8], [10240 x i8]* %3, 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 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %10, i32* %11
%12 = tail call i32 @htons(i32 80)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %12, i32* %13
%14 = tail call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %14, i32* %15
%16 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%17 = call i32 @connect(i32 %9, %struct.sockaddr* %16, i32 12)
%18 = call i32 @strlen(i8* %5)
%19 = call i32 @send(i32 %9, i8* %5, i32 %18, i32 0)
%20 = call i32 @recv(i32 %9, i8* %6, i32 1023, i32 0)
%21 = icmp slt i32 %20, 1
br i1 %21, label %31, label %22
22: ; preds = %0, %22
%23 = phi i32 [ %29, %22 ], [ %20, %0 ]
%24 = zext i32 %23 to i64
%25 = getelementptr inbounds [10240 x i8], [10240 x i8]* %3, i64 0, i64 %24
store i8 0, i8* %25
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.4, i64 0, i64 0))
%27 = call i32 @puts(i8* %6)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.4, i64 0, i64 0))
%29 = call i32 @recv(i32 %9, i8* %6, i32 1023, i32 0)
%30 = icmp slt i32 %29, 1
br i1 %30, label %31, label %22
31: ; preds = %22, %0
%32 = call i32 @close(i32 %9)
ret i32 0
}