#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ send_status(int /*<<< orphan*/ *, int, char const *);
int /*<<< orphan*/ sprintf(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
void send_response(FILE *client, int code, const char *reason_phrase,
                   const char *message_body) {
  send_status(client, code, reason_phrase);
  if (message_body != NULL) {
    char content_length[256];
    sprintf(content_length, "Content-Length: %zu\r\n", strlen(message_body));
    fprintf(client, "Content-Type: text/html\r\n");
    fprintf(client, "%s", content_length);
    fprintf(client, "\r\n");
    fprintf(client, "%s", message_body);
  }
  fprintf(client, "\r\n");
}


x86 assembly (clang, -O0):
<send_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <send_status@plt>
cmpq   $0x0,-0x20(%rbp)
je     11f4 <send_response+0xb4>
lea    -0x120(%rbp),%rax
mov    %rax,-0x128(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x128(%rbp),%rdi
mov    %eax,%edx
lea    0xe64(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x120(%rbp),%rdx
lea    0xe6b(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe43(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe2e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_response>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
mov    %rcx,%r14
mov    %rdi,%rbx
call   1030 <send_status@plt>
test   %r14,%r14
je     11d0 <send_response+0x80>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0xe85(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %eax,%edx
call   1060 <sprintf@plt>
lea    0xe87(%rip),%rdi
mov    $0x19,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
lea    0xe7a(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <fputs@plt>
lea    0xe56(%rip),%rdi
mov    $0x2,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1070 <fwrite@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"Content-Length: %zu\0D\0A\00"
@.str.1 = [26 x i8] c"Content-Type: text/html\0D\0A\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [3 x i8] c"\0D\0A\00"
define void @send_response(i32* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [256 x i8]
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%10 = load i32*, i32** %5
%11 = load i32, i32* %6
%12 = load i8*, i8** %7
%13 = call i32 @send_status(i32* %10, i32 %11, i8* %12)
%14 = load i8*, i8** %8
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %31
16: ; preds = %4
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%18 = load i8*, i8** %8
%19 = call i32 @strlen(i8* %18)
%20 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32*, i32** %5
%22 = call i32 (i32*, i8*, ...) @fprintf(i32* %21, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32*, i32** %5
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%25 = call i32 (i32*, i8*, ...) @fprintf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i32*, i32** %5
%27 = call i32 (i32*, i8*, ...) @fprintf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32*, i32** %5
%29 = load i8*, i8** %8
%30 = call i32 (i32*, i8*, ...) @fprintf(i32* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %16, %4
%32 = load i32*, i32** %5
%33 = call i32 (i32*, i8*, ...) @fprintf(i32* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"Content-Length: %zu\0D\0A\00"
@.str.1 = [26 x i8] c"Content-Type: text/html\0D\0A\00"
@.str.3 = [3 x i8] c"\0D\0A\00"
define void @send_response(i32* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca [256 x i8]
%6 = tail call i32 @send_status(i32* %0, i32 %1, i8* %2)
%7 = icmp eq i8* %3, null
br i1 %7, label %16, label %8
8: ; preds = %4
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = tail call i32 @strlen(i8* %3)
%11 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = tail call i64 @fwrite(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i64 25, i64 1, i32* %0)
%13 = call i32 @fputs(i8* %9, i32* %0)
%14 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %0)
%15 = tail call i32 @fputs(i8* %3, i32* %0)
br label %16
16: ; preds = %8, %4
%17 = tail call i64 @fwrite(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2, i64 1, i32* %0)
ret void
}