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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int main(void) {
  int sockfd;
  struct sockaddr_in dest;
  char buffer[1024];
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("Socket creation failed");
    exit(errno);
  }
  dest.sin_family = AF_INET;
  dest.sin_port = htons(80);
  if (inet_aton("10.1.1.242", &dest.sin_addr.s_addr) == 0) {
    perror("10.1.1.242");
    exit(errno);
  }
  if (connect(sockfd, (struct sockaddr *)&dest, sizeof(dest)) != 0) {
    perror("Connect");
    exit(errno);
  }
  strcpy(buffer, "GET / HTTP/1.0\n\n");
  send(sockfd, buffer, sizeof(buffer), 0);
  bzero(buffer, sizeof(buffer));
  recv(sockfd, buffer, sizeof(buffer), 0);
  printf("Data received %s\n", buffer);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1211 <main+0x51>
lea    0xe02(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x50,%edi
call   1050 <htons@plt>
mov    %eax,-0x14(%rbp)
lea    -0x18(%rbp),%rsi
lea    0xde2(%rip),%rdi
call   1090 <inet_aton@plt>
cmp    $0x0,%rax
jne    125e <main+0x9e>
lea    0xdcc(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0x0,%rax
je     1293 <main+0xd3>
lea    0xda2(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
lea    -0x420(%rbp),%rdi
lea    0xd89(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   10b0 <bzero@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x420(%rbp),%rsi
lea    0xd4a(%rip),%rdi
call   1070 <printf@plt>
mov    -0x8(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x418,%rsp
mov    0x2e17(%rip),%r14
mov    (%r14),%edi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
test   %eax,%eax
js     1295 <main+0xd5>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    $0x50,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xe0d(%rip),%rdi
mov    %rsp,%rsi
call   1090 <inet_aton@plt>
test   %rax,%rax
je     129e <main+0xde>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10d0 <connect@plt>
test   %rax,%rax
jne    12a7 <main+0xe7>
lea    0xdf4(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1040 <strcpy@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %r14,%rdi
mov    $0x400,%esi
call   10b0 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    0xdc2(%rip),%rdi
mov    %r14,%rsi
call   1070 <printf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd64(%rip),%rdi
jmp    12ae <main+0xee>
lea    0xd72(%rip),%rdi
jmp    12ae <main+0xee>
lea    0xd74(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

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 = [23 x i8] c"Socket creation failed\00"
@errno = global i32 0
@.str.1 = [11 x i8] c"10.1.1.242\00"
@.str.2 = [8 x i8] c"Connect\00"
@.str.3 = [17 x i8] c"GET / HTTP/1.0\0A\0A\00"
@.str.4 = [18 x i8] c"Data received %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %2
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @errno
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 @htons(i32 80)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%19 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %18, i32 0, i32 0
%20 = call i64 @inet_aton(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %13
%23 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @errno
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %13
%27 = load i32, i32* %2
%28 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%29 = call i64 @connect(i32 %27, %struct.sockaddr* %28, i32 12)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %26
%32 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @errno
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %26
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%37 = call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* %2
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%40 = call i32 @send(i32 %38, i8* %39, i32 1024, i32 0)
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%42 = call i32 @bzero(i8* %41, i32 1024)
%43 = load i32, i32* %2
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%45 = call i32 @recv(i32 %43, i8* %44, i32 1024, i32 0)
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%47 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %46)
%48 = load i32, i32* %2
%49 = call i32 @close(i32 %48)
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 = [23 x i8] c"Socket creation failed\00"
@errno = global i32 0
@.str.1 = [11 x i8] c"10.1.1.242\00"
@.str.2 = [8 x i8] c"Connect\00"
@.str.3 = [17 x i8] c"GET / HTTP/1.0\0A\0A\00"
@.str.4 = [18 x i8] c"Data received %s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [1024 x i8]
%3 = bitcast %struct.sockaddr_in* %1 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @errno
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %14, i32* %15
%16 = tail call i32 @htons(i32 80)
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
%19 = call i64 @inet_aton(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @errno
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %13
%26 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%27 = call i64 @connect(i32 %7, %struct.sockaddr* %26, i32 12)
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %25
%30 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @errno
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %25
%34 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 @send(i32 %7, i8* %4, i32 1024, i32 0)
%36 = call i32 @bzero(i8* %4, i32 1024)
%37 = call i32 @recv(i32 %7, i8* %4, i32 1024, i32 0)
%38 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%39 = call i32 @close(i32 %7)
ret i32 0
}