#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 */
typedef int /*<<< orphan*/ bmp;

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *);
int strlen(char *);
int /*<<< orphan*/ write(int, ...);
void serveBMP(int socket) {
  char *message;
  message = "HTTP/1.0 200 OK\r\n"
            "Content-Type: image/bmp\r\n"
            "\r\n";
  printf("about to send=> %s\n", message);
  write(socket, message, strlen(message));
  unsigned char bmp[] = {0x42, 0x4d, 0x36, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00,
                         0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
                         0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x01,
                         0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00,
                         0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 0x00,
                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  write(socket, bmp, sizeof(bmp));
}


x86 assembly (clang, -O0):
<serveBMP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xecc(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
mov    $0x0,%al
call   1030 <write@plt>
lea    -0x50(%rbp),%rdi
lea    0xeb8(%rip),%rsi
mov    $0x36,%edx
call   1060 <memcpy@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x36,%edx
mov    $0x0,%al
call   1030 <write@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serveBMP>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %edi,%ebp
lea    0xeee(%rip),%rdi
lea    0xeba(%rip),%rbx
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    0xf13(%rip),%rax
mov    %rax,0x2e(%rsp)
movaps 0xef9(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xedd(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xec1(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rsi
mov    $0x36,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1030 <write@plt>
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [45 x i8] c"HTTP/1.0 200 OK\0D\0AContent-Type: image/bmp\0D\0A\0D\0A\00"
@.str.1 = [20 x i8] c"about to send=> %s\0A\00"
@__const.serveBMP.bmp = <{ [44 x i8], [10 x i8] }> <{ [44 x i8] c"BM6\00\0C\00\00\00\00\006\00\00\00(\00\00\00\00\02\00\00\00\02\00\00\01\00\18\00\00\00\00\00$\00\00\00\13\0B\00\00\13\0B", [10 x i8] zeroinitializer }>
define void @serveBMP(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [54 x i8]
store i32 %0, i32* %2
store i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%7 = load i32, i32* %2
%8 = load i8*, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = call i32 (i32, ...) @write(i32 %7, i8* %8, i32 %10)
%12 = bitcast [54 x i8]* %4 to i8*
%13 = load i32, i32* %2
%14 = getelementptr inbounds [54 x i8], [54 x i8]* %4, i64 0, i64 0
%15 = call i32 (i32, ...) @write(i32 %13, i8* %14, i64 54)
ret void
}

LLVM IR (-O2):
@.str = [45 x i8] c"HTTP/1.0 200 OK\0D\0AContent-Type: image/bmp\0D\0A\0D\0A\00"
@.str.1 = [20 x i8] c"about to send=> %s\0A\00"
@__const.serveBMP.bmp = <{ [44 x i8], [10 x i8] }> <{ [44 x i8] c"BM6\00\0C\00\00\00\00\006\00\00\00(\00\00\00\00\02\00\00\00\02\00\00\01\00\18\00\00\00\00\00$\00\00\00\13\0B\00\00\13\0B", [10 x i8] zeroinitializer }>
define void @serveBMP(i32 %0) {
%2 = alloca [54 x i8]
%3 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 (i32, ...) @write(i32 %0, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = getelementptr inbounds [54 x i8], [54 x i8]* %2, i64 0, i64 0
%7 = call i32 (i32, ...) @write(i32 %0, i8* %6, i64 54)
ret void
}