#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*/ err(int, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getTime(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strlcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ writeToClient(int, char *);
void sendError(int clientsd, char *title, char *content) {
  char *buf, *tmp, length[20], time[80];
  tmp = (char *)malloc((128 + strlen(content)) * sizeof(char));
  if (tmp == NULL)
    err(1, "malloc");
  buf = tmp;
  getTime(time);
  sprintf(length, "%d", strlen(content));
  strlcpy(buf, "HTTP/1.1 ");
  strcat(buf, title);
  strcat(buf, "Date: ");
  strcat(buf, time);
  strcat(buf, "\nContent-Type: text/html\n");
  strcat(buf, "Content-Length: ");
  strcat(buf, length);
  strcat(buf, "\n\n");
  strcat(buf, content);
  writeToClient(clientsd, buf);
  free(buf);
  buf = NULL;
  tmp = NULL;
}


x86 assembly (clang, -O0):
<sendError>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x80,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e1 <sendError+0x51>
mov    $0x1,%edi
lea    0xe24(%rip),%rsi
call   1060 <err@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    -0x90(%rbp),%rdi
call   1040 <getTime@plt>
lea    -0x40(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x98(%rbp),%rdi
mov    %eax,%edx
lea    0xdee(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xde1(%rip),%rsi
call   1080 <strlcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xdce(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xdb5(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xdbf(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xdb3(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1090 <writeToClient@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendError>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %edi,%r14d
mov    %rdx,%rdi
call   1050 <strlen@plt>
lea    0x80(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11d3 <sendError+0x43>
lea    0xe37(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
lea    0x20(%rsp),%r13
mov    %r13,%rdi
call   1040 <getTime@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xe18(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    %eax,%edx
call   10b0 <sprintf@plt>
lea    0xe07(%rip),%rsi
mov    %rbp,%rdi
call   1080 <strlcpy@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10a0 <strcat@plt>
lea    0xdf7(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strcat@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   10a0 <strcat@plt>
lea    0xde4(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strcat@plt>
lea    0xdef(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strcat@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
call   10a0 <strcat@plt>
lea    0xde6(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <strcat@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10a0 <strcat@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
call   1090 <writeToClient@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [10 x i8] c"HTTP/1.1 \00"
@.str.3 = [7 x i8] c"Date: \00"
@.str.4 = [26 x i8] c"\0AContent-Type: text/html\0A\00"
@.str.5 = [17 x i8] c"Content-Length: \00"
@.str.6 = [3 x i8] c"\0A\0A\00"
define void @sendError(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [20 x i8]
%10 = alloca [80 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%11 = load i8*, i8** %6
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 128, %12
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 1
%16 = trunc i64 %15 to i32
%17 = call i64 @malloc(i32 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %8
%19 = load i8*, i8** %8
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %3
%24 = load i8*, i8** %8
store i8* %24, i8** %7
%25 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%26 = call i32 @getTime(i8* %25)
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%28 = load i8*, i8** %6
%29 = call i32 @strlen(i8* %28)
%30 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %29)
%31 = load i8*, i8** %7
%32 = call i32 @strlcpy(i8* %31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%33 = load i8*, i8** %7
%34 = load i8*, i8** %5
%35 = call i32 @strcat(i8* %33, i8* %34)
%36 = load i8*, i8** %7
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%38 = load i8*, i8** %7
%39 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%40 = call i32 @strcat(i8* %38, i8* %39)
%41 = load i8*, i8** %7
%42 = call i32 @strcat(i8* %41, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%43 = load i8*, i8** %7
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%45 = load i8*, i8** %7
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%47 = call i32 @strcat(i8* %45, i8* %46)
%48 = load i8*, i8** %7
%49 = call i32 @strcat(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%50 = load i8*, i8** %7
%51 = load i8*, i8** %6
%52 = call i32 @strcat(i8* %50, i8* %51)
%53 = load i32, i32* %4
%54 = load i8*, i8** %7
%55 = call i32 @writeToClient(i32 %53, i8* %54)
%56 = load i8*, i8** %7
%57 = call i32 @free(i8* %56)
store i8* null, i8** %7
store i8* null, i8** %8
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"malloc\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [10 x i8] c"HTTP/1.1 \00"
@.str.3 = [7 x i8] c"Date: \00"
@.str.4 = [26 x i8] c"\0AContent-Type: text/html\0A\00"
@.str.5 = [17 x i8] c"Content-Length: \00"
@.str.6 = [3 x i8] c"\0A\0A\00"
define void @sendError(i32 %0, i8* %1, i8* %2) {
%4 = alloca [20 x i8]
%5 = alloca [80 x i8]
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%8 = tail call i32 @strlen(i8* %2)
%9 = add nsw i32 %8, 128
%10 = tail call i64 @malloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = icmp eq i64 %10, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %3
%16 = call i32 @getTime(i8* %7)
%17 = call i32 @strlen(i8* %2)
%18 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = call i32 @strlcpy(i8* %11, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @strcat(i8* %11, i8* %1)
%21 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @strcat(i8* %11, i8* %7)
%23 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%25 = call i32 @strcat(i8* %11, i8* %6)
%26 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%27 = call i32 @strcat(i8* %11, i8* %2)
%28 = call i32 @writeToClient(i32 %0, i8* %11)
%29 = call i32 @free(i8* %11)
ret void
}