#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 */
char *malloc(scalar_t__);
int send(int, char *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, scalar_t__, char *);
scalar_t__ strlen(char *);
int send_400_response(int connfd) {
  char *message_content = "<html><head><title>400 BAD REQUEST</title>"
                          "<head/><body><p>400 BAD REQUEST</p></body>";
  char *message_unformatted =
      "HTTP/1.1 400 BAD REQUEST\r\nConnection: close"
      "\r\nContent-Type: text/html\r\nContent-Length: %ld\r\n\r\n%s";
  char *message = malloc(strlen(message_unformatted) + strlen(message_content));
  sprintf(message, message_unformatted, strlen(message_content),
          message_content);
  if (send(connfd, message, strlen(message), 0) == -1) {
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xef8(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x48(%rbp),%rdi
add    %rax,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
mov    -0x10(%rbp),%rcx
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
jne    11f1 <send_400_response+0xb1>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f8 <send_400_response+0xb8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0xb3,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xefc(%rip),%rsi
lea    0xea0(%rip),%rcx
mov    $0x54,%edx
mov    %rax,%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>
xor    %ecx,%ecx
cmp    $0xffffffff,%eax
sete   %cl
neg    %ecx
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [85 x i8] c"<html><head><title>400 BAD REQUEST</title><head/><body><p>400 BAD REQUEST</p></body>\00"
@.str.1 = [96 x i8] c"HTTP/1.1 400 BAD REQUEST\0D\0AConnection: close\0D\0AContent-Type: text/html\0D\0AContent-Length: %ld\0D\0A\0D\0A%s\00"
define i32 @send_400_response(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i32 %0, i32* %3
store i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([96 x i8], [96 x i8]* @.str.1, i64 0, i64 0), i8** %5
%7 = load i8*, i8** %5
%8 = call i64 @strlen(i8* %7)
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %8, %10
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = load i8*, i8** %5
%15 = load i8*, i8** %4
%16 = call i64 @strlen(i8* %15)
%17 = load i8*, i8** %4
%18 = call i32 @sprintf(i8* %13, i8* %14, i64 %16, i8* %17)
%19 = load i32, i32* %3
%20 = load i8*, i8** %6
%21 = load i8*, i8** %6
%22 = call i64 @strlen(i8* %21)
%23 = call i32 @send(i32 %19, i8* %20, i64 %22, i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %1
store i32 -1, i32* %2
br label %27
26: ; preds = %1
store i32 0, i32* %2
br label %27
27: ; preds = %26, %25
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@.str = [85 x i8] c"<html><head><title>400 BAD REQUEST</title><head/><body><p>400 BAD REQUEST</p></body>\00"
@.str.1 = [96 x i8] c"HTTP/1.1 400 BAD REQUEST\0D\0AConnection: close\0D\0AContent-Type: text/html\0D\0AContent-Length: %ld\0D\0A\0D\0A%s\00"
define i32 @send_400_response(i32 %0) {
%2 = tail call dereferenceable_or_null(179) i8* @malloc(i64 179)
%3 = tail call i32 @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([96 x i8], [96 x i8]* @.str.1, i64 0, i64 0), i64 84, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%5 = tail call i32 @send(i32 %0, i8* %2, i64 %4, i32 0)
%6 = icmp eq i32 %5, -1
%7 = sext i1 %6 to i32
ret i32 %7
}