#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*/ asprintf(char **, char *, char *, char *, int /*<<< orphan*/,
                            char *, char *);
int /*<<< orphan*/ free(char *);
char *get_http_date_str();
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int send_http_response(char *status_code, char *content, int sockfd) {
  char *date = NULL, *response = NULL;
  char *fmt = "HTTP/1.1 %s\n"
              "Server: pingpress\n"
              "Date: %s\n"
              "Content-type: text/plain\n"
              "Content-Length: %d\n"
              "Last-Modified: %s\n"
              "Connection: close\n"
              "\n"
              "%s";
  int rc = 1;
  if (!(date = get_http_date_str()))
    goto send_http_response_exit;
  if (!asprintf(&response, fmt, status_code, date, strlen(content), date,
                content))
    goto send_http_response_exit;
  rc = send(sockfd, response, strlen(response), 0) == -1;
send_http_response_exit:
  free(date);
  free(response);
  return rc;
}


x86 assembly (clang, -O0):
<send_http_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe86(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
mov    $0x0,%al
call   1060 <get_http_date_str@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    119f <send_http_response+0x4f>
jmp    1227 <send_http_response+0xd7>
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    %eax,%r8d
mov    -0x20(%rbp),%r9
mov    -0x10(%rbp),%rax
lea    -0x28(%rbp),%rdi
mov    %rax,(%rsp)
call   1070 <asprintf@plt>
cmp    $0x0,%eax
jne    11f2 <send_http_response+0xa2>
jmp    1227 <send_http_response+0xd7>
mov    -0x14(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
cmp    $0xffffffff,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_http_response>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%rbp
mov    %rdi,%r15
movq   $0x0,0x8(%rsp)
xor    %eax,%eax
call   1060 <get_http_date_str@plt>
mov    %rax,%rbx
mov    $0x1,%r12d
test   %rax,%rax
je     11d6 <send_http_response+0x86>
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rbp,(%rsp)
lea    0xe6a(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
mov    %rbx,%r9
call   1070 <asprintf@plt>
test   %eax,%eax
je     11d6 <send_http_response+0x86>
mov    0x8(%rsp),%rbp
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
xor    %r12d,%r12d
cmp    $0xffffffff,%eax
sete   %r12b
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r12d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [123 x i8] c"HTTP/1.1 %s\0AServer: pingpress\0ADate: %s\0AContent-type: text/plain\0AContent-Length: %d\0ALast-Modified: %s\0AConnection: close\0A\0A%s\00"
define i32 @send_http_response(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8* null, i8** %7
store i8* null, i8** %8
store i8* getelementptr inbounds ([123 x i8], [123 x i8]* @.str, i64 0, i64 0), i8** %9
store i32 1, i32* %10
%11 = call i8* (...) @get_http_date_str()
store i8* %11, i8** %7
%12 = icmp ne i8* %11, null
br i1 %12, label %14, label %13
13: ; preds = %3
br label %33
14: ; preds = %3
%15 = load i8*, i8** %9
%16 = load i8*, i8** %4
%17 = load i8*, i8** %7
%18 = load i8*, i8** %5
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %7
%21 = load i8*, i8** %5
%22 = call i32 @asprintf(i8** %8, i8* %15, i8* %16, i8* %17, i32 %19, i8* %20, i8* %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %14
br label %33
25: ; preds = %14
%26 = load i32, i32* %6
%27 = load i8*, i8** %8
%28 = load i8*, i8** %8
%29 = call i32 @strlen(i8* %28)
%30 = call i32 @send(i32 %26, i8* %27, i32 %29, i32 0)
%31 = icmp eq i32 %30, -1
%32 = zext i1 %31 to i32
store i32 %32, i32* %10
br label %33
33: ; preds = %25, %24, %13
%34 = load i8*, i8** %7
%35 = call i32 @free(i8* %34)
%36 = load i8*, i8** %8
%37 = call i32 @free(i8* %36)
%38 = load i32, i32* %10
ret i32 %38
}

LLVM IR (-O2):
@.str = [123 x i8] c"HTTP/1.1 %s\0AServer: pingpress\0ADate: %s\0AContent-type: text/plain\0AContent-Length: %d\0ALast-Modified: %s\0AConnection: close\0A\0A%s\00"
define i32 @send_http_response(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%6 = tail call i8* (...) @get_http_date_str()
%7 = icmp eq i8* %6, null
br i1 %7, label %18, label %8
8: ; preds = %3
%9 = tail call i32 @strlen(i8* %1)
%10 = call i32 @asprintf(i8** %4, i8* getelementptr inbounds ([123 x i8], [123 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %6, i32 %9, i8* %6, i8* %1)
%11 = icmp eq i32 %10, 0
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = call i32 @send(i32 %2, i8* %13, i32 %14, i32 0)
%16 = icmp eq i32 %15, -1
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %8, %3, %12
%19 = phi i32 [ %17, %12 ], [ 1, %8 ], [ 1, %3 ]
%20 = call i32 @free(i8* %6)
%21 = load i8*, i8** %4
%22 = call i32 @free(i8* %21)
ret i32 %19
}