#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 */

/* Variables and functions */
int asprintf(char **, char const *, char const *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fail(int, char *, ...);
int /*<<< orphan*/ free(char *);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/,
             int /*<<< orphan*/);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
char *perform_http_get(int socket_ref, const char *host, const char *page) {
  char *request_message = NULL;
  const char *request_format =
      "GET /%s HTTP/1.0\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Macintosh; "
      "Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) "
      "Chrome/32.0.1700.77 Safari/537.36\r\n\r\n";
  int status;
  status = asprintf(&request_message, request_format, page, host);
  fail(status == -1 || !request_message, "asprintf failed.\n");
  status = send(socket_ref, request_message, strlen(request_message), 0);
  fail(status == -1, "send failed: %s\n", strerror(errno));
  char *page_content = NULL;
  int content_length = -1;
  while (1) {
    int numero_de_bytes_recibidos;
    char buffer_de_datos_recibidos[0x1000 + 10];
    numero_de_bytes_recibidos =
        recvfrom(socket_ref, buffer_de_datos_recibidos, 0x1000, 0, 0, 0);
    if (numero_de_bytes_recibidos == 0) {
      break;
    }
    fail(numero_de_bytes_recibidos == -1, "%s\n", strerror(errno));
    buffer_de_datos_recibidos[numero_de_bytes_recibidos] = '\0';
    if (page_content == NULL) {
      asprintf(&page_content, "%s", buffer_de_datos_recibidos);
    } else {
      asprintf(&page_content, "%s%s", page_content, buffer_de_datos_recibidos);
    }
  }
  free(request_message);
  return page_content;
}


x86 assembly (clang, -O0):
<perform_http_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe6b(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1080 <asprintf@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x1,%al
cmpl   $0xffffffff,-0x2c(%rbp)
mov    %al,-0x1051(%rbp)
je     11d5 <perform_http_get+0x65>
cmpq   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
mov    %al,-0x1051(%rbp)
mov    -0x1051(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
lea    0xebd(%rip),%rsi
mov    $0x0,%al
call   1040 <fail@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1064(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x1060(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1064(%rbp),%edi
mov    -0x1060(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1058(%rbp)
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1058(%rbp),%edi
mov    %eax,%edx
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1040 <fail@plt>
movq   $0x0,-0x38(%rbp)
movl   $0xffffffff,-0x3c(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x1050(%rbp),%rsi
mov    $0x1000,%edx
xor    %r9d,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
call   1070 <recvfrom@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jne    1298 <perform_http_get+0x128>
jmp    1325 <perform_http_get+0x1b5>
cmpl   $0xffffffff,-0x40(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1068(%rbp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x1068(%rbp),%edi
mov    %eax,%edx
lea    0xdfc(%rip),%rsi
mov    $0x0,%al
call   1040 <fail@plt>
movslq -0x40(%rbp),%rax
movb   $0x0,-0x1050(%rbp,%rax,1)
cmpq   $0x0,-0x38(%rbp)
jne    1303 <perform_http_get+0x193>
lea    -0x1050(%rbp),%rdx
lea    -0x38(%rbp),%rdi
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1080 <asprintf@plt>
jmp    1320 <perform_http_get+0x1b0>
mov    -0x38(%rbp),%rdx
lea    -0x1050(%rbp),%rcx
lea    -0x38(%rbp),%rdi
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1080 <asprintf@plt>
jmp    1269 <perform_http_get+0xf9>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rax
add    $0x1070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<perform_http_get>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1028,%rsp
mov    %rsi,%rcx
mov    %edi,%ebp
movq   $0x0,(%rsp)
lea    0xe6b(%rip),%rsi
mov    %rsp,%rdi
xor    %eax,%eax
call   1080 <asprintf@plt>
cmp    $0xffffffff,%eax
sete   %al
cmpq   $0x0,(%rsp)
sete   %cl
or     %al,%cl
movzbl %cl,%edi
lea    0xeeb(%rip),%rsi
xor    %eax,%eax
call   1040 <fail@plt>
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
sete   %bl
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xebf(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fail@plt>
movq   $0x0,0x8(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1000,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1070 <recvfrom@plt>
test   %eax,%eax
je     12cf <perform_http_get+0x15f>
mov    %eax,%r15d
lea    0xe8d(%rip),%r14
lea    0x8(%rsp),%r12
lea    0x10(%rsp),%rbx
jmp    127f <perform_http_get+0x10f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe70(%rip),%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1080 <asprintf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   1070 <recvfrom@plt>
mov    %eax,%r15d
test   %eax,%eax
je     12cf <perform_http_get+0x15f>
xor    %r13d,%r13d
cmp    $0xffffffff,%r15d
sete   %r13b
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <fail@plt>
movslq %r15d,%rax
movb   $0x0,0x10(%rsp,%rax,1)
mov    0x8(%rsp),%rdx
mov    %r12,%rdi
test   %rdx,%rdx
jne    1250 <perform_http_get+0xe0>
lea    0xe06(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <asprintf@plt>
jmp    1261 <perform_http_get+0xf1>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rax
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [164 x i8] c"GET /%s HTTP/1.0\0D\0AHost: %s\0D\0AUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36\0D\0A\0D\0A\00"
@.str.1 = [18 x i8] c"asprintf failed.\0A\00"
@.str.2 = [17 x i8] c"send failed: %s\0A\00"
@errno = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [5 x i8] c"%s%s\00"
define i8* @perform_http_get(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca [4106 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i8* null, i8** %7
store i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str, i64 0, i64 0), i8** %8
%14 = load i8*, i8** %8
%15 = load i8*, i8** %6
%16 = load i8*, i8** %5
%17 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %7, i8* %14, i8* %15, i8* %16)
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = icmp eq i32 %18, -1
br i1 %19, label %24, label %20
20: ; preds = %3
%21 = load i8*, i8** %7
%22 = icmp ne i8* %21, null
%23 = xor i1 %22, true
br label %24
24: ; preds = %20, %3
%25 = phi i1 [ true, %3 ], [ %23, %20 ]
%26 = zext i1 %25 to i32
%27 = call i32 (i32, i8*, ...) @fail(i32 %26, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* %4
%29 = load i8*, i8** %7
%30 = load i8*, i8** %7
%31 = call i32 @strlen(i8* %30)
%32 = call i32 @send(i32 %28, i8* %29, i32 %31, i32 0)
store i32 %32, i32* %9
%33 = load i32, i32* %9
%34 = icmp eq i32 %33, -1
%35 = zext i1 %34 to i32
%36 = load i32, i32* @errno
%37 = call i32 @strerror(i32 %36)
%38 = call i32 (i32, i8*, ...) @fail(i32 %35, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %37)
store i8* null, i8** %10
store i32 -1, i32* %11
br label %39
39: ; preds = %24, %65
%40 = load i32, i32* %4
%41 = getelementptr inbounds [4106 x i8], [4106 x i8]* %13, i64 0, i64 0
%42 = call i32 @recvfrom(i32 %40, i8* %41, i32 4096, i32 0, i32 0, i32 0)
store i32 %42, i32* %12
%43 = load i32, i32* %12
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %39
br label %66
46: ; preds = %39
%47 = load i32, i32* %12
%48 = icmp eq i32 %47, -1
%49 = zext i1 %48 to i32
%50 = load i32, i32* @errno
%51 = call i32 @strerror(i32 %50)
%52 = call i32 (i32, i8*, ...) @fail(i32 %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %51)
%53 = load i32, i32* %12
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [4106 x i8], [4106 x i8]* %13, i64 0, i64 %54
store i8 0, i8* %55
%56 = load i8*, i8** %10
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %61
58: ; preds = %46
%59 = getelementptr inbounds [4106 x i8], [4106 x i8]* %13, i64 0, i64 0
%60 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %59)
br label %65
61: ; preds = %46
%62 = load i8*, i8** %10
%63 = getelementptr inbounds [4106 x i8], [4106 x i8]* %13, i64 0, i64 0
%64 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %62, i8* %63)
br label %65
65: ; preds = %61, %58
br label %39
66: ; preds = %45
%67 = load i8*, i8** %7
%68 = call i32 @free(i8* %67)
%69 = load i8*, i8** %10
ret i8* %69
}

LLVM IR (-O2):
@.str = [164 x i8] c"GET /%s HTTP/1.0\0D\0AHost: %s\0D\0AUser-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.77 Safari/537.36\0D\0A\0D\0A\00"
@.str.1 = [18 x i8] c"asprintf failed.\0A\00"
@.str.2 = [17 x i8] c"send failed: %s\0A\00"
@errno = global i32 0
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [5 x i8] c"%s%s\00"
define i8* @perform_http_get(i32 %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [4106 x i8]
%7 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%8 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %4, i8* getelementptr inbounds ([164 x i8], [164 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %1)
%9 = icmp eq i32 %8, -1
%10 = load i8*, i8** %4
%11 = icmp eq i8* %10, null
%12 = select i1 %9, i1 true, i1 %11
%13 = zext i1 %12 to i32
%14 = call i32 (i32, i8*, ...) @fail(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%15 = load i8*, i8** %4
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @send(i32 %0, i8* %15, i32 %16, i32 0)
%18 = icmp eq i32 %17, -1
%19 = zext i1 %18 to i32
%20 = load i32, i32* @errno
%21 = call i32 @strerror(i32 %20)
%22 = call i32 (i32, i8*, ...) @fail(i32 %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%24 = getelementptr inbounds [4106 x i8], [4106 x i8]* %6, i64 0, i64 0
%25 = call i32 @recvfrom(i32 %0, i8* %24, i32 4096, i32 0, i32 0, i32 0)
%26 = icmp eq i32 %25, 0
br i1 %26, label %45, label %27
27: ; preds = %3, %42
%28 = phi i32 [ %43, %42 ], [ %25, %3 ]
%29 = icmp eq i32 %28, -1
%30 = zext i1 %29 to i32
%31 = load i32, i32* @errno
%32 = call i32 @strerror(i32 %31)
%33 = call i32 (i32, i8*, ...) @fail(i32 %30, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = sext i32 %28 to i64
%35 = getelementptr inbounds [4106 x i8], [4106 x i8]* %6, i64 0, i64 %34
store i8 0, i8* %35
%36 = load i8*, i8** %5
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %27
%39 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %24)
br label %42
40: ; preds = %27
%41 = call i32 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* %36, i8* %24)
br label %42
42: ; preds = %38, %40
%43 = call i32 @recvfrom(i32 %0, i8* %24, i32 4096, i32 0, i32 0, i32 0)
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %27
45: ; preds = %42, %3
%46 = load i8*, i8** %4
%47 = call i32 @free(i8* %46)
%48 = load i8*, i8** %5
ret i8* %48
}