#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*/ calcPoint(int, double *, double, double, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ writeHeader(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));
  writeHeader(socket);
  double x = -2.0;
  double y = -2.0;
  double seed[2] = {x, y};
  while (y < 2.0) {
    while (x < 2.0) {
      calcPoint(socket, seed, x, y, 0);
      x = x + 1.0 / 128.0;
      seed[0] = x;
    }
    y = y + 1.0 / 128.0;
    x = -2.0;
    seed[0] = x;
    seed[1] = y;
  }
}


x86 assembly (clang, -O0):
<serveBMP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
lea    0xeb6(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xed4(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
call   1060 <writeHeader@plt>
movsd  0xe55(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe48(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe2f(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    126d <serveBMP+0x11d>
jmp    11e9 <serveBMP+0x99>
movsd  0xe17(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1235 <serveBMP+0xe5>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
xor    %edx,%edx
call   1070 <calcPoint@plt>
movsd  0xdf4(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11e9 <serveBMP+0x99>
movsd  0xdd3(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xdb1(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11d1 <serveBMP+0x81>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serveBMP>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
lea    0xef3(%rip),%rdi
lea    0xebf(%rip),%r14
mov    %r14,%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebx,%edi
call   1060 <writeHeader@plt>
movapd 0xe6c(%rip),%xmm0
movapd %xmm0,(%rsp)
movsd  0xe6f(%rip),%xmm2
mov    %rsp,%r14
movabs $0xc000000000000000,%r15
xchg   %ax,%ax
movsd  0xe58(%rip),%xmm3
movsd  %xmm2,0x10(%rsp)
xchg   %ax,%ax
movsd  %xmm3,0x18(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
movaps %xmm3,%xmm0
movapd %xmm2,%xmm1
xor    %edx,%edx
call   1070 <calcPoint@plt>
movsd  0x18(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
movsd  0xe33(%rip),%xmm1
movsd  0xe23(%rip),%xmm0
addsd  %xmm0,%xmm3
movsd  %xmm3,(%rsp)
ucomisd %xmm3,%xmm1
ja     11c0 <serveBMP+0x70>
addsd  %xmm0,%xmm2
mov    %r15,(%rsp)
movsd  %xmm2,0x8(%rsp)
ucomisd %xmm2,%xmm1
ja     11b0 <serveBMP+0x60>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
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"
define void @serveBMP(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca double
%5 = alloca double
%6 = alloca [2 x double]
store i32 %0, i32* %2
store i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = load i32, i32* %2
%10 = load i8*, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = call i32 @write(i32 %9, i8* %10, i32 %12)
%14 = load i32, i32* %2
%15 = call i32 @writeHeader(i32 %14)
store double -2.000000e+00, double* %4
store double -2.000000e+00, double* %5
%16 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 0
%17 = load double, double* %4
store double %17, double* %16
%18 = getelementptr inbounds double, double* %16, i64 1
%19 = load double, double* %5
store double %19, double* %18
br label %20
20: ; preds = %37, %1
%21 = load double, double* %5
%22 = fcmp olt double %21, 2.000000e+00
br i1 %22, label %23, label %44
23: ; preds = %20
br label %24
24: ; preds = %27, %23
%25 = load double, double* %4
%26 = fcmp olt double %25, 2.000000e+00
br i1 %26, label %27, label %37
27: ; preds = %24
%28 = load i32, i32* %2
%29 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 0
%30 = load double, double* %4
%31 = load double, double* %5
%32 = call i32 @calcPoint(i32 %28, double* %29, double %30, double %31, i32 0)
%33 = load double, double* %4
%34 = fadd double %33, 7.812500e-03
store double %34, double* %4
%35 = load double, double* %4
%36 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 0
store double %35, double* %36
br label %24
37: ; preds = %24
%38 = load double, double* %5
%39 = fadd double %38, 7.812500e-03
store double %39, double* %5
store double -2.000000e+00, double* %4
%40 = load double, double* %4
%41 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 0
store double %40, double* %41
%42 = load double, double* %5
%43 = getelementptr inbounds [2 x double], [2 x double]* %6, i64 0, i64 1
store double %42, double* %43
br label %20
44: ; preds = %20
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"
define void @serveBMP(i32 %0) {
%2 = alloca <2 x double>
%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 @write(i32 %0, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i32 @writeHeader(i32 %0)
%7 = bitcast <2 x double>* %2 to i8*
%8 = getelementptr inbounds <2 x double>, <2 x double>* %2, i64 0, i64 0
%9 = getelementptr inbounds <2 x double>, <2 x double>* %2, i64 0, i64 1
store <2 x double> <double -2.000000e+00, double -2.000000e+00>, <2 x double>* %2
br label %10
10: ; preds = %1, %17
%11 = phi double [ -2.000000e+00, %1 ], [ %18, %17 ]
br label %12
12: ; preds = %10, %12
%13 = phi double [ -2.000000e+00, %10 ], [ %15, %12 ]
%14 = call i32 @calcPoint(i32 %0, double* %8, double %13, double %11, i32 0)
%15 = fadd double %13, 7.812500e-03
store double %15, double* %8
%16 = fcmp olt double %15, 2.000000e+00
br i1 %16, label %12, label %17
17: ; preds = %12
%18 = fadd double %11, 7.812500e-03
store double -2.000000e+00, double* %8
store double %18, double* %9
%19 = fcmp olt double %18, 2.000000e+00
br i1 %19, label %10, label %20
20: ; preds = %17
ret void
}