#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*/ close(int);
int /*<<< orphan*/ sprintf(char *, char *, int, char *, int, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
void server_send(int code, char *charcode, char *content, int sockfd,
                 int length) {
  char sendline[length];
  sprintf(sendline,
          "HTTP/1.0 %d %s\r\n"
          "Server: libhttp/1.0\r\n"
          "Content-type: text/html; charset=utf-8\r\n"
          "Content-length: %d\r\n\r\n"
          "%s",
          code, charcode, (int)strlen(content), content);
  write(sockfd, sendline, strlen(sendline));
  close(sockfd);
}


x86 assembly (clang, -O0):
<server_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x4c(%rbp),%edx
mov    -0x48(%rbp),%rcx
mov    -0x38(%rbp),%rdi
mov    %eax,%r8d
mov    -0x18(%rbp),%r9
lea    0xe50(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<server_send>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r13
mov    %rsi,%r15
mov    %edi,%r12d
mov    %r8d,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rdx,%rdi
call   1040 <strlen@plt>
lea    0xe83(%rip),%rsi
mov    %rbx,%rdi
mov    %r12d,%edx
mov    %r15,%rcx
mov    %eax,%r8d
mov    %r13,%r9
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %r14d,%edi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <close@plt>

LLVM IR (-O0):
@.str = [102 x i8] c"HTTP/1.0 %d %s\0D\0AServer: libhttp/1.0\0D\0AContent-type: text/html; charset=utf-8\0D\0AContent-length: %d\0D\0A\0D\0A%s\00"
define void @server_send(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load i32, i32* %10
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %11
%16 = alloca i8, i64 %14
store i64 %14, i64* %12
%17 = load i32, i32* %6
%18 = load i8*, i8** %7
%19 = load i8*, i8** %8
%20 = call i64 @strlen(i8* %19)
%21 = trunc i64 %20 to i32
%22 = load i8*, i8** %8
%23 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str, i64 0, i64 0), i32 %17, i8* %18, i32 %21, i8* %22)
%24 = load i32, i32* %9
%25 = call i64 @strlen(i8* %16)
%26 = call i32 @write(i32 %24, i8* %16, i64 %25)
%27 = load i32, i32* %9
%28 = call i32 @close(i32 %27)
%29 = load i8*, i8** %11
ret void
}

LLVM IR (-O2):
@.str = [102 x i8] c"HTTP/1.0 %d %s\0D\0AServer: libhttp/1.0\0D\0AContent-type: text/html; charset=utf-8\0D\0AContent-length: %d\0D\0A\0D\0A%s\00"
define void @server_send(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4) {
%6 = zext i32 %4 to i64
%7 = alloca i8, i64 %6
%8 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%9 = trunc i64 %8 to i32
%10 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([102 x i8], [102 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %1, i32 %9, i8* %2)
%11 = call i64 @strlen(i8* %7)
%12 = call i32 @write(i32 %3, i8* %7, i64 %11)
%13 = tail call i32 @close(i32 %3)
ret void
}