#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 */
struct HTTPResponse {
  int dummy;
};
typedef int /*<<< orphan*/ ssize_t;

/* Variables and functions */
char *alloca(size_t);
int /*<<< orphan*/ http_response_append_data(struct HTTPResponse *, char *,
                                             size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char *, char const *);
int strlen(char const *);
ssize_t http_response_write_status_line(struct HTTPResponse *response,
                                        const char *status_line) {
  size_t status_len = 8 + 1 + strlen(status_line) + strlen("\r\n") + 1;
  char *status = alloca(status_len);
  snprintf(status, status_len,
           "HTTP/1.1 %s"
           "\r\n",
           status_line);
  return http_response_append_data(response, status, status_len - 1);
}


x86 assembly (clang, -O0):
<http_response_write_status_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x9,%eax
mov    %eax,-0x24(%rbp)
lea    0xea5(%rip),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <alloca@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rcx
lea    0xe65(%rip),%rdx
call   1040 <snprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x1,%rdx
call   1060 <http_response_append_data@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_response_write_status_line>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
lea    0xeac(%rip),%rdi
call   1030 <strlen@plt>
add    %ebx,%eax
add    $0xa,%eax
movslq %eax,%rbx
mov    %rbx,%rdi
call   1050 <alloca@plt>
mov    %rax,%r12
lea    0xe82(%rip),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15,%rcx
call   1040 <snprintf@plt>
add    $0xffffffffffffffff,%rbx
mov    %r14,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1060 <http_response_append_data@plt>

LLVM IR (-O0):
%struct.HTTPResponse = type { i32 }
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [14 x i8] c"HTTP/1.1 %s\0D\0A\00"
define i32 @http_response_write_status_line(%struct.HTTPResponse* %0, i8* %1) {
%3 = alloca %struct.HTTPResponse*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store %struct.HTTPResponse* %0, %struct.HTTPResponse** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 9, %8
%10 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = add nsw i32 %9, %10
%12 = add nsw i32 %11, 1
%13 = sext i32 %12 to i64
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = call i8* @alloca(i64 %14)
store i8* %15, i8** %6
%16 = load i8*, i8** %6
%17 = load i64, i64* %5
%18 = load i8*, i8** %4
%19 = call i32 @snprintf(i8* %16, i64 %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load %struct.HTTPResponse*, %struct.HTTPResponse** %3
%21 = load i8*, i8** %6
%22 = load i64, i64* %5
%23 = sub i64 %22, 1
%24 = call i32 @http_response_append_data(%struct.HTTPResponse* %20, i8* %21, i64 %23)
ret i32 %24
}

LLVM IR (-O2):
%struct.HTTPResponse = type { i32 }
@.str = [3 x i8] c"\0D\0A\00"
@.str.1 = [14 x i8] c"HTTP/1.1 %s\0D\0A\00"
define i32 @http_response_write_status_line(%struct.HTTPResponse* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = add i32 %3, 10
%6 = add i32 %5, %4
%7 = sext i32 %6 to i64
%8 = tail call i8* @alloca(i64 %7)
%9 = tail call i32 @snprintf(i8* %8, i64 %7, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%10 = add nsw i64 %7, -1
%11 = tail call i32 @http_response_append_data(%struct.HTTPResponse* %0, i8* %8, i64 %10)
ret i32 %11
}