#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int O_RDWR;
int STDOUT_FILENO;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ close(int);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ remove(char *);
int strlen(char const *);
int write(int, char const *, int);
int main(int argc, char **argv) {
  int fd, size;
  char buffer[65535] = {0};
  static char const *request = "GET /index.html HTTP/1.1\r\n"
                               "Host: www.google.co.jp\r\n"
                               "Connection: close\r\n\r\n";
  fd = open("/net/tcp/74.125.235.240!80", O_CREAT | O_RDWR, S_IRWXU);
  if (fd < 0) {
    perror("open");
    return EXIT_FAILURE;
  }
  size = write(fd, request, strlen(request));
  if (size < 0) {
    perror("write");
    return EXIT_FAILURE;
  }
  do {
    size = read(fd, buffer, sizeof(buffer));
    if (size < 0) {
      perror("read");
      break;
    }
    write(STDOUT_FILENO, buffer, size);
  } while (size != 0);
  close(fd);
  remove("/net/tcp/74.125.235.240!80");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x10020(%rbp),%rdi
xor    %esi,%esi
mov    $0xffff,%edx
call   1060 <memset@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
mov    0x2e14(%rip),%rax
or     (%rax),%esi
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
lea    0xe7a(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11fd <main+0x7d>
lea    0xe7c(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d7 <main+0x157>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1002c(%rbp)
mov    0x2e53(%rip),%rax
mov    %rax,-0x10028(%rbp)
mov    0x2e45(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x1002c(%rbp),%edi
mov    -0x10028(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    125e <main+0xde>
lea    0xe20(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d7 <main+0x157>
jmp    1263 <main+0xe3>
mov    -0x14(%rbp),%edi
lea    -0x10020(%rbp),%rsi
mov    $0xffff,%edx
call   1080 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1295 <main+0x115>
lea    0xde3(%rip),%rdi
call   10a0 <perror@plt>
jmp    12b7 <main+0x137>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    -0x10020(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <write@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1263 <main+0xe3>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
lea    0xd82(%rip),%rdi
call   1030 <remove@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x10008,%rsp
mov    %rsp,%rdi
mov    $0xffff,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    0x2e55(%rip),%rax
mov    0x2e26(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
lea    0xe8a(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1252 <main+0xd2>
mov    %eax,%r14d
lea    0xe2b(%rip),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %eax,%eax
js     125b <main+0xdb>
mov    %rsp,%rbx
mov    0x2df0(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0xffff,%edx
call   1080 <read@plt>
test   %eax,%eax
js     1270 <main+0xf0>
mov    %eax,%ebp
mov    (%r15),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
test   %ebp,%ebp
jne    1200 <main+0x80>
mov    %r14d,%edi
call   1070 <close@plt>
lea    0xe12(%rip),%rdi
call   1030 <remove@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%eax
add    $0x10008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0a(%rip),%rdi
jmp    1262 <main+0xe2>
lea    0xe06(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d52(%rip),%rax
jmp    1242 <main+0xc2>
lea    0xdf7(%rip),%rdi
call   10a0 <perror@plt>
jmp    1227 <main+0xa7>

LLVM IR (-O0):
@main.request = internal global i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i32 0, i32 0)
@.str = [72 x i8] c"GET /index.html HTTP/1.1\0D\0AHost: www.google.co.jp\0D\0AConnection: close\0D\0A\0D\0A\00"
@.str.1 = [27 x i8] c"/net/tcp/74.125.235.240!80\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRWXU = global i32 0
@.str.2 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [5 x i8] c"read\00"
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [65535 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [65535 x i8]* %8 to i8*
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_RDWR
%12 = or i32 %10, %11
%13 = load i32, i32* @S_IRWXU
%14 = call i32 @open(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %3
br label %53
20: ; preds = %2
%21 = load i32, i32* %6
%22 = load i8*, i8** @main.request
%23 = load i8*, i8** @main.request
%24 = call i32 @strlen(i8* %23)
%25 = call i32 @write(i32 %21, i8* %22, i32 %24)
store i32 %25, i32* %7
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %20
%29 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
store i32 %30, i32* %3
br label %53
31: ; preds = %20
br label %32
32: ; preds = %45, %31
%33 = load i32, i32* %6
%34 = getelementptr inbounds [65535 x i8], [65535 x i8]* %8, i64 0, i64 0
%35 = call i32 @read(i32 %33, i8* %34, i32 65535)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %32
%39 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %48
40: ; preds = %32
%41 = load i32, i32* @STDOUT_FILENO
%42 = getelementptr inbounds [65535 x i8], [65535 x i8]* %8, i64 0, i64 0
%43 = load i32, i32* %7
%44 = call i32 @write(i32 %41, i8* %42, i32 %43)
br label %45
45: ; preds = %40
%46 = load i32, i32* %7
%47 = icmp ne i32 %46, 0
br i1 %47, label %32, label %48
48: ; preds = %45, %38
%49 = load i32, i32* %6
%50 = call i32 @close(i32 %49)
%51 = call i32 @remove(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%52 = load i32, i32* @EXIT_SUCCESS
store i32 %52, i32* %3
br label %53
53: ; preds = %48, %28, %17
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
@.str = [72 x i8] c"GET /index.html HTTP/1.1\0D\0AHost: www.google.co.jp\0D\0AConnection: close\0D\0A\0D\0A\00"
@.str.1 = [27 x i8] c"/net/tcp/74.125.235.240!80\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@S_IRWXU = global i32 0
@.str.2 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [6 x i8] c"write\00"
@.str.4 = [5 x i8] c"read\00"
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [65535 x i8]
%4 = getelementptr inbounds [65535 x i8], [65535 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @O_CREAT
%6 = load i32, i32* @O_RDWR
%7 = or i32 %6, %5
%8 = load i32, i32* @S_IRWXU
%9 = tail call i32 @open(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %31
13: ; preds = %2
%14 = tail call i32 @strlen(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @write(i32 %9, i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %31
19: ; preds = %13, %24
%20 = call i32 @read(i32 %9, i8* %4, i32 65535)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %28
24: ; preds = %19
%25 = load i32, i32* @STDOUT_FILENO
%26 = call i32 @write(i32 %25, i8* %4, i32 %20)
%27 = icmp eq i32 %20, 0
br i1 %27, label %28, label %19
28: ; preds = %24, %22
%29 = tail call i32 @close(i32 %9)
%30 = tail call i32 @remove(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %28, %17, %11
%32 = phi i32* [ @EXIT_FAILURE, %11 ], [ @EXIT_FAILURE, %17 ], [ @EXIT_SUCCESS, %28 ]
%33 = load i32, i32* %32
ret i32 %33
}