#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 /*<<< orphan*/ perror(char *);
int send(int, char *, int, int /*<<< orphan*/);
int httpWrite(int fd, const char *body, int bodysize, const char *headers,
              int headerssize) {
  int n = 0;
  char *p;
  p = malloc(headerssize + bodysize);
  if (!p)
    return 0;
  memcpy(p, headers, headerssize);
  memcpy(p + headerssize, body, bodysize);
  n = send(fd, p, headerssize + bodysize, 0);
  if (n < 0) {
    perror("send");
  }
  free(p);
  return n;
}


x86 assembly (clang, -O0):
<httpWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x24(%rbp),%edi
add    -0x14(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1197 <httpWrite+0x47>
movl   $0x0,-0x4(%rbp)
jmp    11fa <httpWrite+0xaa>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
add    -0x14(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    11eb <httpWrite+0x9b>
lea    0xe1a(%rip),%rdi
call   1070 <perror@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%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    %r8d,%ebp
mov    %rcx,%r14
mov    %edx,%r13d
mov    %rsi,%r12
mov    %edi,0x4(%rsp)
lea    0x0(%rbp,%r13,1),%r15d
mov    %r15d,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11bf <httpWrite+0x6f>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1050 <memcpy@plt>
movslq %ebp,%rdi
add    %rbx,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
call   1050 <memcpy@plt>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,%ebp
test   %eax,%eax
js     11d2 <httpWrite+0x82>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11c1 <httpWrite+0x71>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe27(%rip),%rdi
call   1070 <perror@plt>
jmp    11b5 <httpWrite+0x65>

LLVM IR (-O0):
@.str = [5 x i8] c"send\00"
define i32 @httpWrite(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i32 %0, i32* %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
store i32 0, i32* %12
%14 = load i32, i32* %11
%15 = load i32, i32* %9
%16 = add nsw i32 %14, %15
%17 = call i8* @malloc(i32 %16)
store i8* %17, i8** %13
%18 = load i8*, i8** %13
%19 = icmp ne i8* %18, null
br i1 %19, label %21, label %20
20: ; preds = %5
store i32 0, i32* %6
br label %47
21: ; preds = %5
%22 = load i8*, i8** %13
%23 = load i8*, i8** %10
%24 = load i32, i32* %11
%25 = call i32 @memcpy(i8* %22, i8* %23, i32 %24)
%26 = load i8*, i8** %13
%27 = load i32, i32* %11
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8*, i8** %8
%31 = load i32, i32* %9
%32 = call i32 @memcpy(i8* %29, i8* %30, i32 %31)
%33 = load i32, i32* %7
%34 = load i8*, i8** %13
%35 = load i32, i32* %11
%36 = load i32, i32* %9
%37 = add nsw i32 %35, %36
%38 = call i32 @send(i32 %33, i8* %34, i32 %37, i32 0)
store i32 %38, i32* %12
%39 = load i32, i32* %12
%40 = icmp slt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %21
%42 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %41, %21
%44 = load i8*, i8** %13
%45 = call i32 @free(i8* %44)
%46 = load i32, i32* %12
store i32 %46, i32* %6
br label %47
47: ; preds = %43, %20
%48 = load i32, i32* %6
ret i32 %48
}

LLVM IR (-O2):
@.str = [5 x i8] c"send\00"
define i32 @httpWrite(i32 %0, i8* %1, i32 %2, i8* %3, i32 %4) {
%6 = add nsw i32 %4, %2
%7 = tail call i8* @malloc(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %20, label %9
9: ; preds = %5
%10 = tail call i32 @memcpy(i8* %7, i8* %3, i32 %4)
%11 = sext i32 %4 to i64
%12 = getelementptr inbounds i8, i8* %7, i64 %11
%13 = tail call i32 @memcpy(i8* %12, i8* %1, i32 %2)
%14 = tail call i32 @send(i32 %0, i8* %7, i32 %6, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %9
%17 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %9
%19 = tail call i32 @free(i8* %7)
br label %20
20: ; preds = %5, %18
%21 = phi i32 [ %14, %18 ], [ 0, %5 ]
ret i32 %21
}