#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*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
void bad_request(int sockfd) {
  char buf[1024];
  char err_400[] = "<html>"
                   "\r\n"
                   "<head><title>400 Bad Request</title></head>"
                   "\r\n"
                   "<body bgcolor=\"white\">"
                   "\r\n"
                   "<center><h1>400 Bad Request</h1></center>"
                   "\r\n"
                   "</body>"
                   "\r\n"
                   "</html>";
  sprintf(buf, "HTTP/1.1 400 Bad Request\r\n");
  send(sockfd, buf, strlen(buf), 0);
  sprintf(buf, "Content-Type: text/html\r\n");
  send(sockfd, buf, strlen(buf), 0);
  sprintf(buf, "Content-Length: %lu\r\n", strlen(err_400));
  send(sockfd, buf, strlen(buf), 0);
  sprintf(buf, "Connection: close\r\n");
  send(sockfd, buf, strlen(buf), 0);
  strcpy(buf, "\r\n");
  send(sockfd, buf, strlen(buf), 0);
  strcpy(buf, err_400);
  send(sockfd, buf, strlen(err_400), 0);
}


x86 assembly (clang, -O0):
<bad_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x510,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x4a0(%rbp),%rdi
lea    0xe94(%rip),%rsi
mov    $0x89,%edx
call   1060 <memcpy@plt>
lea    -0x410(%rbp),%rdi
lea    0xf05(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x504(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x500(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x504(%rbp),%edi
mov    -0x500(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    -0x410(%rbp),%rdi
lea    0xed2(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x4f4(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x4f0(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4f4(%rbp),%edi
mov    -0x4f0(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    -0x410(%rbp),%rax
mov    %rax,-0x4e8(%rbp)
lea    -0x4a0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4e8(%rbp),%rdi
mov    %eax,%edx
lea    0xe82(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x4dc(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x4d8(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4dc(%rbp),%edi
mov    -0x4d8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    -0x410(%rbp),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x4cc(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x4c8(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4cc(%rbp),%edi
mov    -0x4c8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    -0x410(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x4bc(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x4b8(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4bc(%rbp),%edi
mov    -0x4b8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    -0x410(%rbp),%rdi
lea    -0x4a0(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x4ac(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x4a8(%rbp)
lea    -0x4a0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4ac(%rbp),%edi
mov    -0x4a8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
add    $0x510,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bad_request>:
push   %rbp
push   %r14
push   %rbx
sub    $0x490,%rsp
mov    %edi,%ebp
lea    0xe9c(%rip),%rsi
mov    %rsp,%r14
mov    $0x89,%edx
mov    %r14,%rdi
call   1060 <memcpy@plt>
movups 0xf0e(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movups 0xf0a(%rip),%xmm0
movups %xmm0,0x9b(%rsp)
lea    0x90(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
movups 0xeed(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movups 0xee8(%rip),%xmm0
movups %xmm0,0x9a(%rsp)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0xecb(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
movups 0xeb8(%rip),%xmm0
movaps %xmm0,0x90(%rsp)
movl   $0xa0d65,0xa0(%rsp)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
add    $0x490,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.bad_request.err_400 = [137 x i8] c"<html>\0D\0A<head><title>400 Bad Request</title></head>\0D\0A<body bgcolor=\22white\22>\0D\0A<center><h1>400 Bad Request</h1></center>\0D\0A</body>\0D\0A</html>\00"
@.str = [27 x i8] c"HTTP/1.1 400 Bad Request\0D\0A\00"
@.str.1 = [26 x i8] c"Content-Type: text/html\0D\0A\00"
@.str.2 = [22 x i8] c"Content-Length: %lu\0D\0A\00"
@.str.3 = [20 x i8] c"Connection: close\0D\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
define void @bad_request(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca [137 x i8]
store i32 %0, i32* %2
%5 = bitcast [137 x i8]* %4 to i8*
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %2
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = call i32 @send(i32 %8, i8* %9, i32 %11, i32 0)
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %13, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* %2
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = call i32 @strlen(i8* %17)
%19 = call i32 @send(i32 %15, i8* %16, i32 %18, i32 0)
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%21 = getelementptr inbounds [137 x i8], [137 x i8]* %4, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %22)
%24 = load i32, i32* %2
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
%28 = call i32 @send(i32 %24, i8* %25, i32 %27, i32 0)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%31 = load i32, i32* %2
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%34 = call i32 @strlen(i8* %33)
%35 = call i32 @send(i32 %31, i8* %32, i32 %34, i32 0)
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%37 = call i32 @strcpy(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%38 = load i32, i32* %2
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%41 = call i32 @strlen(i8* %40)
%42 = call i32 @send(i32 %38, i8* %39, i32 %41, i32 0)
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%44 = getelementptr inbounds [137 x i8], [137 x i8]* %4, i64 0, i64 0
%45 = call i32 @strcpy(i8* %43, i8* %44)
%46 = load i32, i32* %2
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%48 = getelementptr inbounds [137 x i8], [137 x i8]* %4, i64 0, i64 0
%49 = call i32 @strlen(i8* %48)
%50 = call i32 @send(i32 %46, i8* %47, i32 %49, i32 0)
ret void
}

LLVM IR (-O2):
@__const.bad_request.err_400 = [137 x i8] c"<html>\0D\0A<head><title>400 Bad Request</title></head>\0D\0A<body bgcolor=\22white\22>\0D\0A<center><h1>400 Bad Request</h1></center>\0D\0A</body>\0D\0A</html>\00"
@.str = [27 x i8] c"HTTP/1.1 400 Bad Request\0D\0A\00"
@.str.1 = [26 x i8] c"Content-Type: text/html\0D\0A\00"
@.str.2 = [22 x i8] c"Content-Length: %lu\0D\0A\00"
@.str.3 = [20 x i8] c"Connection: close\0D\0A\00"
@.str.4 = [3 x i8] c"\0D\0A\00"
define void @bad_request(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca [137 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [137 x i8], [137 x i8]* %3, i64 0, i64 0
%6 = call i32 @strlen(i8* %4)
%7 = call i32 @send(i32 %0, i8* %4, i32 %6, i32 0)
%8 = call i32 @strlen(i8* %4)
%9 = call i32 @send(i32 %0, i8* %4, i32 %8, i32 0)
%10 = call i32 @strlen(i8* %5)
%11 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %10)
%12 = call i32 @strlen(i8* %4)
%13 = call i32 @send(i32 %0, i8* %4, i32 %12, i32 0)
%14 = call i32 @strlen(i8* %4)
%15 = call i32 @send(i32 %0, i8* %4, i32 %14, i32 0)
%16 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @strlen(i8* %4)
%18 = call i32 @send(i32 %0, i8* %4, i32 %17, i32 0)
%19 = call i32 @strcpy(i8* %4, i8* %5)
%20 = call i32 @strlen(i8* %5)
%21 = call i32 @send(i32 %0, i8* %4, i32 %20, i32 0)
ret void
}