#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 = 0.14;
  double y = 0.61;
  double zoom = 60.0;
  double zoom_x = x - 2.0 / zoom;
  double zoom_y = y - 2.0 / zoom;
  double seed[2] = {zoom_x, zoom_y};
  while (zoom_y < (y - 2.0 / zoom + 511 * (2.0 / zoom / 256.0))) {
    while (zoom_x < (x - 2.0 / zoom + 511 * (2.0 / zoom / 256.0))) {
      calcPoint(socket, seed, zoom_x, zoom_y, 0);
      zoom_x = zoom_x + 2.0 / zoom / 256.0;
      seed[0] = zoom_x;
    }
    zoom_y = zoom_y + 2.0 / zoom / 256.0;
    zoom_x = x - 2.0 / zoom;
    seed[0] = zoom_x;
    seed[1] = zoom_y;
  }
}


x86 assembly (clang, -O0):
<serveBMP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
lea    0xece(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xeec(%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
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
call   1060 <writeHeader@plt>
movsd  0xe6d(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe58(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe43(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe29(%rip),%xmm1
divsd  -0x28(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe0e(%rip),%xmm1
divsd  -0x28(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
movsd  0xdda(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
subsd  %xmm0,%xmm2
movsd  0xdc9(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  0xde4(%rip),%xmm3
divsd  %xmm3,%xmm0
movsd  0xdd0(%rip),%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    135e <serveBMP+0x20e>
jmp    1267 <serveBMP+0x117>
movsd  -0x30(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm2
movsd  0xd87(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
subsd  %xmm0,%xmm2
movsd  0xd76(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  0xd91(%rip),%xmm3
divsd  %xmm3,%xmm0
movsd  0xd7d(%rip),%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1303 <serveBMP+0x1b3>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
movsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
xor    %edx,%edx
call   1070 <calcPoint@plt>
movsd  -0x30(%rbp),%xmm0
movsd  0xd26(%rip),%xmm1
divsd  -0x28(%rbp),%xmm1
movsd  0xd41(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    1267 <serveBMP+0x117>
movsd  -0x38(%rbp),%xmm0
movsd  0xcf0(%rip),%xmm1
divsd  -0x28(%rbp),%xmm1
movsd  0xd0b(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xcc9(%rip),%xmm1
divsd  -0x28(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
jmp    1214 <serveBMP+0xc4>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<serveBMP>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
lea    0xf03(%rip),%rdi
lea    0xecf(%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>
movaps 0xe6d(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movsd  0xe70(%rip),%xmm3
lea    0x10(%rsp),%r14
movabs $0x3fbb4e81b4e81b50,%r15
4e bb 3f
nop
movsd  0xe60(%rip),%xmm0
movsd  %xmm3,0x8(%rsp)
xchg   %ax,%ax
movsd  %xmm0,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
movsd  0x8(%rsp),%xmm1
xor    %edx,%edx
call   1070 <calcPoint@plt>
movsd  0xe49(%rip),%xmm2
movsd  0xe39(%rip),%xmm1
movsd  0x8(%rsp),%xmm3
movsd  (%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
ucomisd (%rsp),%xmm2
movsd  (%rsp),%xmm0
ja     11c0 <serveBMP+0x70>
addsd  %xmm1,%xmm3
mov    %r15,0x10(%rsp)
movsd  %xmm3,0x18(%rsp)
movsd  0xe07(%rip),%xmm1
ucomisd %xmm3,%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 double
%7 = alloca double
%8 = alloca double
%9 = 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
%10 = load i8*, i8** %3
%11 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i32, i32* %2
%13 = load i8*, i8** %3
%14 = load i8*, i8** %3
%15 = call i32 @strlen(i8* %14)
%16 = call i32 @write(i32 %12, i8* %13, i32 %15)
%17 = load i32, i32* %2
%18 = call i32 @writeHeader(i32 %17)
store double 1.400000e-01, double* %4
store double 6.100000e-01, double* %5
store double 6.000000e+01, double* %6
%19 = load double, double* %4
%20 = load double, double* %6
%21 = fdiv double 2.000000e+00, %20
%22 = fsub double %19, %21
store double %22, double* %7
%23 = load double, double* %5
%24 = load double, double* %6
%25 = fdiv double 2.000000e+00, %24
%26 = fsub double %23, %25
store double %26, double* %8
%27 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%28 = load double, double* %7
store double %28, double* %27
%29 = getelementptr inbounds double, double* %27, i64 1
%30 = load double, double* %8
store double %30, double* %29
br label %31
31: ; preds = %67, %1
%32 = load double, double* %8
%33 = load double, double* %5
%34 = load double, double* %6
%35 = fdiv double 2.000000e+00, %34
%36 = fsub double %33, %35
%37 = load double, double* %6
%38 = fdiv double 2.000000e+00, %37
%39 = fdiv double %38, 2.560000e+02
%40 = call double @llvm.fmuladd.f64(double 5.110000e+02, double %39, double %36)
%41 = fcmp olt double %32, %40
br i1 %41, label %42, label %81
42: ; preds = %31
br label %43
43: ; preds = %54, %42
%44 = load double, double* %7
%45 = load double, double* %4
%46 = load double, double* %6
%47 = fdiv double 2.000000e+00, %46
%48 = fsub double %45, %47
%49 = load double, double* %6
%50 = fdiv double 2.000000e+00, %49
%51 = fdiv double %50, 2.560000e+02
%52 = call double @llvm.fmuladd.f64(double 5.110000e+02, double %51, double %48)
%53 = fcmp olt double %44, %52
br i1 %53, label %54, label %67
54: ; preds = %43
%55 = load i32, i32* %2
%56 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
%57 = load double, double* %7
%58 = load double, double* %8
%59 = call i32 @calcPoint(i32 %55, double* %56, double %57, double %58, i32 0)
%60 = load double, double* %7
%61 = load double, double* %6
%62 = fdiv double 2.000000e+00, %61
%63 = fdiv double %62, 2.560000e+02
%64 = fadd double %60, %63
store double %64, double* %7
%65 = load double, double* %7
%66 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
store double %65, double* %66
br label %43
67: ; preds = %43
%68 = load double, double* %8
%69 = load double, double* %6
%70 = fdiv double 2.000000e+00, %69
%71 = fdiv double %70, 2.560000e+02
%72 = fadd double %68, %71
store double %72, double* %8
%73 = load double, double* %4
%74 = load double, double* %6
%75 = fdiv double 2.000000e+00, %74
%76 = fsub double %73, %75
store double %76, double* %7
%77 = load double, double* %7
%78 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 0
store double %77, double* %78
%79 = load double, double* %8
%80 = getelementptr inbounds [2 x double], [2 x double]* %9, i64 0, i64 1
store double %79, double* %80
br label %31
81: ; preds = %31
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 0x3FBB4E81B4E81B50, double 0x3FE2740DA740DA74>, <2 x double>* %2
br label %10
10: ; preds = %1, %17
%11 = phi double [ 0x3FE2740DA740DA74, %1 ], [ %18, %17 ]
br label %12
12: ; preds = %10, %12
%13 = phi double [ 0x3FBB4E81B4E81B50, %10 ], [ %15, %12 ]
%14 = call i32 @calcPoint(i32 %0, double* %8, double %13, double %11, i32 0)
%15 = fadd double %13, 0x3F21111111111111
store double %15, double* %8
%16 = fcmp olt double %15, 0x3FC62B851EB851EC
br i1 %16, label %12, label %17
17: ; preds = %12
%18 = fadd double %11, 0x3F21111111111111
store double 0x3FBB4E81B4E81B50, double* %8
store double %18, double* %9
%19 = fcmp olt double %18, 0x3FE4951EB851EB85
br i1 %19, label %10, label %20
20: ; preds = %17
ret void
}