#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*/ perror(char *);
scalar_t__ send(int, char *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ strlen(char *);
void build_error_response(int connection, int error_code) {
  char buf[255];
  sprintf(buf, "HTTP/1.1 %d Error Occurred\r\n\r\n", error_code);
  if (send(connection, buf, strlen(buf), 0) < strlen(buf)) {
    perror("Trying to respond");
  }
}


x86 assembly (clang, -O0):
<build_error_response>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe9e(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x124(%rbp)
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    -0x110(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x124(%rbp),%edi
mov    -0x120(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rax,-0x118(%rbp)
lea    -0x110(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x118(%rbp),%rax
cmp    %rcx,%rax
jge    11d3 <build_error_response+0x93>
lea    0xe51(%rip),%rdi
call   1050 <perror@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_error_response>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    %esi,%edx
mov    %edi,%ebp
lea    0xeac(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    %rax,%rbp
jl     1190 <build_error_response+0x50>
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe88(%rip),%rdi
call   1050 <perror@plt>
jmp    1186 <build_error_response+0x46>

LLVM IR (-O0):
@.str = [31 x i8] c"HTTP/1.1 %d Error Occurred\0D\0A\0D\0A\00"
@.str.1 = [18 x i8] c"Trying to respond\00"
define void @build_error_response(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [255 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* %4
%8 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %3
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%12 = call i64 @strlen(i8* %11)
%13 = call i64 @send(i32 %9, i8* %10, i64 %12, i32 0)
%14 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%15 = call i64 @strlen(i8* %14)
%16 = icmp slt i64 %13, %15
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
ret void
}

LLVM IR (-O2):
@.str = [31 x i8] c"HTTP/1.1 %d Error Occurred\0D\0A\0D\0A\00"
@.str.1 = [18 x i8] c"Trying to respond\00"
define void @build_error_response(i32 %0, i32 %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = call i64 @strlen(i8* %4)
%7 = call i64 @send(i32 %0, i8* %4, i64 %6, i32 0)
%8 = call i64 @strlen(i8* %4)
%9 = icmp slt i64 %7, %8
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
ret void
}