#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 /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int strlen(char const *);
int write(int, char *, int);
int httpWrite(int fd, const char *body, int bodysize, const char *headers) {
  int n = 0;
  int i;
  char *p;
  i = strlen(headers);
  p = malloc(i + bodysize);
  memcpy(p, headers, i);
  memcpy(p + i, body, bodysize);
  n = write(fd, p, i + bodysize);
  free(p);
  return n;
}


x86 assembly (clang, -O0):
<httpWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%edi
add    -0x14(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x30(%rbp),%rdi
movslq -0x28(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
add    -0x14(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x24(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<httpWrite>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%rbx
mov    %edx,%r14d
mov    %rsi,%r15
mov    %edi,0x4(%rsp)
mov    %rcx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    (%r14,%rbp,1),%r13d
mov    %r13d,%edi
call   1070 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1060 <memcpy@plt>
movslq %ebp,%rdi
add    %r12,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1060 <memcpy@plt>
mov    0x4(%rsp),%edi
mov    %r12,%rsi
mov    %r13d,%edx
call   1040 <write@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @httpWrite(i32 %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i32 0, i32* %9
%12 = load i8*, i8** %8
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %10
%14 = load i32, i32* %10
%15 = load i32, i32* %7
%16 = add nsw i32 %14, %15
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %11
%18 = load i8*, i8** %11
%19 = load i8*, i8** %8
%20 = load i32, i32* %10
%21 = call i32 @memcpy(i8* %18, i8* %19, i32 %20)
%22 = load i8*, i8** %11
%23 = load i32, i32* %10
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8*, i8** %6
%27 = load i32, i32* %7
%28 = call i32 @memcpy(i8* %25, i8* %26, i32 %27)
%29 = load i32, i32* %5
%30 = load i8*, i8** %11
%31 = load i32, i32* %10
%32 = load i32, i32* %7
%33 = add nsw i32 %31, %32
%34 = call i32 @write(i32 %29, i8* %30, i32 %33)
store i32 %34, i32* %9
%35 = load i8*, i8** %11
%36 = call i32 @free(i8* %35)
%37 = load i32, i32* %9
ret i32 %37
}

LLVM IR (-O2):
define i32 @httpWrite(i32 %0, i8* %1, i32 %2, i8* %3) {
%5 = tail call i32 @strlen(i8* %3)
%6 = add nsw i32 %5, %2
%7 = tail call i8* @malloc(i32 %6)
%8 = tail call i32 @memcpy(i8* %7, i8* %3, i32 %5)
%9 = sext i32 %5 to i64
%10 = getelementptr inbounds i8, i8* %7, i64 %9
%11 = tail call i32 @memcpy(i8* %10, i8* %1, i32 %2)
%12 = tail call i32 @write(i32 %0, i8* %7, i32 %6)
%13 = tail call i32 @free(i8* %7)
ret i32 %12
}