#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 /*<<< orphan*/ server;
typedef int /*<<< orphan*/ get_msg;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int 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 fd;
  struct sockaddr_in server;
  fd = socket(AF_INET, SOCK_STREAM, 0);
  server.sin_family = AF_INET;
  server.sin_addr.s_addr = inet_addr("157.82.13.119");
  server.sin_port = htons(80);
  if (connect(fd, (struct sockaddr *)&server, sizeof(server)) < 0) {
    perror("connecting stream socket");
    exit(1);
  }
  char get_msg[] = "GET /index.html HTTP/1.0\n\n";
  write(fd, get_msg, sizeof(get_msg));
  char buf[256];
  int read_size = 256;
  while (read_size > 0) {
    read_size = read(fd, buf, sizeof(buf));
    write(1, buf, read_size);
  }
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
lea    0xe28(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x50,%edi
call   1040 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <connect@plt>
cmp    $0x0,%rax
jge    121e <main+0x8e>
lea    0xdff(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0xe0b(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xe08(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xe05(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe02(%rip),%ax
mov    %ax,-0x28(%rbp)
mov    0xdfa(%rip),%al
mov    %al,-0x26(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1b,%edx
call   1030 <write@plt>
movl   $0x100,-0x144(%rbp)
cmpl   $0x0,-0x144(%rbp)
jle    12b1 <main+0x121>
mov    -0x14(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %eax,-0x144(%rbp)
lea    -0x140(%rbp),%rsi
mov    -0x144(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    126e <main+0xde>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x130,%rsp
mov    0x2e46(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,%r14d
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
lea    0xe3c(%rip),%rdi
call   1070 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x50,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10a0 <connect@plt>
test   %rax,%rax
js     125b <main+0xcb>
movups 0xe45(%rip),%xmm0
movups %xmm0,0x1b(%rsp)
movaps 0xe2e(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r14d,%edi
mov    $0x1b,%edx
call   1030 <write@plt>
lea    0x30(%rsp),%rbx
xchg   %ax,%ax
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %eax,%ebp
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %ebp,%ebp
jg     1220 <main+0x90>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x130,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdac(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, 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"157.82.13.119\00"
@.str.1 = [25 x i8] c"connecting stream socket\00"
@__const.main.get_msg = [27 x i8] c"GET /index.html HTTP/1.0\0A\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 [27 x i8]
%9 = alloca [256 x i8]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%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* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = call i32 @htons(i32 80)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* %6
%22 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%23 = call i64 @connect(i32 %21, %struct.sockaddr* %22, i32 12)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %2
%26 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %2
%29 = bitcast [27 x i8]* %8 to i8*
%30 = load i32, i32* %6
%31 = getelementptr inbounds [27 x i8], [27 x i8]* %8, i64 0, i64 0
%32 = call i32 @write(i32 %30, i8* %31, i32 27)
store i32 256, i32* %10
br label %33
33: ; preds = %36, %28
%34 = load i32, i32* %10
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %43
36: ; preds = %33
%37 = load i32, i32* %6
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%39 = call i32 @read(i32 %37, i8* %38, i32 256)
store i32 %39, i32* %10
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%41 = load i32, i32* %10
%42 = call i32 @write(i32 1, i8* %40, i32 %41)
br label %33
43: ; preds = %33
%44 = load i32, i32* %6
%45 = call i32 @close(i32 %44)
%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 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [14 x i8] c"157.82.13.119\00"
@.str.1 = [25 x i8] c"connecting stream socket\00"
@__const.main.get_msg = [27 x i8] c"GET /index.html HTTP/1.0\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [27 x i8]
%5 = alloca [256 x i8]
%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 = load i32, i32* @AF_INET
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %10, i32* %11
%12 = tail call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %12, i32* %13
%14 = tail call i32 @htons(i32 80)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %14, i32* %15
%16 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%17 = call i64 @connect(i32 %9, %struct.sockaddr* %16, i32 12)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %2
%23 = getelementptr inbounds [27 x i8], [27 x i8]* %4, i64 0, i64 0
%24 = call i32 @write(i32 %9, i8* %23, i32 27)
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
br label %26
26: ; preds = %22, %26
%27 = call i32 @read(i32 %9, i8* %25, i32 256)
%28 = call i32 @write(i32 1, i8* %25, i32 %27)
%29 = icmp sgt i32 %27, 0
br i1 %29, label %26, label %30
30: ; preds = %26
%31 = call i32 @close(i32 %9)
ret i32 0
}