#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 */
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, int, char const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ send_status(int /*<<< orphan*/ *, int, char const *);
scalar_t__ 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 (fprintf(client,
              "Connection: close\r\nContent-Length: %d\r\nContent-Type: "
              "text/plain\r\n\r\n%s",
              (int)strlen(message_body), message_body) < 0) {
    perror("bug fprintf");
  }
}


x86 assembly (clang, -O0):
<send_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%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>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%edx
mov    -0x20(%rbp),%rcx
lea    0xe77(%rip),%rsi
call   1050 <fprintf@plt>
cmp    $0x0,%rax
jge    11a4 <send_response+0x64>
lea    0xea7(%rip),%rdi
call   1060 <perror@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_response>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdi,%rbx
call   1030 <send_status@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0xea2(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
mov    %r14,%rcx
call   1050 <fprintf@plt>
test   %rax,%rax
js     1178 <send_response+0x38>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xec7(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <perror@plt>

LLVM IR (-O0):
@.str = [70 x i8] c"Connection: close\0D\0AContent-Length: %d\0D\0AContent-Type: text/plain\0D\0A\0D\0A%s\00"
@.str.1 = [12 x i8] c"bug fprintf\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*
store i32* %0, i32** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%9 = load i32*, i32** %5
%10 = load i32, i32* %6
%11 = load i8*, i8** %7
%12 = call i32 @send_status(i32* %9, i32 %10, i8* %11)
%13 = load i32*, i32** %5
%14 = load i8*, i8** %8
%15 = call i64 @strlen(i8* %14)
%16 = trunc i64 %15 to i32
%17 = load i8*, i8** %8
%18 = call i64 @fprintf(i32* %13, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %16, i8* %17)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %4
%21 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %4
ret void
}

LLVM IR (-O2):
@.str = [70 x i8] c"Connection: close\0D\0AContent-Length: %d\0D\0AContent-Type: text/plain\0D\0A\0D\0A%s\00"
@.str.1 = [12 x i8] c"bug fprintf\00"
define void @send_response(i32* %0, i32 %1, i8* %2, i8* %3) {
%5 = tail call i32 @send_status(i32* %0, i32 %1, i8* %2)
%6 = tail call i64 @strlen(i8* dereferenceable(1) %3)
%7 = trunc i64 %6 to i32
%8 = tail call i64 @fprintf(i32* %0, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %3)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %4
ret void
}