#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 ssize_t;

/* Variables and functions */
char *alloca(int);
int http_response_write_status_line(struct HTTPResponse *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int, char const *);
char *status_message_by_code(unsigned int);
ssize_t http_response_write_status_line_by_code(struct HTTPResponse *response,
                                                unsigned code) {
  const char *message = NULL;
  char *status_line = alloca(36);
  if ((message = status_message_by_code(code)) == NULL)
    return -1;
  snprintf(status_line, 36, "%d %s", code, message);
  return http_response_write_status_line(response, status_line);
}


x86 assembly (clang, -O0):
<http_response_write_status_line_by_code>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x24,%edi
call   1050 <alloca@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <status_message_by_code@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1187 <http_response_write_status_line_by_code+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b3 <http_response_write_status_line_by_code+0x73>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    $0x24,%esi
lea    0xe62(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <http_response_write_status_line@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_response_write_status_line_by_code>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x24,%edi
call   1050 <alloca@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1060 <status_message_by_code@plt>
test   %rax,%rax
je     118a <http_response_write_status_line_by_code+0x4a>
lea    0xe97(%rip),%rdx
mov    %rbx,%rdi
mov    $0x24,%esi
mov    %ebp,%ecx
mov    %rax,%r8
call   1030 <snprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <http_response_write_status_line@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.HTTPResponse = type { i32 }
@.str = [6 x i8] c"%d %s\00"
define i32 @http_response_write_status_line_by_code(%struct.HTTPResponse* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.HTTPResponse*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
store %struct.HTTPResponse* %0, %struct.HTTPResponse** %4
store i32 %1, i32* %5
store i8* null, i8** %6
%8 = call i8* @alloca(i32 36)
store i8* %8, i8** %7
%9 = load i32, i32* %5
%10 = call i8* @status_message_by_code(i32 %9)
store i8* %10, i8** %6
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 -1, i32* %3
br label %21
13: ; preds = %2
%14 = load i8*, i8** %7
%15 = load i32, i32* %5
%16 = load i8*, i8** %6
%17 = call i32 @snprintf(i8* %14, i32 36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %16)
%18 = load %struct.HTTPResponse*, %struct.HTTPResponse** %4
%19 = load i8*, i8** %7
%20 = call i32 @http_response_write_status_line(%struct.HTTPResponse* %18, i8* %19)
store i32 %20, i32* %3
br label %21
21: ; preds = %13, %12
%22 = load i32, i32* %3
ret i32 %22
}

LLVM IR (-O2):
%struct.HTTPResponse = type { i32 }
@.str = [6 x i8] c"%d %s\00"
define i32 @http_response_write_status_line_by_code(%struct.HTTPResponse* %0, i32 %1) {
%3 = tail call i8* @alloca(i32 36)
%4 = tail call i8* @status_message_by_code(i32 %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = tail call i32 @snprintf(i8* %3, i32 36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %1, i8* %4)
%8 = tail call i32 @http_response_write_status_line(%struct.HTTPResponse* %0, i8* %3)
br label %9
9: ; preds = %2, %6
%10 = phi i32 [ %8, %6 ], [ -1, %2 ]
ret i32 %10
}