#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 */
struct sockaddr_storage {
  int dummy;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ addrfrom;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
scalar_t__ recvfrom(int, char **, int, int /*<<< orphan*/, struct sockaddr *,
                    int *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int main(void) {
  int sock;
  if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    fprintf(stderr, "socket() failed: %s\n.", strerror(errno));
    return (EXIT_FAILURE);
  }
  struct sockaddr_in addr;
  addr.sin_family = AF_INET;
  addr.sin_port = htons(8000);
  inet_aton("127.0.0.1", &addr.sin_addr);
  if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    fprintf(stderr, "connect() failed: %s\n.", strerror(errno));
    return (EXIT_FAILURE);
  }
  char *req = "GET / HTTP/1.0\r\n\r\n";
  send(sock, req, sizeof(char) * strlen(req), 0);
  char buf[42];
  struct sockaddr_storage addrfrom;
  socklen_t fromlen = sizeof(addrfrom);
  if (recvfrom(sock, &buf, sizeof(buf), 0, (struct sockaddr *)&addrfrom,
               &fromlen) < 0) {
    fprintf(stderr, "recvfrom() failed: %s\n.", strerror(errno));
    return (EXIT_FAILURE);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    120b <main+0x7b>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x60(%rbp),%edi
mov    %rax,%rdx
lea    0xe0b(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2db7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1339 <main+0x1a9>
mov    0x2dd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1f40,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rsi
lea    0xde7(%rip),%rdi
call   1070 <inet_aton@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
cmp    $0x0,%rax
jge    128c <main+0xfc>
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xdaa(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1339 <main+0x1a9>
lea    0xda4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rsi
cltq
shl    $0x0,%rax
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
movl   $0x4,-0x5c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
lea    -0x58(%rbp),%r8
mov    $0x2a,%edx
xor    %ecx,%ecx
lea    -0x5c(%rbp),%r9
call   1080 <recvfrom@plt>
cmp    $0x0,%rax
jge    132d <main+0x19d>
mov    0x2cd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x78(%rbp),%edi
mov    %rax,%rdx
lea    0xd33(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2c95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1339 <main+0x1a9>
mov    0x2c7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
mov    0x2e4a(%rip),%r14
mov    (%r14),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     124f <main+0xbf>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    $0x1f40,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xe38(%rip),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
call   1070 <inet_aton@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1090 <connect@plt>
test   %rax,%rax
js     126f <main+0xdf>
lea    0xe31(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
movl   $0x4,0x4(%rsp)
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%r8
lea    0x4(%rsp),%r9
mov    %ebx,%edi
mov    $0x2a,%edx
xor    %ecx,%ecx
call   1080 <recvfrom@plt>
test   %rax,%rax
js     128f <main+0xff>
mov    0x2d63(%rip),%rax
jmp    12be <main+0x12e>
mov    0x2d7a(%rip),%rax
mov    (%rax),%ebx
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd93(%rip),%rsi
jmp    12ad <main+0x11d>
mov    0x2d5a(%rip),%rax
mov    (%rax),%ebx
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd93(%rip),%rsi
jmp    12ad <main+0x11d>
mov    0x2d3a(%rip),%rax
mov    (%rax),%ebx
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd9d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2cfa(%rip),%rax
mov    (%rax),%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"socket() failed: %s\0A.\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [23 x i8] c"connect() failed: %s\0A.\00"
@.str.3 = [19 x i8] c"GET / HTTP/1.0\0D\0A\0D\0A\00"
@.str.4 = [24 x i8] c"recvfrom() failed: %s\0A.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i8*
%5 = alloca [42 x i8]
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
store i32 0, i32* %1
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = load i32, i32* @IPPROTO_TCP
%11 = call i32 @socket(i32 %8, i32 %9, i32 %10)
store i32 %11, i32* %2
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %0
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
store i32 %18, i32* %1
br label %58
19: ; preds = %0
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @htons(i32 8000)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%25 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %24)
%26 = load i32, i32* %2
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i64 @connect(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %36
30: ; preds = %19
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = call i8* @strerror(i32 %32)
%34 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_FAILURE
store i32 %35, i32* %1
br label %58
36: ; preds = %19
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8** %4
%37 = load i32, i32* %2
%38 = load i8*, i8** %4
%39 = load i8*, i8** %4
%40 = call i32 @strlen(i8* %39)
%41 = sext i32 %40 to i64
%42 = mul i64 1, %41
%43 = trunc i64 %42 to i32
%44 = call i32 @send(i32 %37, i8* %38, i32 %43, i32 0)
store i32 4, i32* %7
%45 = load i32, i32* %2
%46 = bitcast [42 x i8]* %5 to i8**
%47 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
%48 = call i64 @recvfrom(i32 %45, i8** %46, i32 42, i32 0, %struct.sockaddr* %47, i32* %7)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %36
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %53)
%55 = load i32, i32* @EXIT_FAILURE
store i32 %55, i32* %1
br label %58
56: ; preds = %36
%57 = load i32, i32* @EXIT_SUCCESS
store i32 %57, i32* %1
br label %58
58: ; preds = %56, %50, %30, %13
%59 = load i32, i32* %1
ret i32 %59
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@stderr = global i32 0
@.str = [22 x i8] c"socket() failed: %s\0A.\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [23 x i8] c"connect() failed: %s\0A.\00"
@.str.3 = [19 x i8] c"GET / HTTP/1.0\0D\0A\0D\0A\00"
@.str.4 = [24 x i8] c"recvfrom() failed: %s\0A.\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [42 x i8]
%3 = alloca %struct.sockaddr_storage
%4 = alloca i32
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = load i32, i32* @IPPROTO_TCP
%8 = tail call i32 @socket(i32 %5, i32 %6, i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
br label %53
16: ; preds = %0
%17 = bitcast %struct.sockaddr_in* %1 to i8*
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %18, i32* %19
%20 = tail call i32 @htons(i32 8000)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%23 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32* %22)
%24 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%25 = call i64 @connect(i32 %8, %struct.sockaddr* %24, i32 12)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %33
27: ; preds = %16
%28 = load i32, i32* @stderr
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @EXIT_FAILURE
br label %51
33: ; preds = %16
%34 = call i32 @strlen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @send(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %34, i32 0)
%36 = getelementptr inbounds [42 x i8], [42 x i8]* %2, i64 0, i64 0
%37 = bitcast %struct.sockaddr_storage* %3 to i8*
%38 = bitcast i32* %4 to i8*
store i32 4, i32* %4
%39 = bitcast [42 x i8]* %2 to i8**
%40 = bitcast %struct.sockaddr_storage* %3 to %struct.sockaddr*
%41 = call i64 @recvfrom(i32 %8, i8** %39, i32 42, i32 0, %struct.sockaddr* %40, i32* %4)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %33
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* %46)
br label %48
48: ; preds = %33, %43
%49 = phi i32* [ @EXIT_FAILURE, %43 ], [ @EXIT_SUCCESS, %33 ]
%50 = load i32, i32* %49
br label %51
51: ; preds = %48, %27
%52 = phi i32 [ %32, %27 ], [ %50, %48 ]
br label %53
53: ; preds = %51, %10
%54 = phi i32 [ %15, %10 ], [ %52, %51 ]
ret i32 %54
}