#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;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ get;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ address;

/* 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*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockfd;
  socklen_t len;
  struct sockaddr_in address;
  int result;
  char buf[32] = "GET /index.html HTTP/1.1\n\n\n";
  char get[2048] = {0};
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  address.sin_family = AF_INET;
  address.sin_addr.s_addr = inet_addr("127.0.0.1");
  address.sin_port = htons(11000);
  len = sizeof(address);
  result = connect(sockfd, (struct sockaddr *)&address, len);
  if (result == -1) {
    perror("oops: client1");
    return 1;
  }
  write(sockfd, buf, sizeof(buf));
  read(sockfd, get, sizeof(get));
  printf("---------------------------------------------------\n");
  printf("recv from server:\n%s\n", get);
  printf("---------------------------------------------------\n");
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe40(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xe3d(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xe3a(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe37(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    -0x850(%rbp),%rdi
xor    %esi,%esi
mov    $0x800,%edx
call   1060 <memset@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
mov    0x2dd0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xdf9(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    $0x2af8,%edi
call   1040 <htons@plt>
mov    %eax,-0x28(%rbp)
movl   $0xc,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   10b0 <connect@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1277 <main+0xd7>
lea    0xdc4(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12dc <main+0x13c>
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x20,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
lea    -0x850(%rbp),%rsi
mov    $0x800,%edx
call   1080 <read@plt>
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x850(%rbp),%rsi
lea    0xdb5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x838,%rsp
movaps 0xe4c(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe30(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x30(%rsp),%rdi
xor    %r14d,%r14d
mov    $0x800,%edx
xor    %esi,%esi
call   1070 <memset@plt>
mov    0x2df8(%rip),%rbx
mov    (%rbx),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xe0f(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x2af8,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   10c0 <connect@plt>
cmp    $0xffffffff,%eax
je     12a0 <main+0xf0>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x20,%edx
call   1040 <write@plt>
lea    0x30(%rsp),%r15
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x800,%edx
call   1090 <read@plt>
lea    0xde7(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xdc2(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %r14d,%eax
add    $0x838,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd83(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%r14d
jmp    128f <main+0xdf>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.buf = [32 x i8] c"GET /index.html HTTP/1.1\0A\0A\0A\00\00\00\00\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [14 x i8] c"oops: client1\00"
@.str.2 = [53 x i8] c"---------------------------------------------------\0A\00"
@.str.3 = [22 x i8] c"recv from server:\0A%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca [32 x i8]
%11 = alloca [2048 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = bitcast [32 x i8]* %10 to i8*
%13 = bitcast [2048 x i8]* %11 to i8*
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %6
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %17, i32* %18
%19 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 %19, i32* %21
%22 = call i32 @htons(i32 11000)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %22, i32* %23
store i32 12, i32* %7
%24 = load i32, i32* %6
%25 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%26 = load i32, i32* %7
%27 = call i32 @connect(i32 %24, %struct.sockaddr* %25, i32 %26)
store i32 %27, i32* %9
%28 = load i32, i32* %9
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %2
%31 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %45
32: ; preds = %2
%33 = load i32, i32* %6
%34 = getelementptr inbounds [32 x i8], [32 x i8]* %10, i64 0, i64 0
%35 = call i32 @write(i32 %33, i8* %34, i32 32)
%36 = load i32, i32* %6
%37 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%38 = call i32 @read(i32 %36, i8* %37, i32 2048)
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %11, i64 0, i64 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
store i32 0, i32* %3
br label %45
45: ; preds = %32, %30
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.buf = [32 x i8] c"GET /index.html HTTP/1.1\0A\0A\0A\00\00\00\00\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [14 x i8] c"oops: client1\00"
@.str.3 = [22 x i8] c"recv from server:\0A%s\0A\00"
@str.4 = [52 x i8] c"---------------------------------------------------\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [32 x i8]
%5 = alloca [2048 x i8]
%6 = bitcast %struct.sockaddr_in* %3 to i8*
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = tail call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %12, i32* %13
%14 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %14, i32* %15
%16 = tail call i32 @htons(i32 11000)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %16, i32* %17
%18 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%19 = call i32 @connect(i32 %11, %struct.sockaddr* %18, i32 12)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %30
23: ; preds = %2
%24 = call i32 @write(i32 %11, i8* %7, i32 32)
%25 = call i32 @read(i32 %11, i8* %8, i32 2048)
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.4, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.4, i64 0, i64 0))
%29 = call i32 @close(i32 %11)
br label %30
30: ; preds = %23, %21
%31 = phi i32 [ 1, %21 ], [ 0, %23 ]
ret i32 %31
}