#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 size_t ssize_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *);
size_t read(int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, char *,
                            char *);
char *strlen(char *);
int /*<<< orphan*/ write(int, char *, char *);
ssize_t process_http(int sockfd, char *host, char *page, char *poststr) {
  char sendline[4096 + 1], recvline[4096 + 1];
  ssize_t n;
  printf("Longitud %lu\n", strlen(poststr));
  snprintf(sendline, 300,
           "POST %s HTTP/1.1\r\n"
           "Host: %s\r\n"
           "Connection: Close"
           "Content-type: application/x-www-form-urlencoded\r\n"
           "Content-length: %lu\r\n\r\n"
           "%s",
           page, host, strlen(poststr), poststr);
  write(sockfd, sendline, strlen(sendline));
  while ((n = read(sockfd, recvline, 4096)) > 0) {
    recvline[n] = '\0';
    printf("%s", recvline);
  }
  return n;
}


x86 assembly (clang, -O0):
<process_http>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2080,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rsi
lea    0xe83(%rip),%rdi
call   1050 <printf@plt>
lea    -0x1030(%rbp),%rax
mov    %rax,-0x2070(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x2068(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x2060(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2070(%rbp),%rdi
mov    -0x2068(%rbp),%rcx
mov    -0x2060(%rbp),%r8
mov    %rax,%r9
mov    -0x20(%rbp),%rax
mov    $0x12c,%esi
lea    0xe37(%rip),%rdx
mov    %rax,(%rsp)
call   1060 <snprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x2054(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x2050(%rbp)
lea    -0x1030(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2054(%rbp),%edi
mov    -0x2050(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
lea    -0x2040(%rbp),%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
mov    %rax,-0x2048(%rbp)
cmp    $0x0,%rax
jbe    1264 <process_http+0x114>
mov    -0x2048(%rbp),%rax
movb   $0x0,-0x2040(%rbp,%rax,1)
lea    -0x2040(%rbp),%rsi
lea    0xe29(%rip),%rdi
call   1050 <printf@plt>
jmp    1218 <process_http+0xc8>
mov    -0x2048(%rbp),%rax
add    $0x2080,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_http>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x2028,%rsp
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
mov    %rcx,%rdi
call   1040 <strlen@plt>
lea    0xe89(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rbx,(%rsp)
lea    0xe7c(%rip),%rdx
lea    0x1020(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x12c,%esi
mov    %r14,%rcx
mov    %r15,%r8
mov    %rax,%r9
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1000,%edx
call   1070 <read@plt>
test   %rax,%rax
je     1214 <process_http+0xc4>
lea    0xea1(%rip),%r14
lea    0x10(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1000,%edx
call   1070 <read@plt>
test   %rax,%rax
jne    11f0 <process_http+0xa0>
xor    %eax,%eax
add    $0x2028,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Longitud %lu\0A\00"
@.str.1 = [120 x i8] c"POST %s HTTP/1.1\0D\0AHost: %s\0D\0AConnection: CloseContent-type: application/x-www-form-urlencoded\0D\0AContent-length: %lu\0D\0A\0D\0A%s\00"
@.str.2 = [3 x i8] c"%s\00"
define i64 @process_http(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [4097 x i8]
%10 = alloca [4097 x i8]
%11 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%12 = load i8*, i8** %8
%13 = call i8* @strlen(i8* %12)
%14 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%16 = load i8*, i8** %7
%17 = load i8*, i8** %6
%18 = load i8*, i8** %8
%19 = call i8* @strlen(i8* %18)
%20 = load i8*, i8** %8
%21 = call i32 @snprintf(i8* %15, i32 300, i8* getelementptr inbounds ([120 x i8], [120 x i8]* @.str.1, i64 0, i64 0), i8* %16, i8* %17, i8* %19, i8* %20)
%22 = load i32, i32* %5
%23 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%24 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%25 = call i8* @strlen(i8* %24)
%26 = call i32 @write(i32 %22, i8* %23, i8* %25)
br label %27
27: ; preds = %32, %4
%28 = load i32, i32* %5
%29 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%30 = call i64 @read(i32 %28, i8* %29, i32 4096)
store i64 %30, i64* %11
%31 = icmp ugt i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = load i64, i64* %11
%34 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 %33
store i8 0, i8* %34
%35 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%36 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %35)
br label %27
37: ; preds = %27
%38 = load i64, i64* %11
ret i64 %38
}

LLVM IR (-O2):
@.str = [14 x i8] c"Longitud %lu\0A\00"
@.str.1 = [120 x i8] c"POST %s HTTP/1.1\0D\0AHost: %s\0D\0AConnection: CloseContent-type: application/x-www-form-urlencoded\0D\0AContent-length: %lu\0D\0A\0D\0A%s\00"
@.str.2 = [3 x i8] c"%s\00"
define i64 @process_http(i32 %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [4097 x i8]
%6 = alloca [4097 x i8]
%7 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 0
%9 = tail call i8* @strlen(i8* %3)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i8* @strlen(i8* %3)
%12 = call i32 @snprintf(i8* %7, i32 300, i8* getelementptr inbounds ([120 x i8], [120 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %1, i8* %11, i8* %3)
%13 = call i8* @strlen(i8* %7)
%14 = call i32 @write(i32 %0, i8* %7, i8* %13)
%15 = call i64 @read(i32 %0, i8* %8, i32 4096)
%16 = icmp eq i64 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %4, %17
%18 = phi i64 [ %21, %17 ], [ %15, %4 ]
%19 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%21 = call i64 @read(i32 %0, i8* %8, i32 4096)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %17
23: ; preds = %17, %4
ret i64 0
}